Skip to content

Commit eb6de67

Browse files
authored
fix intermittent test failures in nightly run in ItMiiAuxiliaryImage (#2491)
* fix intermittent test failure in nightly parallel run * add private methods for introspector pod log
1 parent 2f729d1 commit eb6de67

File tree

1 file changed

+65
-15
lines changed

1 file changed

+65
-15
lines changed

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

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.Map;
1515

1616
import io.kubernetes.client.custom.V1Patch;
17+
import io.kubernetes.client.openapi.ApiException;
18+
import io.kubernetes.client.openapi.models.V1Pod;
1719
import oracle.weblogic.domain.AuxiliaryImage;
1820
import oracle.weblogic.domain.Domain;
1921
import oracle.weblogic.kubernetes.actions.impl.primitive.Command;
@@ -59,6 +61,8 @@
5961
import static oracle.weblogic.kubernetes.actions.TestActions.dockerTag;
6062
import static oracle.weblogic.kubernetes.actions.TestActions.getDomainCustomResource;
6163
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;
6266
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
6367
import static oracle.weblogic.kubernetes.actions.TestActions.now;
6468
import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource;
@@ -79,7 +83,7 @@
7983
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword;
8084
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.deleteDomainResource;
8185
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;
8387
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getPodCreationTime;
8488
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getPodsWithTimeStamps;
8589
import static oracle.weblogic.kubernetes.utils.FileUtils.copyFileFromPod;
@@ -476,8 +480,7 @@ void testErrorPathDomainMismatchMountPath() {
476480

477481
// check the introspector pod log contains the expected error message
478482
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);
481484

482485
// check the domain event contains the expected error message
483486
checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED,
@@ -559,9 +562,7 @@ void testErrorPathDomainMissingWDTBinary() {
559562
String expectedErrorMsg = "The domain resource 'spec.domainHomeSourceType' is 'FromModel' and "
560563
+ "a WebLogic Deploy Tool (WDT) install is not located at 'spec.configuration.model.wdtInstallHome' "
561564
+ "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);
565566

566567
// check the domain event contains the expected error message
567568
checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED,
@@ -647,9 +648,7 @@ void testErrorPathDomainMissingDomainConfig() {
647648
// check the introspector pod log contains the expected error message
648649
String expectedErrorMsg =
649650
"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);
653652

654653
// check the domain event contains the expected error message
655654
checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED,
@@ -723,9 +722,7 @@ void testErrorPathDomainWithFailCustomMountCommand() {
723722

724723
// check the introspector pod log contains the expected error message
725724
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);
729726

730727
// check the domain event contains the expected error message
731728
checkDomainEventContainsExpectedMsg(opNamespace, domainNamespace, domainUid, DOMAIN_PROCESSING_FAILED,
@@ -845,9 +842,7 @@ void testErrorPathFilePermission() {
845842

846843
// check the introspector pod log contains the expected error message
847844
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);
851846

852847
// check the domain event contains the expected error message
853848
checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED,
@@ -1218,4 +1213,59 @@ private String checkWDTVersion(String domainNamespace, String auxiliaryImagePath
12181213

12191214
return Files.readAllLines(Paths.get(RESULTS_ROOT, "/WDTversion.txt")).get(0);
12201215
}
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+
12211271
}

0 commit comments

Comments
 (0)