Skip to content

Commit d1a10e0

Browse files
committed
move ExecAndPrintLog to TestUtils
1 parent 9881fa0 commit d1a10e0

File tree

2 files changed

+21
-40
lines changed

2 files changed

+21
-40
lines changed

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

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.logging.Level;
1515
import oracle.kubernetes.operator.utils.Domain;
1616
import oracle.kubernetes.operator.utils.DomainCRD;
17-
import oracle.kubernetes.operator.utils.ExecCommand;
1817
import oracle.kubernetes.operator.utils.ExecResult;
1918
import oracle.kubernetes.operator.utils.K8sTestUtils;
2019
import oracle.kubernetes.operator.utils.Operator;
@@ -197,25 +196,7 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
197196
logTestBegin(testMethodName);
198197

199198
try {
200-
ExecAndPrintLog("docker images");
201-
String images1[] = {
202-
"aa168fda9148",
203-
"f4ebe13a774d",
204-
"1a0416dcad6b",
205-
"11311c769c45",
206-
"752895b7af34",
207-
"f284edce6956",
208-
"27ded50d518c",
209-
"6cdb96a19a82",
210-
"4d0e7bd02c03",
211-
"85dfdb97e0de",
212-
"d58f0d158db5",
213-
"d58f0d158db5"
214-
};
215-
for (String image : images1) {
216-
ExecAndPrintLog("docker rmi -f " + image);
217-
}
218-
ExecAndPrintLog("docker images");
199+
TestUtils.ExecAndPrintLog("docker images");
219200
logger.info(
220201
"About to verifyDomainServerPodRestart for Domain: "
221202
+ domain.getDomainUid()
@@ -231,20 +212,20 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
231212
String newImage =
232213
System.getenv("REPO_REGISTRY") + "/weblogick8s/middleware/weblogic:duplicate";
233214

215+
// tag image with repo name
234216
String tag =
235217
"docker tag " + getWeblogicImageName() + ":" + getWeblogicImageTag() + " " + newImage;
236-
// tag image with repo name
237-
ExecAndPrintLog(tag);
238-
ExecAndPrintLog("docker images");
218+
TestUtils.ExecAndPrintLog(tag);
219+
TestUtils.ExecAndPrintLog("docker images");
239220

240-
ExecAndPrintLog(
221+
TestUtils.ExecAndPrintLog(
241222
"docker login "
242223
+ System.getenv("REPO_REGISTRY")
243224
+ " -u "
244225
+ System.getenv("REPO_USERNAME")
245226
+ " -p "
246227
+ System.getenv("REPO_PASSWORD"));
247-
ExecAndPrintLog("docker push " + newImage);
228+
TestUtils.ExecAndPrintLog("docker push " + newImage);
248229

249230
// login and push image to ocir
250231
// TestUtils.loginAndPushImageToOCIR(newImage);
@@ -259,7 +240,7 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
259240
260241
// domain.getDomainNS());
261242

262-
ExecAndPrintLog(
243+
TestUtils.ExecAndPrintLog(
263244
"kubectl create secret docker-registry docker-store "
264245
+ "--docker-server="
265246
+ System.getenv("REPO_REGISTRY")
@@ -281,7 +262,7 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
281262
+ " -n "
282263
+ domain.getDomainNS()
283264
+ " --dry-run -o yaml | kubectl apply -f - ";
284-
ExecAndPrintLog(command);
265+
TestUtils.ExecAndPrintLog(command);
285266

286267
// apply new domain yaml and verify pod restart
287268
domain.verifyDomainServerPodRestart(
@@ -309,19 +290,6 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
309290
logger.info("SUCCESS - " + testMethodName);
310291
}
311292

312-
private void ExecAndPrintLog(String command) throws Exception {
313-
ExecResult result = ExecCommand.exec(command);
314-
logger.info(
315-
"\nCommand "
316-
+ command
317-
+ "\nreturn value: "
318-
+ result.exitValue()
319-
+ "\nstderr = "
320-
+ result.stderr()
321-
+ "\nstdout = "
322-
+ result.stdout());
323-
}
324-
325293
/**
326294
* Modify/Add the containerSecurityContext section at ServerPod Level using kubectl apply -f
327295
* cont.security.context.domain.yaml. Verify all the pods re-started. The property tested is:

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,4 +1402,17 @@ public static ExecResult loginAndPushImageToOCIR(String image) throws Exception
14021402
+ result.stderr());
14031403
return result;
14041404
}
1405+
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());
1417+
}
14051418
}

0 commit comments

Comments
 (0)