Skip to content

Commit 259fa5d

Browse files
authored
fix ItMultiDomainModelsWithLoadBalancer#testLivenessProbe in release/3.4 (#3409)
* fix ItMultiDomainModelsWithLoadBalancer#testLivenessProbe in release/3.4
1 parent 6eb61d9 commit 259fa5d

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

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

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -419,38 +419,40 @@ void testLivenessProbe() {
419419
int numClusters = domain.getSpec().getClusters().size();
420420

421421
String serverName;
422+
String serverNamePrefix;
422423
if (numClusters > 1) {
423-
serverName = domainUid + "-" + clusterName + "-" + MANAGED_SERVER_NAME_BASE + "1";
424+
serverNamePrefix = domainUid + "-" + clusterName + "-" + MANAGED_SERVER_NAME_BASE;
424425
} else {
425-
serverName = domainUid + "-" + MANAGED_SERVER_NAME_BASE + "1";
426+
serverNamePrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE;
426427
}
427428

428429
// create file to kill server process
429430
File killServerScript = assertDoesNotThrow(() -> createScriptToKillServer(),
430431
"Failed to create script to kill server");
431432
logger.info("File/script created to kill server {0}", killServerScript);
432433

433-
checkPodReady(serverName, domainUid, domainNamespace);
434+
String server1Name = serverNamePrefix + "1";
435+
checkPodReady(server1Name, domainUid, domainNamespace);
434436

435437
// copy script to pod
436438
String destLocation = "/u01/killserver.sh";
437-
assertDoesNotThrow(() -> copyFileToPod(domainNamespace, serverName, "weblogic-server",
439+
assertDoesNotThrow(() -> copyFileToPod(domainNamespace, server1Name, "weblogic-server",
438440
killServerScript.toPath(), Paths.get(destLocation)),
439441
String.format("Failed to copy file %s to pod %s in namespace %s",
440-
killServerScript, serverName, domainNamespace));
441-
logger.info("File copied to Pod {0} in namespace {1}", serverName, domainNamespace);
442+
killServerScript, server1Name, domainNamespace));
443+
logger.info("File copied to Pod {0} in namespace {1}", server1Name, domainNamespace);
442444

443445
// get the restart count of the container in pod before liveness probe restarts
444446
final int beforeRestartCount =
445-
assertDoesNotThrow(() -> getContainerRestartCount(domainNamespace, null, serverName, null),
447+
assertDoesNotThrow(() -> getContainerRestartCount(domainNamespace, null, server1Name, null),
446448
String.format("Failed to get the restart count of the container from pod {0} in namespace {1}",
447-
serverName, domainNamespace));
449+
server1Name, domainNamespace));
448450
logger.info("Restart count before liveness probe {0}", beforeRestartCount);
449451

450452
// change file permissions
451-
ExecResult execResult = assertDoesNotThrow(() -> execCommand(domainNamespace, serverName, null,
453+
ExecResult execResult = assertDoesNotThrow(() -> execCommand(domainNamespace, server1Name, null,
452454
true, "/bin/sh", "-c", "chmod +x " + destLocation),
453-
String.format("Failed to change permissions for file %s in pod %s", destLocation, serverName));
455+
String.format("Failed to change permissions for file %s in pod %s", destLocation, server1Name));
454456
assertTrue(execResult.exitValue() == 0,
455457
String.format("Failed to change file %s permissions, stderr %s stdout %s", destLocation,
456458
execResult.stderr(), execResult.stdout()));
@@ -461,10 +463,10 @@ void testLivenessProbe() {
461463
* initiates a container restart.
462464
*/
463465
for (int i = 0; i < 3; i++) {
464-
execResult = assertDoesNotThrow(() -> execCommand(domainNamespace, serverName, null,
465-
true, "/bin/sh", "-c", destLocation + " " + serverName),
466+
execResult = assertDoesNotThrow(() -> execCommand(domainNamespace, server1Name, null,
467+
true, "/bin/sh", "-c", destLocation + " " + server1Name),
466468
String.format("Failed to execute script %s in pod %s namespace %s", destLocation,
467-
serverName, domainNamespace));
469+
server1Name, domainNamespace));
468470
logger.info("Command executed to kill server inside pod, exit value {0}, stdout {1}, stderr {2}",
469471
execResult.exitValue(), execResult.stdout(), execResult.stderr());
470472

@@ -476,16 +478,26 @@ void testLivenessProbe() {
476478
}
477479

478480
// check pod is ready
479-
checkPodReady(serverName, domainUid, domainNamespace);
481+
checkPodReady(server1Name, domainUid, domainNamespace);
480482

481483
// get the restart count of the container in pod after liveness probe restarts
482484
int afterRestartCount = assertDoesNotThrow(() ->
483-
getContainerRestartCount(domainNamespace, null, serverName, null),
485+
getContainerRestartCount(domainNamespace, null, server1Name, null),
484486
String.format("Failed to get the restart count of the container from pod {0} in namespace {1}",
485-
serverName, domainNamespace));
487+
server1Name, domainNamespace));
486488
assertTrue(afterRestartCount - beforeRestartCount == 1,
487489
String.format("Liveness probe did not start the container in pod %s in namespace %s",
488-
serverName, domainNamespace));
490+
server1Name, domainNamespace));
491+
492+
// check the sample app is accessible from admin server pod
493+
for (int i = 1; i <= replicaCount; i++) {
494+
testUntil(
495+
checkSampleAppReady(domainUid, domainNamespace, serverNamePrefix + i),
496+
logger,
497+
"sample app is accessible from server {0} in namespace {1}",
498+
serverNamePrefix + i,
499+
domainNamespace);
500+
}
489501

490502
//access application in managed servers through NGINX load balancer
491503
logger.info("Accessing the sample app through NGINX load balancer");
@@ -1240,4 +1252,15 @@ private void verifyAdminConsoleLoginUsingIngressController(String domainUid, Str
12401252
}
12411253
}
12421254

1255+
private Callable<Boolean> checkSampleAppReady(String domainUid, String domainNamespace, String serverName) {
1256+
return () -> {
1257+
String curlCmd = String.format("curl http://%s:%s/sample-war/index.jsp", serverName, MANAGED_SERVER_PORT);
1258+
String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE;
1259+
ExecResult execResult = assertDoesNotThrow(() -> execCommand(domainNamespace, adminServerPodName, null,
1260+
true, "/bin/sh", "-c", curlCmd),
1261+
String.format("Failed to execute curl command %s from pod %s in namespace %s", curlCmd,
1262+
adminServerPodName, domainNamespace));
1263+
return execResult.stdout().contains(serverName.substring(domainUid.length() + 1));
1264+
};
1265+
}
12431266
}

0 commit comments

Comments
 (0)