Skip to content

Commit 36da76c

Browse files
committed
adding test for precreateService attribute
1 parent 1f3ca45 commit 36da76c

File tree

4 files changed

+67
-77
lines changed

4 files changed

+67
-77
lines changed

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: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,22 @@ public void verifyPodsCreated() throws Exception {
138138
}
139139

140140
/**
141-
* verify services are created
142-
*
141+
*
143142
* @throws Exception
144143
*/
145144
public void verifyServicesCreated() throws Exception {
146-
// check admin service
145+
verifyServicesCreated(false);
146+
}
147+
148+
/**
149+
* verify services are created
150+
*
151+
* @param precreateService - if true check services are created for configuredManagedServerCount number of servers else
152+
* check for initialManagedServerReplicas number of servers
153+
* @throws Exception
154+
*/
155+
public void verifyServicesCreated(boolean precreateService) throws Exception {
156+
// check admin service
147157
logger.info("Checking if admin service(" + domainUid + "-" + adminServerName + ") is created");
148158
TestUtils.checkServiceCreated(domainUid + "-" + adminServerName, domainNS);
149159

@@ -159,7 +169,7 @@ public void verifyServicesCreated() throws Exception {
159169

160170
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
161171
// check managed server services
162-
for (int i = 1; i <= initialManagedServerReplicas; i++) {
172+
for (int i = 1; i <= (precreateService? configuredManagedServerCount: initialManagedServerReplicas); i++) {
163173
logger.info(
164174
"Checking if managed service("
165175
+ domainUid
@@ -598,9 +608,7 @@ public void destroy() throws Exception {
598608
public void shutdown() throws Exception {
599609
int replicas = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
600610
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);
611+
ExecResult result = TestUtils.exec(cmd.toString(), true);
604612
verifyDomainDeleted(replicas);
605613
}
606614

@@ -611,15 +619,8 @@ public void shutdown() throws Exception {
611619
*/
612620
public void shutdownUsingServerStartPolicy() throws Exception {
613621
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);
622+
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}' ";
623+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
623624
verifyServerPodsDeleted(replicas);
624625
}
625626

@@ -629,18 +630,23 @@ public void shutdownUsingServerStartPolicy() throws Exception {
629630
* @throws Exception
630631
*/
631632
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);
633+
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"IF_NEEDED\"}}'";
634+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
641635
verifyPodsCreated();
642636
verifyServersReady();
643637
}
638+
639+
/**
640+
* add precreateService true in domain.yaml
641+
*
642+
* @throws 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+
644650
/**
645651
* verify domain is deleted
646652
*
@@ -1791,23 +1797,11 @@ public int getLoadBalancerWebPort() {
17911797
* @throws Exception
17921798
*/
17931799
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\":\""
1800+
logger.info("About to shutdown managed server <" + msName + ">");
1801+
String patchStr = "'{\"spec\":{\"managedServers\":[{\"serverName\":\""
18001802
+ 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);
1803+
+ "\",\"serverStartPolicy\":\"NEVER\"}]}}' ";
1804+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
18111805

18121806
TestUtils.checkPodDeleted(domainUid + "-" + msName, domainNS);
18131807
}
@@ -1818,24 +1812,12 @@ public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Ex
18181812
* @throws Exception
18191813
*/
18201814
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\":\""
1815+
logger.info("About to restart managed server <" + msName + "> ");
1816+
String patchStr = "'{\"spec\":{\"managedServers\":[{\"serverName\":\""
18271817
+ 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);
1838-
1818+
+ "\",\"serverStartPolicy\":\"IF_NEEDED\"}]}}'";
1819+
TestUtils.kubectlpatch(domainUid, domainNS, patchStr);
1820+
18391821
TestUtils.checkPodCreated(domainUid + "-" + msName, domainNS);
18401822
TestUtils.checkPodReady(domainUid + "-" + msName, domainNS);
18411823
}

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

Lines changed: 22 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,15 @@ 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+
String cmd =
1415+
"kubectl patch domain "
1416+
+ domainUid
1417+
+ " -n "
1418+
+ domainNS
1419+
+ " -p "
1420+
+ patchStr
1421+
+ " --type merge";
1422+
return exec(cmd, true);
14171423
}
14181424
}

0 commit comments

Comments
 (0)