|
14 | 14 | import java.util.Map; |
15 | 15 |
|
16 | 16 | import io.kubernetes.client.custom.V1Patch; |
| 17 | +import io.kubernetes.client.openapi.ApiException; |
| 18 | +import io.kubernetes.client.openapi.models.V1Pod; |
17 | 19 | import oracle.weblogic.domain.AuxiliaryImage; |
18 | 20 | import oracle.weblogic.domain.Domain; |
19 | 21 | import oracle.weblogic.kubernetes.actions.impl.primitive.Command; |
|
59 | 61 | import static oracle.weblogic.kubernetes.actions.TestActions.dockerTag; |
60 | 62 | import static oracle.weblogic.kubernetes.actions.TestActions.getDomainCustomResource; |
61 | 63 | import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorPodName; |
| 64 | +import static oracle.weblogic.kubernetes.actions.TestActions.getPod; |
| 65 | +import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog; |
62 | 66 | import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort; |
63 | 67 | import static oracle.weblogic.kubernetes.actions.TestActions.now; |
64 | 68 | import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource; |
|
79 | 83 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword; |
80 | 84 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.deleteDomainResource; |
81 | 85 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getExternalServicePodName; |
82 | | -import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getIntrospectorPodName; |
| 86 | +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getIntrospectJobName; |
83 | 87 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getPodCreationTime; |
84 | 88 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getPodsWithTimeStamps; |
85 | 89 | import static oracle.weblogic.kubernetes.utils.FileUtils.copyFileFromPod; |
@@ -476,8 +480,7 @@ void testErrorPathDomainMismatchMountPath() { |
476 | 480 |
|
477 | 481 | // check the introspector pod log contains the expected error message |
478 | 482 | String expectedErrorMsg = "Auxiliary Image: Dir '/errorpath' doesn't exist or is empty. Exiting."; |
479 | | - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace)); |
480 | | - checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); |
| 483 | + verifyIntrospectorPodLogContainsExpectedErrorMsg(domainUid, errorpathDomainNamespace, expectedErrorMsg); |
481 | 484 |
|
482 | 485 | // check the domain event contains the expected error message |
483 | 486 | checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, |
@@ -559,9 +562,7 @@ void testErrorPathDomainMissingWDTBinary() { |
559 | 562 | String expectedErrorMsg = "The domain resource 'spec.domainHomeSourceType' is 'FromModel' and " |
560 | 563 | + "a WebLogic Deploy Tool (WDT) install is not located at 'spec.configuration.model.wdtInstallHome' " |
561 | 564 | + "which is currently set to '/auxiliary/weblogic-deploy'"; |
562 | | - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace), |
563 | | - "Can't get introspector pod's name"); |
564 | | - checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); |
| 565 | + verifyIntrospectorPodLogContainsExpectedErrorMsg(domainUid, errorpathDomainNamespace, expectedErrorMsg); |
565 | 566 |
|
566 | 567 | // check the domain event contains the expected error message |
567 | 568 | checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, |
@@ -647,9 +648,7 @@ void testErrorPathDomainMissingDomainConfig() { |
647 | 648 | // check the introspector pod log contains the expected error message |
648 | 649 | String expectedErrorMsg = |
649 | 650 | "createDomain did not find the required domainInfo section in the model file /auxiliary/models/model.jms2.yaml"; |
650 | | - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace), |
651 | | - "Get introspector's pod name failed"); |
652 | | - checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); |
| 651 | + verifyIntrospectorPodLogContainsExpectedErrorMsg(domainUid, errorpathDomainNamespace, expectedErrorMsg); |
653 | 652 |
|
654 | 653 | // check the domain event contains the expected error message |
655 | 654 | checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, |
@@ -723,9 +722,7 @@ void testErrorPathDomainWithFailCustomMountCommand() { |
723 | 722 |
|
724 | 723 | // check the introspector pod log contains the expected error message |
725 | 724 | String expectedErrorMsg = "Auxiliary Image: Command 'exit 1' execution failed in container"; |
726 | | - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, domainNamespace), |
727 | | - "Get introspector's pod name failed"); |
728 | | - checkPodLogContainsString(domainNamespace, introspectorPodName, expectedErrorMsg); |
| 725 | + verifyIntrospectorPodLogContainsExpectedErrorMsg(domainUid, domainNamespace, expectedErrorMsg); |
729 | 726 |
|
730 | 727 | // check the domain event contains the expected error message |
731 | 728 | checkDomainEventContainsExpectedMsg(opNamespace, domainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, |
@@ -845,9 +842,7 @@ void testErrorPathFilePermission() { |
845 | 842 |
|
846 | 843 | // check the introspector pod log contains the expected error message |
847 | 844 | String expectedErrorMsg = "cp: can't open '/auxiliary/test1.txt': Permission denied"; |
848 | | - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace), |
849 | | - "Can't get introspector's pod name"); |
850 | | - checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); |
| 845 | + verifyIntrospectorPodLogContainsExpectedErrorMsg(domainUid, errorpathDomainNamespace, expectedErrorMsg); |
851 | 846 |
|
852 | 847 | // check the domain event contains the expected error message |
853 | 848 | checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, |
@@ -1218,4 +1213,59 @@ private String checkWDTVersion(String domainNamespace, String auxiliaryImagePath |
1218 | 1213 |
|
1219 | 1214 | return Files.readAllLines(Paths.get(RESULTS_ROOT, "/WDTversion.txt")).get(0); |
1220 | 1215 | } |
| 1216 | + |
| 1217 | + private boolean introspectorPodLogContainsExpectedErrorMsg(String domainUid, |
| 1218 | + String namespace, |
| 1219 | + String errormsg) { |
| 1220 | + String introspectPodName; |
| 1221 | + V1Pod introspectorPod; |
| 1222 | + |
| 1223 | + String introspectJobName = getIntrospectJobName(domainUid); |
| 1224 | + String labelSelector = String.format("weblogic.domainUID in (%s)", domainUid); |
| 1225 | + |
| 1226 | + try { |
| 1227 | + introspectorPod = getPod(namespace, labelSelector, introspectJobName); |
| 1228 | + } catch (ApiException apiEx) { |
| 1229 | + logger.severe("got ApiException while getting pod: {0}", apiEx); |
| 1230 | + return false; |
| 1231 | + } |
| 1232 | + |
| 1233 | + if (introspectorPod != null && introspectorPod.getMetadata() != null) { |
| 1234 | + introspectPodName = introspectorPod.getMetadata().getName(); |
| 1235 | + logger.info("found introspectore pod {0} in namespace {1}", introspectPodName, namespace); |
| 1236 | + } else { |
| 1237 | + return false; |
| 1238 | + } |
| 1239 | + |
| 1240 | + String introspectorLog; |
| 1241 | + try { |
| 1242 | + introspectorLog = getPodLog(introspectPodName, namespace); |
| 1243 | + logger.info("introspector log: {0}", introspectorLog); |
| 1244 | + } catch (ApiException apiEx) { |
| 1245 | + logger.severe("got ApiException while getting pod log: {0}", apiEx); |
| 1246 | + return false; |
| 1247 | + } |
| 1248 | + |
| 1249 | + return introspectorLog.contains(errormsg); |
| 1250 | + } |
| 1251 | + |
| 1252 | + private void verifyIntrospectorPodLogContainsExpectedErrorMsg(String domainUid, |
| 1253 | + String namespace, |
| 1254 | + String expectedErrorMsg) { |
| 1255 | + |
| 1256 | + // wait and check whether the introspector log contains the expected error message |
| 1257 | + logger.info("verifying that the introspector log contains the expected error message"); |
| 1258 | + withStandardRetryPolicy |
| 1259 | + .conditionEvaluationListener( |
| 1260 | + condition -> |
| 1261 | + logger.info( |
| 1262 | + "Checking for the log of introspector pod contains the expected error msg {0}. " |
| 1263 | + + "Elapsed time {1}ms, remaining time {2}ms", |
| 1264 | + expectedErrorMsg, |
| 1265 | + condition.getElapsedTimeInMS(), |
| 1266 | + condition.getRemainingTimeInMS())) |
| 1267 | + .until(() -> |
| 1268 | + introspectorPodLogContainsExpectedErrorMsg(domainUid, namespace, expectedErrorMsg)); |
| 1269 | + } |
| 1270 | + |
1221 | 1271 | } |
0 commit comments