Skip to content

Commit 176196b

Browse files
sankarpnrjeberhard
authored andcommitted
Enhance existing tests to make right after failed domain status
1 parent c5c39e5 commit 176196b

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItDiagnosticsFailedCondition.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@
5454
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_STATUS_CONDITION_COMPLETED_TYPE;
5555
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_STATUS_CONDITION_FAILED_TYPE;
5656
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_VERSION;
57+
import static oracle.weblogic.kubernetes.TestConstants.ENCRYPION_PASSWORD_DEFAULT;
58+
import static oracle.weblogic.kubernetes.TestConstants.ENCRYPION_USERNAME_DEFAULT;
5759
import static oracle.weblogic.kubernetes.TestConstants.FMWINFRA_IMAGE_NAME;
5860
import static oracle.weblogic.kubernetes.TestConstants.FMWINFRA_IMAGE_TAG;
5961
import static oracle.weblogic.kubernetes.TestConstants.FMWINFRA_IMAGE_TO_USE_IN_SPEC;
6062
import static oracle.weblogic.kubernetes.TestConstants.IMAGE_PULL_POLICY;
6163
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME;
6264
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
6365
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
66+
import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO_SECRET_NAME;
6467
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TO_USE_IN_SPEC;
6568
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
6669
import static oracle.weblogic.kubernetes.actions.TestActions.deleteClusterCustomResource;
@@ -78,6 +81,7 @@
7881
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getUniqueName;
7982
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
8083
import static oracle.weblogic.kubernetes.utils.ConfigMapUtils.configMapExist;
84+
import static oracle.weblogic.kubernetes.utils.ConfigMapUtils.createConfigMapAndVerify;
8185
import static oracle.weblogic.kubernetes.utils.ConfigMapUtils.createConfigMapFromFiles;
8286
import static oracle.weblogic.kubernetes.utils.DbUtils.createRcuAccessSecret;
8387
import static oracle.weblogic.kubernetes.utils.DbUtils.setupDBandRCUschema;
@@ -89,8 +93,10 @@
8993
import static oracle.weblogic.kubernetes.utils.ImageUtils.createBaseRepoSecret;
9094
import static oracle.weblogic.kubernetes.utils.ImageUtils.createImageRegistrySecret;
9195
import static oracle.weblogic.kubernetes.utils.ImageUtils.createMiiImageAndVerify;
96+
import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret;
9297
import static oracle.weblogic.kubernetes.utils.ImageUtils.imageRepoLoginAndPushImageToRegistry;
9398
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
99+
import static oracle.weblogic.kubernetes.utils.PatchDomainUtils.patchDomainResource;
94100
import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity;
95101
import static oracle.weblogic.kubernetes.utils.SecretUtils.createOpsswalletpasswordSecret;
96102
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
@@ -853,6 +859,111 @@ rcuSchemaPrefix, domainNamespace, getNextFreePort(), dbUrl, dbListenerPort),
853859
}
854860
}
855861

862+
/**
863+
* Test domain status condition with a bad model file.
864+
* Verify the following conditions are generated in an order after an introspector failure.
865+
* type: Failed, status: true
866+
* type: Available, status: false
867+
* type: Completed, status: false
868+
* Verify the introspector reruns to make it right when model file is fixed.
869+
*/
870+
@Test
871+
@DisplayName("Test domain status condition with bad model file")
872+
void testIntrospectorMakerightAvailableFromFailure() {
873+
// Create the repo secret to pull the image
874+
// this secret is used only for non-kind cluster
875+
createTestRepoSecret(domainNamespace);
876+
877+
// create secret for admin credentials
878+
logger.info("Create secret for admin credentials");
879+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(
880+
adminSecretName,
881+
domainNamespace,
882+
ADMIN_USERNAME_DEFAULT,
883+
ADMIN_PASSWORD_DEFAULT),
884+
String.format("createSecret failed for %s", adminSecretName));
885+
886+
// create encryption secret
887+
logger.info("Create encryption secret");
888+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(
889+
encryptionSecretName,
890+
domainNamespace,
891+
ENCRYPION_USERNAME_DEFAULT,
892+
ENCRYPION_PASSWORD_DEFAULT),
893+
String.format("createSecret failed for %s", encryptionSecretName));
894+
895+
// create WDT config map without any files
896+
createConfigMapAndVerify("empty-cm", domainUid, domainNamespace, Collections.emptyList());
897+
String image = MII_BASIC_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG;
898+
899+
// create the domain object
900+
DomainResource domain = createDomainResourceWithConfigMap(domainUid,
901+
domainNamespace,
902+
adminSecretName,
903+
TEST_IMAGES_REPO_SECRET_NAME,
904+
encryptionSecretName,
905+
2,
906+
image,
907+
"empty-cm",
908+
180L,
909+
"mymii-cluster-resource");
910+
911+
logger.info("Creating a domain resource with model file image");
912+
createDomainAndVerify(domain, domainNamespace);
913+
checkDomainStatusConditionTypeHasExpectedStatus(domainUid, domainNamespace,
914+
DOMAIN_STATUS_CONDITION_COMPLETED_TYPE, "True");
915+
916+
//patch the domain with bad image
917+
//check the desired completed, available and failed status
918+
//verify the condition type Failed exists
919+
StringBuffer patchStr = new StringBuffer("[{");
920+
patchStr.append("\"op\": \"replace\",")
921+
.append(" \"path\": \"/spec/image\",")
922+
.append("\"value\": \"")
923+
.append("bad-mii-image:doesntexist")
924+
.append("\"}]");
925+
logger.info("PatchStr for imageUpdate: {0}", patchStr.toString());
926+
927+
assertTrue(patchDomainResource(domainUid, domainNamespace, patchStr),
928+
"patchDomainCustomResource(imageUpdate) failed");
929+
checkDomainStatusConditionTypeHasExpectedStatus(domainUid, domainNamespace,
930+
DOMAIN_STATUS_CONDITION_FAILED_TYPE, "True");
931+
932+
//fix the domain failure by patching the domain resource with good image
933+
patchStr = new StringBuffer("["
934+
+ "{");
935+
patchStr.append("\"op\": \"replace\",")
936+
.append(" \"path\": \"/spec/image\",")
937+
.append("\"value\": \"")
938+
.append(MII_BASIC_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG)
939+
.append("\"},")
940+
.append("{\"op\": \"add\",")
941+
.append(" \"path\": \"/spec/restartVersion\",").append("\"value\": ").append("\"1\"")
942+
.append("}"
943+
+ "]");
944+
logger.info("PatchStr for imageUpdate: {0}", patchStr.toString());
945+
946+
assertTrue(patchDomainResource(domainUid, domainNamespace, patchStr),
947+
"patchDomainCustomResource(imageUpdate) failed");
948+
949+
final String adminServerPodName = domainUid + "-admin-server";
950+
final String managedServerPrefix = domainUid + "-managed-server";
951+
952+
// check admin server pod is ready
953+
logger.info("Wait for admin server pod {0} to be ready in namespace {1}",
954+
adminServerPodName, domainNamespace);
955+
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);
956+
// check managed server pods are ready
957+
for (int i = 1; i <= 2; i++) {
958+
logger.info("Wait for managed server pod {0} to be ready in namespace {1}",
959+
managedServerPrefix + i, domainNamespace);
960+
checkPodReadyAndServiceExists(managedServerPrefix + i, domainUid, domainNamespace);
961+
}
962+
checkDomainStatusConditionTypeHasExpectedStatus(domainUid, domainNamespace,
963+
DOMAIN_STATUS_CONDITION_COMPLETED_TYPE, "True");
964+
checkDomainStatusConditionTypeExists(domainUid, domainNamespace, DOMAIN_STATUS_CONDITION_AVAILABLE_TYPE);
965+
}
966+
856967
// Create a domain resource with a custom ConfigMap
857968
private DomainResource createDomainResourceWithConfigMap(String domainUid,
858969
String domNamespace, String adminSecretName,

0 commit comments

Comments
 (0)