Skip to content

Commit a2869d8

Browse files
authored
Merge pull request #1123 from oracle/owls75192
adding test for precreateService attribute
2 parents b5f58be + 229512f commit a2869d8

File tree

5 files changed

+75
-77
lines changed

5 files changed

+75
-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
@@ -502,7 +502,9 @@ public void testDomainInImageUsingWDT() throws Exception {
502502

503503
private Domain testAdvancedUseCasesForADomain(Operator operator, Domain domain) throws Exception {
504504
if (!SMOKETEST) {
505+
domain.enablePrecreateService();
505506
testClusterScaling(operator, domain);
507+
domain.verifyServicesCreated(true);
506508
testDomainLifecyle(operator, domain);
507509
testOperatorLifecycle(operator, domain);
508510
}

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

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

198198
try {
199-
TestUtils.ExecAndPrintLog("docker images");
199+
TestUtils.exec("docker images", true);
200200
logger.info(
201201
"About to verifyDomainServerPodRestart for Domain: "
202202
+ domain.getDomainUid()
@@ -213,8 +213,8 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
213213
// tag image with repo name
214214
String tag =
215215
"docker tag " + getWeblogicImageName() + ":" + getWeblogicImageTag() + " " + newImage;
216-
TestUtils.ExecAndPrintLog(tag);
217-
TestUtils.ExecAndPrintLog("docker images");
216+
TestUtils.exec(tag, true);
217+
TestUtils.exec("docker images", true);
218218

219219
// login and push image to ocir
220220
TestUtils.loginAndPushImageToOCIR(newImage);

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

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ public void verifyPodsCreated() throws Exception {
143143
* @throws Exception
144144
*/
145145
public void verifyServicesCreated() throws Exception {
146+
verifyServicesCreated(false);
147+
}
148+
149+
/**
150+
* verify services are created
151+
*
152+
* @param precreateService - if true check services are created for configuredManagedServerCount
153+
* number of servers else check for initialManagedServerReplicas number of servers
154+
* @throws Exception
155+
*/
156+
public void verifyServicesCreated(boolean precreateService) throws Exception {
146157
// check admin service
147158
logger.info("Checking if admin service(" + domainUid + "-" + adminServerName + ") is created");
148159
TestUtils.checkServiceCreated(domainUid + "-" + adminServerName, domainNS);
@@ -159,7 +170,9 @@ public void verifyServicesCreated() throws Exception {
159170

160171
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
161172
// check managed server services
162-
for (int i = 1; i <= initialManagedServerReplicas; i++) {
173+
for (int i = 1;
174+
i <= (precreateService ? configuredManagedServerCount : initialManagedServerReplicas);
175+
i++) {
163176
logger.info(
164177
"Checking if managed service("
165178
+ domainUid
@@ -598,9 +611,7 @@ public void destroy() throws Exception {
598611
public void shutdown() throws Exception {
599612
int replicas = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
600613
String cmd = "kubectl delete domain " + domainUid + " -n " + domainNS;
601-
ExecResult result = TestUtils.exec(cmd.toString());
602-
String output = result.stdout().trim();
603-
logger.info("command to delete domain " + cmd + " \n returned " + output);
614+
ExecResult result = TestUtils.exec(cmd.toString(), true);
604615
verifyDomainDeleted(replicas);
605616
}
606617

@@ -611,15 +622,8 @@ public void shutdown() throws Exception {
611622
*/
612623
public void shutdownUsingServerStartPolicy() throws Exception {
613624
int replicas = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
614-
String cmd =
615-
"kubectl patch domain "
616-
+ domainUid
617-
+ " -n "
618-
+ domainNS
619-
+ " -p '{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}' --type merge";
620-
ExecResult result = TestUtils.exec(cmd);
621-
String output = result.stdout().trim();
622-
logger.info("command to shutdown domain " + cmd + " \n returned " + output);
625+
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}' ";
626+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
623627
verifyServerPodsDeleted(replicas);
624628
}
625629

@@ -629,18 +633,23 @@ public void shutdownUsingServerStartPolicy() throws Exception {
629633
* @throws Exception
630634
*/
631635
public void restartUsingServerStartPolicy() throws Exception {
632-
String cmd =
633-
"kubectl patch domain "
634-
+ domainUid
635-
+ " -n "
636-
+ domainNS
637-
+ " -p '{\"spec\":{\"serverStartPolicy\":\"IF_NEEDED\"}}' --type merge";
638-
ExecResult result = TestUtils.exec(cmd);
639-
String output = result.stdout().trim();
640-
logger.info("command to restart domain " + cmd + " \n returned " + output);
636+
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"IF_NEEDED\"}}'";
637+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
641638
verifyPodsCreated();
642639
verifyServersReady();
643640
}
641+
642+
/**
643+
* add precreateService true in domain.yaml
644+
*
645+
* @throws Exception
646+
*/
647+
public void enablePrecreateService() throws Exception {
648+
String patchStr = "'{\"spec\":{\"serverService\":{\"precreateService\":true}}}'";
649+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
650+
verifyServicesCreated(true);
651+
}
652+
644653
/**
645654
* verify domain is deleted
646655
*
@@ -1791,23 +1800,12 @@ public int getLoadBalancerWebPort() {
17911800
* @throws Exception
17921801
*/
17931802
public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Exception {
1794-
String cmd =
1795-
"kubectl patch domain "
1796-
+ domainUid
1797-
+ " -n "
1798-
+ domainNS
1799-
+ " -p '{\"spec\":{\"managedServers\":[{\"serverName\":\""
1803+
logger.info("About to shutdown managed server <" + msName + ">");
1804+
String patchStr =
1805+
"'{\"spec\":{\"managedServers\":[{\"serverName\":\""
18001806
+ msName
1801-
+ "\",\"serverStartPolicy\":\"NEVER\"}]}}' --type merge";
1802-
1803-
logger.info("command to shutdown managed server <" + msName + "> is: " + cmd);
1804-
1805-
ExecResult result = ExecCommand.exec(cmd);
1806-
if (result.exitValue() != 0) {
1807-
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
1808-
}
1809-
String output = result.stdout().trim();
1810-
logger.info("output from shutting down managed server:\n" + output);
1807+
+ "\",\"serverStartPolicy\":\"NEVER\"}]}}' ";
1808+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
18111809

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

18391826
TestUtils.checkPodCreated(domainUid + "-" + msName, domainNS);
18401827
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
@@ -233,17 +233,23 @@ public static void deletePVC(String pvcName, String namespace, String domainUid,
233233
}
234234

235235
public static ExecResult exec(String cmd) throws Exception {
236+
return exec(cmd, false);
237+
}
238+
239+
public static ExecResult exec(String cmd, boolean debug) throws Exception {
236240
ExecResult result = ExecCommand.exec(cmd);
237-
if (result.exitValue() != 0) {
241+
if (result.exitValue() != 0 || debug) {
238242
logger.info(
239-
"Command "
243+
"\nCommand "
240244
+ cmd
241-
+ " return value "
245+
+ "\nreturn value: "
242246
+ result.exitValue()
243-
+ " \n failed with stderr = "
247+
+ "\nstderr = "
244248
+ result.stderr()
245-
+ " \n stdout = "
249+
+ "\nstdout = "
246250
+ result.stdout());
251+
}
252+
if (result.exitValue() != 0) {
247253
throw new RuntimeException(
248254
"FAILURE: Command "
249255
+ cmd
@@ -252,6 +258,7 @@ public static ExecResult exec(String cmd) throws Exception {
252258
+ " \n stdout = "
253259
+ result.stdout());
254260
}
261+
255262
return result;
256263
}
257264

@@ -1403,16 +1410,16 @@ public static ExecResult loginAndPushImageToOCIR(String image) throws Exception
14031410
return result;
14041411
}
14051412

1406-
public static void ExecAndPrintLog(String command) throws Exception {
1407-
ExecResult result = ExecCommand.exec(command);
1408-
logger.info(
1409-
"\nCommand "
1410-
+ command
1411-
+ "\nreturn value: "
1412-
+ result.exitValue()
1413-
+ "\nstderr = "
1414-
+ result.stderr()
1415-
+ "\nstdout = "
1416-
+ result.stdout());
1413+
public static ExecResult kubectlpatch(String domainUid, String domainNS, String patchStr)
1414+
throws Exception {
1415+
String cmd =
1416+
"kubectl patch domain "
1417+
+ domainUid
1418+
+ " -n "
1419+
+ domainNS
1420+
+ " -p "
1421+
+ patchStr
1422+
+ " --type merge";
1423+
return exec(cmd, true);
14171424
}
14181425
}

0 commit comments

Comments
 (0)