Skip to content

Commit 0eded91

Browse files
committed
call TestUtils.exec()
1 parent 4288cd9 commit 0eded91

File tree

2 files changed

+33
-116
lines changed

2 files changed

+33
-116
lines changed

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

Lines changed: 20 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ public Domain(Map<String, Object> inputDomainMap) throws Exception {
9292
public void verifyDomainCreated() throws Exception {
9393
StringBuffer command = new StringBuffer();
9494
command.append("kubectl get domain ").append(domainUid).append(" -n ").append(domainNS);
95-
ExecResult result = ExecCommand.exec(command.toString());
96-
if (result.exitValue() != 0) {
97-
throw new RuntimeException(
98-
"FAILED: command to get domain " + command + " failed with " + result.stderr());
99-
}
95+
ExecResult result = TestUtils.exec(command.toString());
10096
if (!result.stdout().contains(domainUid))
10197
throw new RuntimeException("FAILURE: domain not found, exiting!");
10298

@@ -262,11 +258,7 @@ public void verifyAdminServerExternalService(String username, String password) t
262258
.append(password)
263259
.append(" -H X-Requested-By:Integration-Test --write-out %{http_code} -o /dev/null");
264260
logger.info("cmd for curl " + cmd);
265-
ExecResult result = ExecCommand.exec(cmd.toString());
266-
if (result.exitValue() != 0) {
267-
throw new RuntimeException(
268-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
269-
}
261+
ExecResult result = TestUtils.exec(cmd.toString());
270262
String output = result.stdout().trim();
271263
logger.info("output " + output);
272264
if (!output.equals("200")) {
@@ -372,11 +364,7 @@ public void deployWebAppViaREST(
372364
.append("/management/weblogic/latest/edit/appDeployments")
373365
.append(" --write-out %{http_code} -o /dev/null");
374366
logger.fine("Command to deploy webapp " + cmd);
375-
ExecResult result = ExecCommand.exec(cmd.toString());
376-
if (result.exitValue() != 0) {
377-
throw new RuntimeException(
378-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
379-
}
367+
ExecResult result = TestUtils.exec(cmd.toString());
380368
String output = result.stdout().trim();
381369
if (!output.contains("202")) {
382370
throw new RuntimeException("FAILURE: Webapp deployment failed with response code " + output);
@@ -506,16 +494,7 @@ public void create() throws Exception {
506494
.append(domainUid)
507495
.append("/domain.yaml");
508496
logger.info("Running " + cmd);
509-
ExecResult result = ExecCommand.exec(cmd.toString());
510-
if (result.exitValue() != 0) {
511-
throw new RuntimeException(
512-
"FAILURE: command "
513-
+ cmd
514-
+ " failed, returned "
515-
+ result.stdout()
516-
+ "\n"
517-
+ result.stderr());
518-
}
497+
ExecResult result = TestUtils.exec(cmd.toString());
519498
String outputStr = result.stdout().trim();
520499
logger.info("Command returned " + outputStr);
521500

@@ -534,11 +513,7 @@ public void destroy() throws Exception {
534513
.append("/weblogic-domains/")
535514
.append(domainUid)
536515
.append("/domain.yaml");
537-
ExecResult result = ExecCommand.exec(cmd.toString());
538-
if (result.exitValue() != 0) {
539-
throw new RuntimeException(
540-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
541-
}
516+
ExecResult result = TestUtils.exec(cmd.toString());
542517
String output = result.stdout().trim();
543518
logger.info("command to delete domain " + cmd + " \n returned " + output);
544519
verifyDomainDeleted(replicas);
@@ -552,11 +527,7 @@ public void destroy() throws Exception {
552527
public void shutdown() throws Exception {
553528
int replicas = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
554529
String cmd = "kubectl delete domain " + domainUid + " -n " + domainNS;
555-
ExecResult result = ExecCommand.exec(cmd);
556-
if (result.exitValue() != 0) {
557-
throw new RuntimeException(
558-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
559-
}
530+
ExecResult result = TestUtils.exec(cmd.toString());
560531
String output = result.stdout().trim();
561532
logger.info("command to delete domain " + cmd + " \n returned " + output);
562533
verifyDomainDeleted(replicas);
@@ -575,11 +546,7 @@ public void shutdownUsingServerStartPolicy() throws Exception {
575546
+ " -n "
576547
+ domainNS
577548
+ " -p '{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}' --type merge";
578-
ExecResult result = ExecCommand.exec(cmd);
579-
if (result.exitValue() != 0) {
580-
throw new RuntimeException(
581-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
582-
}
549+
ExecResult result = TestUtils.exec(cmd);
583550
String output = result.stdout().trim();
584551
logger.info("command to shutdown domain " + cmd + " \n returned " + output);
585552
verifyServerPodsDeleted(replicas);
@@ -597,11 +564,7 @@ public void restartUsingServerStartPolicy() throws Exception {
597564
+ " -n "
598565
+ domainNS
599566
+ " -p '{\"spec\":{\"serverStartPolicy\":\"IF_NEEDED\"}}' --type merge";
600-
ExecResult result = ExecCommand.exec(cmd);
601-
if (result.exitValue() != 0) {
602-
throw new RuntimeException(
603-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
604-
}
567+
ExecResult result = TestUtils.exec(cmd);
605568
String output = result.stdout().trim();
606569
logger.info("command to restart domain " + cmd + " \n returned " + output);
607570
verifyPodsCreated();
@@ -715,16 +678,7 @@ public void verifyAdminConsoleViaLB() throws Exception {
715678
.append(responseBodyFile);
716679
logger.info("cmd for curl " + cmd);
717680

718-
ExecResult result = ExecCommand.exec(cmd.toString());
719-
if (result.exitValue() != 0) {
720-
throw new RuntimeException(
721-
"FAILURE: command "
722-
+ cmd
723-
+ " failed, returned "
724-
+ result.stderr()
725-
+ "\n "
726-
+ result.stdout());
727-
}
681+
ExecResult result = TestUtils.exec(cmd.toString());
728682

729683
String output = result.stdout().trim();
730684
logger.info("output " + output);
@@ -785,11 +739,7 @@ public int getNumberOfServersInClusterServiceEndpoint(String clusterName) throws
785739
.append(domainNS)
786740
.append(" | grep Endpoints | awk '{print $2}'");
787741

788-
ExecResult result = ExecCommand.exec(cmd.toString());
789-
if (result.exitValue() != 0) {
790-
throw new RuntimeException(
791-
"FAILURE: Commmand " + cmd + " failed, cluster service is not ready.");
792-
}
742+
ExecResult result = TestUtils.exec(cmd.toString());
793743
logger.info("Cluster service Endpoint " + result.stdout());
794744
return new StringTokenizer(result.stdout(), ",").countTokens();
795745
}
@@ -806,12 +756,8 @@ private int getAdminSericeLBNodePort() throws Exception {
806756

807757
logger.info("Cmd to get the admins service node port " + cmd);
808758

809-
ExecResult result = ExecCommand.exec(cmd.toString());
810-
if (result.exitValue() == 0) {
811-
return new Integer(result.stdout().trim()).intValue();
812-
} else {
813-
throw new RuntimeException("Cmd failed " + result.stderr() + " \n " + result.stdout());
814-
}
759+
ExecResult result = TestUtils.exec(cmd.toString());
760+
return new Integer(result.stdout().trim()).intValue();
815761
}
816762

817763
/**
@@ -979,16 +925,7 @@ private void createSecret() throws Exception {
979925
String.format(
980926
"kubectl label secret %s weblogic.domainUID=%s -n %s",
981927
secret.getSecretName(), domainUid, domainNS);
982-
ExecResult result = ExecCommand.exec(labelCmd);
983-
if (result.exitValue() != 0) {
984-
throw new RuntimeException(
985-
"FAILURE: command to label secret \""
986-
+ labelCmd
987-
+ "\" failed, returned "
988-
+ result.stdout()
989-
+ "\n"
990-
+ result.stderr());
991-
}
928+
TestUtils.exec(labelCmd);
992929
}
993930

994931
/**
@@ -1161,11 +1098,7 @@ private void callShellScriptByExecToPod(
11611098

11621099
private void callWebAppAndWaitTillReady(String curlCmd) throws Exception {
11631100
for (int i = 0; i < maxIterations; i++) {
1164-
ExecResult result = ExecCommand.exec(curlCmd.toString());
1165-
if (result.exitValue() != 0) {
1166-
throw new RuntimeException(
1167-
"FAILURE: command " + curlCmd + " failed, returned " + result.stderr());
1168-
}
1101+
ExecResult result = TestUtils.exec(curlCmd);
11691102
String responseCode = result.stdout().trim();
11701103
if (!responseCode.equals("200")) {
11711104
logger.info(
@@ -1200,18 +1133,9 @@ private void callWebAppAndCheckForServerNameInResponse(
12001133
logger.info("Calling webapp 20 times " + curlCmd);
12011134
// number of times to call webapp
12021135
for (int i = 0; i < 20; i++) {
1203-
ExecResult result = ExecCommand.exec(curlCmd.toString());
1204-
if (result.exitValue() != 0) {
1205-
throw new RuntimeException(
1206-
"FAILURE: command "
1207-
+ curlCmd
1208-
+ " failed, returned "
1209-
+ result.stderr()
1210-
+ " \n "
1211-
+ result.stdout());
1212-
} else {
1213-
logger.info("webapp invoked successfully for curlCmd:" + curlCmd);
1214-
}
1136+
ExecResult result = TestUtils.exec(curlCmd);
1137+
1138+
logger.info("webapp invoked successfully for curlCmd:" + curlCmd);
12151139
if (verifyLoadBalancing) {
12161140
String response = result.stdout().trim();
12171141
// logger.info("response: " + response);
@@ -1356,11 +1280,7 @@ private String getNodeHost() throws Exception {
13561280
+ domainNS
13571281
+ " | grep Node:";
13581282

1359-
ExecResult result = ExecCommand.exec(cmd);
1360-
if (result.exitValue() != 0) {
1361-
throw new RuntimeException(
1362-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
1363-
}
1283+
ExecResult result = TestUtils.exec(cmd);
13641284
String nodePortHost = result.stdout();
13651285
// logger.info("nodePortHost "+nodePortHost);
13661286
if (nodePortHost.contains(":") && nodePortHost.contains("/")) {
@@ -1379,11 +1299,7 @@ private String getNodePort() throws Exception {
13791299
.append(" -n ")
13801300
.append(domainNS)
13811301
.append(" | grep \"Node Port:\"");
1382-
ExecResult result = ExecCommand.exec(cmd.toString());
1383-
if (result.exitValue() != 0) {
1384-
throw new RuntimeException(
1385-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
1386-
}
1302+
ExecResult result = TestUtils.exec(cmd.toString());
13871303
String output = result.stdout();
13881304
if (output.contains("Node Port")) {
13891305
return output.substring(output.indexOf(":") + 1).trim();
@@ -1421,16 +1337,7 @@ private void gitCloneDockerImagesSample() throws Exception {
14211337
.append(BaseTest.getResultDir())
14221338
.append("/docker-images");
14231339
logger.info("Executing cmd " + removeAndClone);
1424-
ExecResult result = ExecCommand.exec(removeAndClone.toString());
1425-
if (result.exitValue() != 0) {
1426-
throw new RuntimeException(
1427-
"FAILURE: command "
1428-
+ removeAndClone
1429-
+ " failed "
1430-
+ result.stderr()
1431-
+ " "
1432-
+ result.stdout());
1433-
}
1340+
ExecResult result = TestUtils.exec(removeAndClone.toString());
14341341
}
14351342
}
14361343

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,21 @@ public static void deletePVC(String pvcName, String namespace, String domainUid)
211211
public static ExecResult exec(String cmd) throws Exception {
212212
ExecResult result = ExecCommand.exec(cmd);
213213
if (result.exitValue() != 0) {
214-
logger.info("Command " + cmd + " failed with " + result.stderr() + " \n " + result.stdout());
214+
logger.info(
215+
"Command "
216+
+ cmd
217+
+ " failed with stderr = "
218+
+ result.stderr()
219+
+ " \n stdout = "
220+
+ result.stdout());
215221
throw new RuntimeException(
216-
"FAILURE: Command " + cmd + " failed with " + result.stderr() + " \n " + result.stdout());
222+
"FAILURE: Command "
223+
+ cmd
224+
+ " failed with stderr = "
225+
+ result.stderr()
226+
+ " \n stdout = "
227+
+ result.stdout());
217228
}
218-
logger.info("Command " + cmd + " returned " + result.stdout());
219229
return result;
220230
}
221231

0 commit comments

Comments
 (0)