Skip to content

Commit fccc126

Browse files
authored
fix intermittent test failures in ItMiiUpdateDomainConfig (#2505)
1 parent 6e86018 commit fccc126

File tree

2 files changed

+101
-80
lines changed

2 files changed

+101
-80
lines changed

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

Lines changed: 37 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.verifyUpdateWebLogicCredential;
8585
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
8686
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
87-
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkSystemResourceConfiguration;
87+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.verifyCommandResultContainsMsg;
88+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.verifySystemResourceConfiguration;
8889
import static oracle.weblogic.kubernetes.utils.ConfigMapUtils.createConfigMapAndVerify;
8990
import static oracle.weblogic.kubernetes.utils.ExecCommand.exec;
9091
import static oracle.weblogic.kubernetes.utils.FileUtils.copyFileToPod;
@@ -276,19 +277,7 @@ void testMiiCustomEnv() {
276277
.append("?fields=notes&links=none\"")
277278
.append(" --silent ");
278279
logger.info("checkJmsServerConfig: curl command {0}", new String(curlString));
279-
ExecResult result = null;
280-
try {
281-
result = exec(new String(curlString), true);
282-
getLogger().info("The command returned exit value: "
283-
+ result.exitValue() + " command output: "
284-
+ result.stderr() + "\n" + result.stdout());
285-
assertTrue((result.exitValue() == 0),
286-
"curl command returned non zero value");
287-
assertTrue((result.stdout().contains("${DOMAIN_UID}~##!'%*$(ls)")),
288-
"Custom environment variable is not reflected in domin config");
289-
} catch (Exception e) {
290-
getLogger().info("Got exception, command failed with errors " + e.getMessage());
291-
}
280+
verifyCommandResultContainsMsg(new String(curlString), "${DOMAIN_UID}~##!'%*$(ls)");
292281
}
293282

294283
/**
@@ -324,7 +313,7 @@ void testMiiHttpServerLogsAreOnPV() {
324313
+ "(elapsed time {0} ms, remaining time {1} ms)",
325314
condition.getElapsedTimeInMS(),
326315
condition.getRemainingTimeInMS()))
327-
.until((Callable<Boolean>) () -> {
316+
.until(() -> {
328317
ExecResult execResult = assertDoesNotThrow(() -> execCommand(domainNamespace, pod, null, true,
329318
"/bin/sh", "-c", curlCmd));
330319
return execResult.toString().contains("HTTP/1.1 200 OK");
@@ -353,27 +342,19 @@ void testMiiCheckSystemResources() {
353342
int adminServiceNodePort
354343
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
355344
assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid");
356-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort, "JDBCSystemResources",
357-
"TestDataSource", "200"), "JDBCSystemResource not found");
345+
346+
verifySystemResourceConfiguration(adminServiceNodePort, "JDBCSystemResources", "TestDataSource", "200");
358347
logger.info("Found the JDBCSystemResource configuration");
359348

360-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort,"JMSSystemResources",
361-
"TestClusterJmsModule", "200"), "JMSSystemResources not found");
349+
verifySystemResourceConfiguration(adminServiceNodePort,"JMSSystemResources", "TestClusterJmsModule", "200");
362350
logger.info("Found the JMSSystemResource configuration");
363351

364-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort,"WLDFSystemResources",
365-
"TestWldfModule", "200"), "WLDFSystemResources not found");
352+
verifySystemResourceConfiguration(adminServiceNodePort,"WLDFSystemResources", "TestWldfModule", "200");
366353
logger.info("Found the WLDFSystemResource configuration");
367354

368-
ExecResult result = null;
369-
result = checkJdbcRuntime("TestDataSource");
370-
logger.info("checkJdbcRuntime: returned {0}", result.toString());
371-
assertTrue(result.stdout().contains("jdbc:oracle:thin:localhost"),
372-
String.format("DB URL does not match with RuntimeMBean Info"));
373-
assertTrue(result.stdout().contains("scott"),
374-
String.format("DB user name does not match with RuntimeMBean Info"));
355+
verifyJdbcRuntime("TestDataSource", "jdbc:oracle:thin:localhost");
356+
verifyJdbcRuntime("TestDataSource", "scott");
375357
logger.info("Found the JDBCSystemResource configuration");
376-
377358
}
378359

379360
/**
@@ -434,10 +415,8 @@ void testMiiDeleteSystemResources() {
434415
int adminServiceNodePort
435416
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
436417
assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid");
437-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort, "JDBCSystemResources",
438-
"TestDataSource", "404"), "JDBCSystemResource should be deleted");
439-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort, "JMSSystemResources",
440-
"TestClusterJmsModule", "404"), "JMSSystemResources should be deleted");
418+
verifySystemResourceConfiguration(adminServiceNodePort, "JDBCSystemResources", "TestDataSource", "404");
419+
verifySystemResourceConfiguration(adminServiceNodePort, "JMSSystemResources", "TestClusterJmsModule", "404");
441420
}
442421

443422
/**
@@ -500,12 +479,11 @@ void testMiiAddSystemResources() {
500479
int adminServiceNodePort
501480
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
502481
assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid");
503-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort,"JDBCSystemResources",
504-
"TestDataSource2", "200"), "JDBCSystemResource not found");
482+
483+
verifySystemResourceConfiguration(adminServiceNodePort,"JDBCSystemResources", "TestDataSource2", "200");
505484
logger.info("Found the JDBCSystemResource configuration");
506485

507-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort, "JMSSystemResources",
508-
"TestClusterJmsModule2", "200"), "JMSSystemResources not found");
486+
verifySystemResourceConfiguration(adminServiceNodePort, "JMSSystemResources", "TestClusterJmsModule2", "200");
509487
logger.info("Found the JMSSystemResource configuration");
510488

511489
// check JMS logs are written on PV
@@ -566,8 +544,7 @@ void testMiiAddDynmicClusteriWithNoReplica() {
566544
String newServerPodName = domainUid + "-config-server1";
567545
checkPodNotCreated(newServerPodName, domainUid, domainNamespace);
568546

569-
boolean isServerConfigured = checkManagedServerConfiguration("config-server1");
570-
assertTrue(isServerConfigured, "Could not find new managed server configuration");
547+
verifyManagedServerConfiguration("config-server1");
571548
logger.info("Found new managed server configuration");
572549
}
573550

@@ -643,8 +620,7 @@ void testMiiAddDynamicCluster() {
643620
checkPodReady(newServerPodName, domainUid, domainNamespace);
644621
checkServiceExists(newServerPodName, domainNamespace);
645622

646-
boolean isServerConfigured = checkManagedServerConfiguration("dynamic-server1");
647-
assertTrue(isServerConfigured, "Could not find new managed server configuration");
623+
verifyManagedServerConfiguration("dynamic-server1");
648624
logger.info("Found new managed server configuration");
649625
}
650626

@@ -717,8 +693,7 @@ void testMiiAddConfiguredCluster() {
717693
checkPodReady(newServerPodName, domainUid, domainNamespace);
718694
checkServiceExists(newServerPodName, domainNamespace);
719695

720-
boolean isServerConfigured = checkManagedServerConfiguration("config-server1");
721-
assertTrue(isServerConfigured, "Could not find new managed server configuration");
696+
verifyManagedServerConfiguration("config-server1");
722697
logger.info("Found new managed server configuration");
723698
}
724699

@@ -1051,36 +1026,23 @@ private void checkPodNotCreated(String podName, String domainUid, String domName
10511026
podName, domNamespace)));
10521027
}
10531028

1054-
/*
1055-
* Verify the server MBEAN configuration through rest API.
1056-
* @param managedServer name of the managed server
1057-
* @returns true if MBEAN is found otherwise false
1058-
**/
1059-
private boolean checkManagedServerConfiguration(String managedServer) {
1060-
ExecResult result = null;
1029+
private void verifyManagedServerConfiguration(String managedServer) {
1030+
10611031
int adminServiceNodePort
10621032
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
1033+
10631034
checkCluster = new StringBuffer("status=$(curl --user weblogic:welcome1 ");
10641035
checkCluster.append("http://" + K8S_NODEPORT_HOST + ":" + adminServiceNodePort)
1065-
.append("/management/tenant-monitoring/servers/")
1066-
.append(managedServer)
1067-
.append(" --silent --show-error ")
1068-
.append(" -o /dev/null")
1069-
.append(" -w %{http_code});")
1070-
.append("echo ${status}");
1036+
.append("/management/tenant-monitoring/servers/")
1037+
.append(managedServer)
1038+
.append(" --silent --show-error ")
1039+
.append(" -o /dev/null")
1040+
.append(" -w %{http_code});")
1041+
.append("echo ${status}");
10711042
logger.info("checkManagedServerConfiguration: curl command {0}", new String(checkCluster));
1072-
try {
1073-
result = exec(new String(checkCluster), true);
1074-
} catch (Exception ex) {
1075-
logger.info("Exception in checkManagedServerConfiguration() {0}", ex);
1076-
return false;
1077-
}
1078-
logger.info("checkManagedServerConfiguration: curl command returned {0}", result.toString());
1079-
if (result.stdout().equals("200")) {
1080-
return true;
1081-
} else {
1082-
return false;
1083-
}
1043+
1044+
verifyCommandResultContainsMsg(new String(checkCluster), "200");
1045+
10841046
}
10851047

10861048
// Crate a ConfigMap with a model file to add a new WebLogic cluster
@@ -1108,25 +1070,20 @@ private void createClusterConfigMap(String configMapName, String modelFile) {
11081070
assertTrue(cmCreated, String.format("createConfigMap failed while creating ConfigMap %s", configMapName));
11091071
}
11101072

1111-
private ExecResult checkJdbcRuntime(String resourcesName) {
1073+
private void verifyJdbcRuntime(String resourcesName, String expectedOutput) {
11121074
int adminServiceNodePort
11131075
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
11141076
ExecResult result = null;
11151077

11161078
curlString = new StringBuffer("curl --user weblogic:welcome1 ");
11171079
curlString.append("http://" + K8S_NODEPORT_HOST + ":" + adminServiceNodePort)
1118-
.append("/management/wls/latest/datasources/id/")
1119-
.append(resourcesName)
1120-
.append("/")
1121-
.append(" --silent --show-error ");
1080+
.append("/management/wls/latest/datasources/id/")
1081+
.append(resourcesName)
1082+
.append("/")
1083+
.append(" --silent --show-error ");
11221084
logger.info("checkJdbcRuntime: curl command {0}", new String(curlString));
1123-
try {
1124-
result = exec(new String(curlString), true);
1125-
} catch (Exception ex) {
1126-
logger.info("checkJdbcRuntime: caught unexpected exception {0}", ex);
1127-
return null;
1128-
}
1129-
return result;
1085+
1086+
verifyCommandResultContainsMsg(new String(curlString), expectedOutput);
11301087
}
11311088

11321089
private static void createJobToChangePermissionsOnPvHostPath(String pvName, String pvcName, String namespace) {

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonTestUtils.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,36 @@ public static boolean checkSystemResourceConfiguration(int nodePort, String reso
442442
.executeAndVerify(expectedStatusCode);
443443
}
444444

445+
/**
446+
* verify the system resource configuration using REST API.
447+
* @param nodePort admin node port
448+
* @param resourcesType type of the resource
449+
* @param resourcesName name of the resource
450+
* @param expectedStatusCode expected status code
451+
*/
452+
public static void verifySystemResourceConfiguration(int nodePort, String resourcesType,
453+
String resourcesName, String expectedStatusCode) {
454+
final LoggingFacade logger = getLogger();
455+
StringBuffer curlString = new StringBuffer("status=$(curl --user ");
456+
curlString.append(ADMIN_USERNAME_DEFAULT + ":" + ADMIN_PASSWORD_DEFAULT)
457+
.append(" http://" + K8S_NODEPORT_HOST + ":" + nodePort)
458+
.append("/management/weblogic/latest/domainConfig")
459+
.append("/")
460+
.append(resourcesType)
461+
.append("/")
462+
.append(resourcesName)
463+
.append("/")
464+
.append(" --silent --show-error ")
465+
.append(" -o /dev/null ")
466+
.append(" -w %{http_code});")
467+
.append("echo ${status}");
468+
logger.info("checkSystemResource: curl command {0}", new String(curlString));
469+
470+
verifyCommandResultContainsMsg(new String(curlString), expectedStatusCode);
471+
}
472+
473+
474+
445475
/**
446476
* Check the system resource configuration using REST API.
447477
* @param nodePort admin node port
@@ -736,4 +766,38 @@ private static boolean isLocalPortFree(int port) {
736766
}
737767
}
738768
}
769+
770+
/**
771+
* Verify the command result contains expected message.
772+
*
773+
* @param command the command to execute
774+
* @param expectedMsg the expected message in the command output
775+
*/
776+
public static void verifyCommandResultContainsMsg(String command, String expectedMsg) {
777+
withStandardRetryPolicy.conditionEvaluationListener(
778+
condition -> getLogger().info("Waiting until command result contains expected message \"{0}\" "
779+
+ "(elapsed time {1} ms, remaining time {2} ms)",
780+
expectedMsg,
781+
condition.getElapsedTimeInMS(),
782+
condition.getRemainingTimeInMS()))
783+
.until(() -> {
784+
785+
ExecResult result;
786+
try {
787+
result = exec(command, true);
788+
getLogger().info("The command returned exit value: " + result.exitValue()
789+
+ " command output: " + result.stderr() + "\n" + result.stdout());
790+
791+
if (result == null || result.exitValue() != 0 || result.stdout() == null) {
792+
return false;
793+
}
794+
795+
return result.stdout().contains(expectedMsg);
796+
797+
} catch (Exception e) {
798+
getLogger().info("Got exception, command failed with errors " + e.getMessage());
799+
return false;
800+
}
801+
});
802+
}
739803
}

0 commit comments

Comments
 (0)