Skip to content

Commit b4145a3

Browse files
committed
Merge remote-tracking branch 'origin/develop' into checkstyle-enforcement
2 parents b85c522 + a2869d8 commit b4145a3

File tree

5 files changed

+74
-77
lines changed

5 files changed

+74
-77
lines changed

integration-tests/USECASES.MD

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ Java integration tests cover the below use cases:
1919

2020
**Advanced Use Cases**
2121

22-
6. Verify domain life cycle (destroy and create) should not have any impact on operator managing the domain and web app load balancing and admin external service.
22+
6. set precreateService true and verify that the services are created for the managed servers that are not started
2323
7. Cluster scale up/down using operator REST endpoint, webapp load balancing should adjust accordingly.
24-
8. Operator life cycle (destroy and create) should not impact the running domain.
24+
8. Verify that the services are created for the managed servers that are not started
25+
9. Verify domain life cycle (destroy and create) should not have any impact on operator managing the domain and web app load balancing and admin external service.
26+
10. Operator life cycle (destroy and create) should not impact the running domain.
2527

2628
Also the below use cases are covered for Quick test:
2729

28-
9. Verify the liveness probe by killing managed server 1 process 3 times to kick pod auto-restart.
29-
10. Shutdown the domain by changing domain `serverStartPolicy` to `NEVER`.
30+
11. Verify the liveness probe by killing managed server 1 process 3 times to kick pod auto-restart.
31+
12. Shutdown the domain by changing domain `serverStartPolicy` to `NEVER`.
3032

3133

3234
## Full test Configuration & Use Cases - Runs Quick test Configuration & Use cases and the below

integration-tests/src/test/java/oracle/kubernetes/operator/ItOperator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,9 @@ public void testDomainInImageUsingWdt() throws Exception {
508508

509509
private Domain testAdvancedUseCasesForADomain(Operator operator, Domain domain) throws Exception {
510510
if (!SMOKETEST) {
511+
domain.enablePrecreateService();
511512
testClusterScaling(operator, domain);
513+
domain.verifyServicesCreated(true);
512514
testDomainLifecyle(operator, domain);
513515
testOperatorLifecycle(operator, domain);
514516
}

integration-tests/src/test/java/oracle/kubernetes/operator/ItPodsRestart.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
218218
logTestBegin(testMethodName);
219219

220220
try {
221-
TestUtils.execAndPrintLog("docker images");
221+
TestUtils.exec("docker images", true);
222222
logger.info(
223223
"About to verifyDomainServerPodRestart for Domain: "
224224
+ domain.getDomainUid()
@@ -235,8 +235,8 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
235235
// tag image with repo name
236236
String tag =
237237
"docker tag " + getWeblogicImageName() + ":" + getWeblogicImageTag() + " " + newImage;
238-
TestUtils.execAndPrintLog(tag);
239-
TestUtils.execAndPrintLog("docker images");
238+
TestUtils.exec(tag, true);
239+
TestUtils.exec("docker images", true);
240240

241241
// login and push image to ocir
242242
TestUtils.loginAndPushImageToOcir(newImage);

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ public void verifyPodsCreated() throws Exception {
139139
* @throws Exception exception
140140
*/
141141
public void verifyServicesCreated() throws Exception {
142+
verifyServicesCreated(false);
143+
}
144+
145+
/**
146+
* verify services are created.
147+
*
148+
* @param precreateService - if true check services are created for configuredManagedServerCount
149+
* number of servers else check for initialManagedServerReplicas number of servers
150+
* @throws Exception exception
151+
*/
152+
public void verifyServicesCreated(boolean precreateService) throws Exception {
142153
// check admin service
143154
logger.info("Checking if admin service(" + domainUid + "-" + adminServerName + ") is created");
144155
TestUtils.checkServiceCreated(domainUid + "-" + adminServerName, domainNS);
@@ -155,7 +166,9 @@ public void verifyServicesCreated() throws Exception {
155166

156167
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
157168
// check managed server services
158-
for (int i = 1; i <= initialManagedServerReplicas; i++) {
169+
for (int i = 1;
170+
i <= (precreateService ? configuredManagedServerCount : initialManagedServerReplicas);
171+
i++) {
159172
logger.info(
160173
"Checking if managed service("
161174
+ domainUid
@@ -595,9 +608,7 @@ public void destroy() throws Exception {
595608
public void shutdown() throws Exception {
596609
int replicas = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
597610
String cmd = "kubectl delete domain " + domainUid + " -n " + domainNS;
598-
ExecResult result = TestUtils.exec(cmd.toString());
599-
String output = result.stdout().trim();
600-
logger.info("command to delete domain " + cmd + " \n returned " + output);
611+
ExecResult result = TestUtils.exec(cmd.toString(), true);
601612
verifyDomainDeleted(replicas);
602613
}
603614

@@ -608,15 +619,8 @@ public void shutdown() throws Exception {
608619
*/
609620
public void shutdownUsingServerStartPolicy() throws Exception {
610621
int replicas = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
611-
String cmd =
612-
"kubectl patch domain "
613-
+ domainUid
614-
+ " -n "
615-
+ domainNS
616-
+ " -p '{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}' --type merge";
617-
ExecResult result = TestUtils.exec(cmd);
618-
String output = result.stdout().trim();
619-
logger.info("command to shutdown domain " + cmd + " \n returned " + output);
622+
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}' ";
623+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
620624
verifyServerPodsDeleted(replicas);
621625
}
622626

@@ -626,19 +630,23 @@ public void shutdownUsingServerStartPolicy() throws Exception {
626630
* @throws Exception exception
627631
*/
628632
public void restartUsingServerStartPolicy() throws Exception {
629-
String cmd =
630-
"kubectl patch domain "
631-
+ domainUid
632-
+ " -n "
633-
+ domainNS
634-
+ " -p '{\"spec\":{\"serverStartPolicy\":\"IF_NEEDED\"}}' --type merge";
635-
ExecResult result = TestUtils.exec(cmd);
636-
String output = result.stdout().trim();
637-
logger.info("command to restart domain " + cmd + " \n returned " + output);
633+
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"IF_NEEDED\"}}'";
634+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
638635
verifyPodsCreated();
639636
verifyServersReady();
640637
}
641638

639+
/**
640+
* add precreateService true in domain.yaml.
641+
*
642+
* @throws Exception exception
643+
*/
644+
public void enablePrecreateService() throws Exception {
645+
String patchStr = "'{\"spec\":{\"serverService\":{\"precreateService\":true}}}'";
646+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
647+
verifyServicesCreated(true);
648+
}
649+
642650
/**
643651
* verify domain is deleted.
644652
*
@@ -1792,23 +1800,12 @@ public int getLoadBalancerWebPort() {
17921800
* @throws Exception exception
17931801
*/
17941802
public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Exception {
1795-
String cmd =
1796-
"kubectl patch domain "
1797-
+ domainUid
1798-
+ " -n "
1799-
+ domainNS
1800-
+ " -p '{\"spec\":{\"managedServers\":[{\"serverName\":\""
1803+
logger.info("About to shutdown managed server <" + msName + ">");
1804+
String patchStr =
1805+
"'{\"spec\":{\"managedServers\":[{\"serverName\":\""
18011806
+ msName
1802-
+ "\",\"serverStartPolicy\":\"NEVER\"}]}}' --type merge";
1803-
1804-
logger.info("command to shutdown managed server <" + msName + "> is: " + cmd);
1805-
1806-
ExecResult result = ExecCommand.exec(cmd);
1807-
if (result.exitValue() != 0) {
1808-
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
1809-
}
1810-
String output = result.stdout().trim();
1811-
logger.info("output from shutting down managed server:\n" + output);
1807+
+ "\",\"serverStartPolicy\":\"NEVER\"}]}}' ";
1808+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
18121809

18131810
TestUtils.checkPodDeleted(domainUid + "-" + msName, domainNS);
18141811
}
@@ -1819,23 +1816,12 @@ public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Ex
18191816
* @throws Exception exception
18201817
*/
18211818
public void restartManagedServerUsingServerStartPolicy(String msName) throws Exception {
1822-
String cmd =
1823-
"kubectl patch domain "
1824-
+ domainUid
1825-
+ " -n "
1826-
+ domainNS
1827-
+ " -p '{\"spec\":{\"managedServers\":[{\"serverName\":\""
1819+
logger.info("About to restart managed server <" + msName + "> ");
1820+
String patchStr =
1821+
"'{\"spec\":{\"managedServers\":[{\"serverName\":\""
18281822
+ msName
1829-
+ "\",\"serverStartPolicy\":\"IF_NEEDED\"}]}}' --type merge";
1830-
1831-
logger.info("command to restart managed server <" + msName + "> is: " + cmd);
1832-
1833-
ExecResult result = ExecCommand.exec(cmd);
1834-
if (result.exitValue() != 0) {
1835-
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
1836-
}
1837-
String output = result.stdout().trim();
1838-
logger.info("output from restarting managed server:\n" + output);
1823+
+ "\",\"serverStartPolicy\":\"IF_NEEDED\"}]}}'";
1824+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
18391825

18401826
TestUtils.checkPodCreated(domainUid + "-" + msName, domainNS);
18411827
TestUtils.checkPodReady(domainUid + "-" + msName, domainNS);

integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,23 @@ public static void deletePvc(String pvcName, String namespace, String domainUid,
244244
}
245245

246246
public static ExecResult exec(String cmd) throws Exception {
247+
return exec(cmd, false);
248+
}
249+
250+
public static ExecResult exec(String cmd, boolean debug) throws Exception {
247251
ExecResult result = ExecCommand.exec(cmd);
248-
if (result.exitValue() != 0) {
252+
if (result.exitValue() != 0 || debug) {
249253
logger.info(
250-
"Command "
254+
"\nCommand "
251255
+ cmd
252-
+ " return value "
256+
+ "\nreturn value: "
253257
+ result.exitValue()
254-
+ " \n failed with stderr = "
258+
+ "\nstderr = "
255259
+ result.stderr()
256-
+ " \n stdout = "
260+
+ "\nstdout = "
257261
+ result.stdout());
262+
}
263+
if (result.exitValue() != 0) {
258264
throw new RuntimeException(
259265
"FAILURE: Command "
260266
+ cmd
@@ -263,6 +269,7 @@ public static ExecResult exec(String cmd) throws Exception {
263269
+ " \n stdout = "
264270
+ result.stdout());
265271
}
272+
266273
return result;
267274
}
268275

@@ -1415,16 +1422,16 @@ public static ExecResult loginAndPushImageToOcir(String image) throws Exception
14151422
return result;
14161423
}
14171424

1418-
public static void execAndPrintLog(String command) throws Exception {
1419-
ExecResult result = ExecCommand.exec(command);
1420-
logger.info(
1421-
"\nCommand "
1422-
+ command
1423-
+ "\nreturn value: "
1424-
+ result.exitValue()
1425-
+ "\nstderr = "
1426-
+ result.stderr()
1427-
+ "\nstdout = "
1428-
+ result.stdout());
1425+
public static ExecResult kubectlpatch(String domainUid, String domainNS, String patchStr)
1426+
throws Exception {
1427+
String cmd =
1428+
"kubectl patch domain "
1429+
+ domainUid
1430+
+ " -n "
1431+
+ domainNS
1432+
+ " -p "
1433+
+ patchStr
1434+
+ " --type merge";
1435+
return exec(cmd, true);
14291436
}
14301437
}

0 commit comments

Comments
 (0)