4646import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
4747import static oracle .weblogic .kubernetes .TestConstants .BASE_IMAGES_REPO ;
4848import static oracle .weblogic .kubernetes .TestConstants .BASE_IMAGES_REPO_SECRET_NAME ;
49+ import static oracle .weblogic .kubernetes .TestConstants .CLUSTER_VERSION ;
4950import static oracle .weblogic .kubernetes .TestConstants .DB_IMAGE_TO_USE_IN_SPEC ;
5051import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
5152import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_STATUS_CONDITION_AVAILABLE_TYPE ;
5253import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_STATUS_CONDITION_COMPLETED_TYPE ;
5354import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_STATUS_CONDITION_FAILED_TYPE ;
55+ import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
5456import static oracle .weblogic .kubernetes .TestConstants .FMWINFRA_IMAGE_NAME ;
5557import static oracle .weblogic .kubernetes .TestConstants .FMWINFRA_IMAGE_TAG ;
5658import static oracle .weblogic .kubernetes .TestConstants .FMWINFRA_IMAGE_TO_USE_IN_SPEC ;
6466import static oracle .weblogic .kubernetes .actions .TestActions .deleteConfigMap ;
6567import static oracle .weblogic .kubernetes .actions .TestActions .patchClusterCustomResource ;
6668import static oracle .weblogic .kubernetes .actions .impl .Domain .patchDomainCustomResource ;
69+ import static oracle .weblogic .kubernetes .assertions .TestAssertions .clusterExists ;
70+ import static oracle .weblogic .kubernetes .assertions .TestAssertions .domainExists ;
6771import static oracle .weblogic .kubernetes .assertions .TestAssertions .domainStatusReasonMatches ;
6872import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterAndVerify ;
6973import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterResource ;
7276import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
7377import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getUniqueName ;
7478import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
79+ import static oracle .weblogic .kubernetes .utils .ConfigMapUtils .configMapExist ;
7580import static oracle .weblogic .kubernetes .utils .ConfigMapUtils .createConfigMapFromFiles ;
7681import static oracle .weblogic .kubernetes .utils .DbUtils .createRcuAccessSecret ;
7782import static oracle .weblogic .kubernetes .utils .DbUtils .setupDBandRCUschema ;
@@ -108,16 +113,13 @@ class ItDiagnosticsFailedCondition {
108113
109114 private static String domainNamespace = null ;
110115 int replicaCount = 2 ;
111- String wlClusterName = "cluster-1" ;
116+ private String wlClusterName = "cluster-1" ;
112117
113118
114119 private static String adminSecretName ;
115120 private static String encryptionSecretName ;
116121 private static final String domainUid = "diagnosticsdomain" ;
117122
118- private static String opServiceAccount = null ;
119- private static String opNamespace = null ;
120-
121123 private static LoggingFacade logger = null ;
122124 private static List <String > ns ;
123125
@@ -134,14 +136,14 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
134136 logger = getLogger ();
135137 logger .info ("Assign a unique namespace for operator" );
136138 assertNotNull (namespaces .get (0 ), "Namespace is null" );
137- opNamespace = namespaces .get (0 );
139+ String opNamespace = namespaces .get (0 );
138140
139141 logger .info ("Assign a unique namespace for WebLogic domain" );
140142 assertNotNull (namespaces .get (1 ), "Namespace is null" );
141143 domainNamespace = namespaces .get (1 );
142144
143145 // set the service account name for the operator
144- opServiceAccount = opNamespace + "-sa" ;
146+ String opServiceAccount = opNamespace + "-sa" ;
145147
146148 // install and verify operator with REST API
147149 installAndVerifyOperator (opNamespace , opServiceAccount , true , 0 , domainNamespace );
@@ -206,9 +208,15 @@ void testBadModelFileStatus() {
206208 if (!testPassed ) {
207209 LoggingUtil .generateLog (this , ns );
208210 }
209- deleteDomainResource (domainNamespace , domainName );
210- deleteConfigMap (badModelFileCm , domainNamespace );
211- deleteClusterCustomResource (clusterResName , domainNamespace );
211+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
212+ deleteDomainResource (domainNamespace , domainName );
213+ }
214+ if (assertDoesNotThrow (() -> configMapExist (domainNamespace , badModelFileCm ).call ())) {
215+ deleteConfigMap (badModelFileCm , domainNamespace );
216+ }
217+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
218+ deleteClusterCustomResource (clusterResName , domainNamespace );
219+ }
212220 }
213221 }
214222
@@ -244,17 +252,19 @@ void testReplicasTooHigh() {
244252 "waiting for domain status condition reason ReplicasTooHigh exists"
245253 );
246254
247- // remove after debug
255+ // Need to patch the cluster first, otherwise the domain can not be patched
256+ // You will get this error:
257+ // the replica count of cluster 'cluster-1' would exceed the cluster size '5' when patching the domain
248258 String patchStr
249259 = "["
250260 + "{\" op\" : \" replace\" , \" path\" : \" /spec/replicas\" , \" value\" : 2}"
251261 + "]" ;
252262 V1Patch patch = new V1Patch (patchStr );
253263 logger .info ("Patching cluster resource using patch string {0} " , patchStr );
264+
254265 assertTrue (patchClusterCustomResource (clusterResName , domainNamespace ,
255266 patch , V1Patch .PATCH_FORMAT_JSON_PATCH ), "Failed to patch cluster" );
256- //end of debug
257-
267+
258268 patchStr = "[{\" op\" : \" replace\" , "
259269 + "\" path\" : \" /spec/webLogicCredentialsSecret/name\" , \" value\" : \" weblogic-credentials-foo\" }]" ;
260270 logger .info ("PatchStr for domainHome: {0}" , patchStr );
@@ -286,8 +296,12 @@ void testReplicasTooHigh() {
286296 if (!testPassed ) {
287297 LoggingUtil .generateLog (this , ns );
288298 }
289- deleteDomainResource (domainNamespace , domainName );
290- deleteClusterCustomResource (clusterResName , domainNamespace );
299+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
300+ deleteDomainResource (domainNamespace , domainName );
301+ }
302+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
303+ deleteClusterCustomResource (clusterResName , domainNamespace );
304+ }
291305 }
292306 }
293307
@@ -334,8 +348,12 @@ void testReplicasTooHighNegative() {
334348 if (!testPassed ) {
335349 LoggingUtil .generateLog (this , ns );
336350 }
337- deleteDomainResource (domainNamespace , domainName );
338- deleteClusterCustomResource (clusterResName , domainNamespace );
351+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
352+ deleteDomainResource (domainNamespace , domainName );
353+ }
354+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
355+ deleteClusterCustomResource (clusterResName , domainNamespace );
356+ }
339357 }
340358 }
341359
@@ -371,8 +389,12 @@ void testImageDoesnotExist() {
371389 if (!testPassed ) {
372390 LoggingUtil .generateLog (this , ns );
373391 }
374- deleteDomainResource (domainNamespace , domainName );
375- deleteClusterCustomResource (clusterResName , domainNamespace );
392+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
393+ deleteDomainResource (domainNamespace , domainName );
394+ }
395+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
396+ deleteClusterCustomResource (clusterResName , domainNamespace );
397+ }
376398 }
377399 }
378400
@@ -408,8 +430,12 @@ void testImagePullSecretDoesnotExist() {
408430 if (!testPassed ) {
409431 LoggingUtil .generateLog (this , ns );
410432 }
411- deleteDomainResource (domainNamespace , domainName );
412- deleteClusterCustomResource (clusterResName , domainNamespace );
433+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
434+ deleteDomainResource (domainNamespace , domainName );
435+ }
436+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
437+ deleteClusterCustomResource (clusterResName , domainNamespace );
438+ }
413439 }
414440 }
415441
@@ -448,8 +474,12 @@ void testIncorrectImagePullSecret() {
448474 if (!testPassed ) {
449475 LoggingUtil .generateLog (this , ns );
450476 }
451- deleteDomainResource (domainNamespace , domainName );
452- deleteClusterCustomResource (clusterResName , domainNamespace );
477+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
478+ deleteDomainResource (domainNamespace , domainName );
479+ }
480+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
481+ deleteClusterCustomResource (clusterResName , domainNamespace );
482+ }
453483 }
454484 }
455485
@@ -531,8 +561,12 @@ void testNonexistentPVC() {
531561 if (!testPassed ) {
532562 LoggingUtil .generateLog (this , ns );
533563 }
534- deleteClusterCustomResource (clusterResName , domainNamespace );
535- deleteDomainResource (domainNamespace , domainName );
564+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
565+ deleteClusterCustomResource (clusterResName , domainNamespace );
566+ }
567+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
568+ deleteDomainResource (domainNamespace , domainName );
569+ }
536570 }
537571 }
538572
@@ -567,8 +601,12 @@ void testNonexistentAdminSecret() {
567601 if (!testPassed ) {
568602 LoggingUtil .generateLog (this , ns );
569603 }
570- deleteDomainResource (domainNamespace , domainName );
571- deleteClusterCustomResource (clusterResName , domainNamespace );
604+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
605+ deleteDomainResource (domainNamespace , domainName );
606+ }
607+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
608+ deleteClusterCustomResource (clusterResName , domainNamespace );
609+ }
572610 }
573611 }
574612
@@ -611,8 +649,12 @@ void testInvalidNodePort() {
611649 if (!testPassed ) {
612650 LoggingUtil .generateLog (this , ns );
613651 }
614- deleteDomainResource (domainNamespace , domainName );
615- deleteClusterCustomResource (clusterResName , domainNamespace );
652+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
653+ deleteDomainResource (domainNamespace , domainName );
654+ }
655+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
656+ deleteClusterCustomResource (clusterResName , domainNamespace );
657+ }
616658 }
617659 }
618660
@@ -650,8 +692,12 @@ void testIntrospectorTimeoutFailure() {
650692 if (!testPassed ) {
651693 LoggingUtil .generateLog (this , ns );
652694 }
653- deleteDomainResource (domainNamespace , domainName );
654- deleteClusterCustomResource (clusterResName , domainNamespace );
695+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
696+ deleteDomainResource (domainNamespace , domainName );
697+ }
698+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
699+ deleteClusterCustomResource (clusterResName , domainNamespace );
700+ }
655701 }
656702 }
657703
@@ -671,15 +717,13 @@ void testMSBootFailureStatus() {
671717 String domainName = getDomainName ();
672718 String clusterResName = getClusterResName (domainName );
673719 try {
674- String fmwMiiImage = null ;
675720 String rcuSchemaPrefix = "FMWDOMAINMII" ;
676721 String oracleDbUrlPrefix = "oracledb." ;
677- String oracleDbSuffix = null ;
678722 String rcuSchemaPassword = "Oradoc_db1" ;
679723 String modelFile = "model-singleclusterdomain-sampleapp-jrf.yaml" ;
680724
681725 final int dbListenerPort = getNextFreePort ();
682- oracleDbSuffix = ".svc.cluster.local:" + dbListenerPort + "/devpdb.k8s" ;
726+ String oracleDbSuffix = ".svc.cluster.local:" + dbListenerPort + "/devpdb.k8s" ;
683727 String dbUrl = oracleDbUrlPrefix + domainNamespace + oracleDbSuffix ;
684728
685729 String rcuaccessSecretName = domainName + "-rcu-access" ;
@@ -712,7 +756,7 @@ rcuSchemaPrefix, domainNamespace, getNextFreePort(), dbUrl, dbListenerPort),
712756
713757 logger .info ("Create an image with jrf model file" );
714758 final List <String > modelList = Collections .singletonList (MODEL_DIR + "/" + modelFile );
715- fmwMiiImage = createMiiImageAndVerify (
759+ String fmwMiiImage = createMiiImageAndVerify (
716760 "jrf-mii-image-status" ,
717761 modelList ,
718762 Collections .singletonList (MII_BASIC_APP_NAME ),
@@ -800,8 +844,12 @@ rcuSchemaPrefix, domainNamespace, getNextFreePort(), dbUrl, dbListenerPort),
800844 if (!testPassed ) {
801845 LoggingUtil .generateLog (this , ns );
802846 }
803- deleteClusterCustomResource (clusterResName , domainNamespace );
804- deleteDomainResource (domainNamespace , domainName );
847+ if (assertDoesNotThrow (() -> clusterExists (clusterResName , CLUSTER_VERSION , domainNamespace ).call ())) {
848+ deleteClusterCustomResource (clusterResName , domainNamespace );
849+ }
850+ if (assertDoesNotThrow (() -> domainExists (domainName , DOMAIN_VERSION , domainNamespace ).call ())) {
851+ deleteDomainResource (domainNamespace , domainName );
852+ }
805853 }
806854 }
807855
0 commit comments