Skip to content

Commit 43b8f99

Browse files
committed
lease k8s resources runnings after test completes
1 parent 7ebc4fe commit 43b8f99

File tree

4 files changed

+51
-41
lines changed

4 files changed

+51
-41
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ public static String getBranchName() {
153153
return branchName;
154154
}
155155

156+
public static ExecResult cleanup() throws Exception {
157+
String cmd =
158+
"export RESULT_ROOT="
159+
+ getResultRoot()
160+
+ " export PV_ROOT="
161+
+ getPvRoot()
162+
+ " && "
163+
+ getProjectRoot()
164+
+ "/src/integration-tests/bash/cleanup.sh";
165+
logger.info("Command to call cleanup script " + cmd);
166+
return ExecCommand.exec(cmd);
167+
}
168+
156169
protected void logTestBegin(String testName) throws Exception {
157170
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
158171
logger.info("BEGIN " + testName);

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.util.Properties;
88
import oracle.kubernetes.operator.utils.Domain;
9-
import oracle.kubernetes.operator.utils.ExecCommand;
109
import oracle.kubernetes.operator.utils.ExecResult;
1110
import oracle.kubernetes.operator.utils.Operator;
1211
import oracle.kubernetes.operator.utils.TestUtils;
@@ -55,6 +54,16 @@ public static void staticPrepare() throws Exception {
5554

5655
// initialize test properties and create the directories
5756
initialize(appPropsFile);
57+
58+
// delete k8s artifacts created if any, delete PV directories
59+
ExecResult result = cleanup();
60+
if (result.exitValue() != 0) {
61+
throw new RuntimeException(
62+
"FAILED: Command to call cleanup script failed " + result.stderr());
63+
}
64+
logger.info(
65+
"Command to call cleanup script returned " + result.stdout() + "\n" + result.stderr());
66+
5867
// renew lease at the begining for every test method, leaseId is set only for Wercker
5968
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
6069

@@ -85,32 +94,26 @@ public static void staticUnPrepare() throws Exception {
8594
System.getenv("QUICKTEST") != null && System.getenv("QUICKTEST").equalsIgnoreCase("true"));
8695
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
8796
logger.info("BEGIN");
88-
logger.info("Run once, shutdown/deleting operator, domain, pv, etc");
97+
// logger.info("Run once, shutdown/deleting operator, domain, pv, etc");
8998

9099
// shutdown operator, domain and cleanup all artifacts and pv dir
91-
try {
100+
/*try {
92101
if (domain != null) domain.destroy();
93102
if (operator != null) operator.destroy();
94103
} finally {
95-
logger.info("Release the k8s cluster lease");
96-
if (getLeaseId() != "") {
97-
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
98-
}
99104
100-
String cmd =
101-
"export RESULT_ROOT="
102-
+ getResultRoot()
103-
+ " export PV_ROOT="
104-
+ getPvRoot()
105-
+ " && "
106-
+ getProjectRoot()
107-
+ "/src/integration-tests/bash/cleanup.sh";
108-
ExecResult result = ExecCommand.exec(cmd);
105+
ExecResult result = cleanup();
109106
if (result.exitValue() != 0) {
110-
logger.info("FAILED: command to call cleanup script " + cmd + " failed " + result.stderr());
107+
logger.info("FAILED: Command to call cleanup script failed " + result.stderr());
111108
}
112-
logger.info("Command " + cmd + " returned " + result.stdout() + "\n" + result.stderr());
109+
logger.info("Command to call cleanup script returned " + result.stdout() + "\n" + result.stderr());
110+
} */
111+
112+
if (getLeaseId() != "") {
113+
logger.info("Release the k8s cluster lease");
114+
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
113115
}
116+
114117
logger.info("SUCCESS");
115118
}
116119

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import java.util.Properties;
88
import oracle.kubernetes.operator.utils.Domain;
9-
import oracle.kubernetes.operator.utils.ExecCommand;
10-
import oracle.kubernetes.operator.utils.ExecResult;
119
import oracle.kubernetes.operator.utils.Operator;
1210
import oracle.kubernetes.operator.utils.TestUtils;
1311
import org.junit.AfterClass;
@@ -85,30 +83,26 @@ public static void staticPrepare() throws Exception {
8583
public static void staticUnPrepare() throws Exception {
8684
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
8785
logger.info("BEGIN");
88-
logger.info("Run once, shutdown/deleting operator, domain, pv, etc");
86+
// logger.info("Run once, shutdown/deleting operator, domain, pv, etc");
87+
88+
if (getLeaseId() != "") {
89+
logger.info("Release the k8s cluster lease");
90+
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
91+
}
92+
8993
// shutdown operator, domain and cleanup all artifacts and pv dir
90-
try {
94+
/* try {
9195
if (domain != null) domain.destroy();
9296
if (operator != null) operator.destroy();
9397
} finally {
94-
logger.info("Release the k8s cluster lease");
95-
if (getLeaseId() != "") {
96-
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
97-
}
98-
String cmd =
99-
"export RESULT_ROOT="
100-
+ getResultRoot()
101-
+ " export PV_ROOT="
102-
+ getPvRoot()
103-
+ " && "
104-
+ getProjectRoot()
105-
+ "/src/integration-tests/bash/cleanup.sh";
106-
ExecResult result = ExecCommand.exec(cmd);
107-
if (result.exitValue() != 0) {
108-
logger.info("FAILED: command to call cleanup script " + cmd + " failed " + result.stderr());
109-
}
110-
logger.info("Command " + cmd + " returned " + result.stdout() + "\n" + result.stderr());
111-
}
98+
//delete k8s artifacts created if any, delete PV directories
99+
ExecResult result = cleanup();
100+
if (result.exitValue() != 0) {
101+
throw new RuntimeException("FAILED: Command to call cleanup script failed " + result.stderr());
102+
}
103+
logger.info("Command to call cleanup script returned " + result.stdout() + "\n" + result.stderr());
104+
105+
} */
112106
logger.info("SUCCESS");
113107
}
114108
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public static void renewK8sClusterLease(String projectRoot, String leaseId) thro
405405
+ "use 'lease.sh -s'. To disable this lease check, do not set"
406406
+ "the LEASE_ID environment variable.");
407407

408-
throw new RuntimeException("Could not renew lease on k8s cluster");
408+
throw new RuntimeException("Could not renew lease on k8s cluster " + execResult.stderr());
409409
} else {
410410
logger.info("Renewed lease for leaseId " + leaseId);
411411
}

0 commit comments

Comments
 (0)