Skip to content

Commit d4fd8f0

Browse files
committed
adding file handler, state dump of pod logs at the end
1 parent 3bdaf76 commit d4fd8f0

File tree

4 files changed

+57
-38
lines changed

4 files changed

+57
-38
lines changed

integration-tests/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@
9191
<executable>${resource-integration-test}/setupenv.sh</executable>
9292
</configuration>
9393
</execution>
94+
<execution><!-- dump pod, domain, etc logs -->
95+
<id>statedump</id>
96+
<phase>post-integration-test</phase>
97+
<goals>
98+
<goal>exec</goal>
99+
</goals>
100+
<configuration>
101+
<executable>${resource-integration-test}/statedump.sh</executable>
102+
</configuration>
103+
</execution>
94104
</executions>
95105
</plugin>
96106
<plugin>

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

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.nio.file.Files;
88
import java.nio.file.Paths;
99
import java.util.Properties;
10+
import java.util.logging.FileHandler;
1011
import java.util.logging.Logger;
12+
import java.util.logging.SimpleFormatter;
1113
import oracle.kubernetes.operator.utils.ExecCommand;
1214
import oracle.kubernetes.operator.utils.ExecResult;
1315
import oracle.kubernetes.operator.utils.TestUtils;
@@ -21,7 +23,7 @@ public class BaseTest {
2123

2224
private static String resultRoot = "";
2325
private static String pvRoot = "";
24-
// private static String resultDir = "";
26+
private static String resultDir = "";
2527
private static String userProjectsDir = "";
2628
private static String projectRoot = "";
2729
private static String username = "weblogic";
@@ -61,8 +63,8 @@ public static void initialize(String appPropsFile) throws Exception {
6163
if (System.getenv("LEASE_ID") != null) {
6264
leaseId = System.getenv("LEASE_ID");
6365
}
64-
// resultDir = resultRoot + "/acceptance_test_tmp";
65-
userProjectsDir = resultRoot + "/acceptance_test_tmp/user-projects";
66+
resultDir = resultRoot + "/acceptance_test_tmp";
67+
userProjectsDir = resultDir + "/user-projects";
6668
projectRoot = System.getProperty("user.dir") + "/..";
6769

6870
// BRANCH_NAME var is used in Jenkins job
@@ -72,6 +74,44 @@ public static void initialize(String appPropsFile) throws Exception {
7274
branchName = TestUtils.getGitBranchName();
7375
}
7476

77+
// for manual/local run, do cleanup
78+
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
79+
80+
// delete k8s artifacts created if any, delete PV directories
81+
ExecResult clnResult = cleanup();
82+
if (clnResult.exitValue() != 0) {
83+
throw new RuntimeException(
84+
"FAILED: Command to call cleanup script failed " + clnResult.stderr());
85+
}
86+
logger.info(
87+
"Command to call cleanup script returned "
88+
+ clnResult.stdout()
89+
+ "\n"
90+
+ clnResult.stderr());
91+
}
92+
// create resultRoot, PVRoot, etc
93+
Files.createDirectories(Paths.get(resultRoot));
94+
Files.createDirectories(Paths.get(resultDir));
95+
Files.createDirectories(Paths.get(userProjectsDir));
96+
97+
// create file handler
98+
FileHandler fh = new FileHandler(resultDir + "/java_test_suite.out");
99+
SimpleFormatter formatter = new SimpleFormatter();
100+
fh.setFormatter(formatter);
101+
logger.addHandler(fh);
102+
logger.info("Adding file handler, logging to file at " + resultDir + "/java_test_suite.out");
103+
104+
// for manual/local run, create file handler, create PVROOT
105+
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
106+
logger.info("Creating PVROOT " + pvRoot);
107+
Files.createDirectories(Paths.get(pvRoot));
108+
ExecResult result = ExecCommand.exec("chmod 777 " + pvRoot);
109+
if (result.exitValue() != 0) {
110+
throw new RuntimeException(
111+
"FAILURE: Couldn't change permissions for PVROOT " + result.stderr());
112+
}
113+
}
114+
75115
logger.info("RESULT_ROOT =" + resultRoot);
76116
logger.info("PV_ROOT =" + pvRoot);
77117
logger.info("userProjectsDir =" + userProjectsDir);
@@ -90,23 +130,6 @@ public static void initialize(String appPropsFile) throws Exception {
90130
logger.info(
91131
"Env var IMAGE_PULL_SECRET_WEBLOGIC " + System.getenv("IMAGE_PULL_SECRET_WEBLOGIC"));
92132
logger.info("Env var BRANCH_NAME " + System.getenv("BRANCH_NAME"));
93-
94-
// create resultRoot, PVRoot, etc
95-
Files.createDirectories(Paths.get(resultRoot));
96-
97-
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
98-
logger.info("Creating PVROOT " + pvRoot);
99-
Files.createDirectories(Paths.get(pvRoot));
100-
ExecResult result = ExecCommand.exec("chmod 777 " + pvRoot);
101-
if (result.exitValue() != 0) {
102-
throw new RuntimeException(
103-
"FAILURE: Couldn't change permissions for PVROOT " + result.stderr());
104-
}
105-
}
106-
107-
// Files.createDirectories(Paths.get(resultDir));
108-
109-
Files.createDirectories(Paths.get(userProjectsDir));
110133
}
111134

112135
public static String getResultRoot() {

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

Lines changed: 2 additions & 14 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.ExecResult;
109
import oracle.kubernetes.operator.utils.Operator;
1110
import oracle.kubernetes.operator.utils.TestUtils;
1211
import org.junit.AfterClass;
@@ -49,22 +48,11 @@ public class ITFirstDomain extends BaseTest {
4948
*/
5049
@BeforeClass
5150
public static void staticPrepare() throws Exception {
52-
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
53-
logger.info("BEGIN");
54-
5551
// initialize test properties and create the directories
5652
initialize(appPropsFile);
5753

58-
// delete k8s artifacts created if any, delete PV directories
59-
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
60-
ExecResult result = cleanup();
61-
if (result.exitValue() != 0) {
62-
throw new RuntimeException(
63-
"FAILED: Command to call cleanup script failed " + result.stderr());
64-
}
65-
logger.info(
66-
"Command to call cleanup script returned " + result.stdout() + "\n" + result.stderr());
67-
}
54+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
55+
logger.info("BEGIN");
6856

6957
// renew lease at the begining for every test method, leaseId is set only for Wercker
7058
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ public static String getExternalOperatorCertificate(String operatorNS, String us
271271
throws Exception {
272272

273273
File certFile =
274-
new File(
275-
TestUtils.class.getClassLoader().getResource(".").getFile() + "/../operator.cert.pem");
274+
new File(userProjectsDir + "/weblogic-operators/" + operatorNS + "/../operator.cert.pem");
276275

277276
StringBuffer opCertCmd = new StringBuffer("grep externalOperatorCert ");
278277
opCertCmd
@@ -304,8 +303,7 @@ public static String getExternalOperatorCertificate(String operatorNS, String us
304303
public static String getExternalOperatorKey(String operatorNS, String userProjectsDir)
305304
throws Exception {
306305
File keyFile =
307-
new File(
308-
TestUtils.class.getClassLoader().getResource(".").getFile() + "/../operator.key.pem");
306+
new File(userProjectsDir + "/weblogic-operators/" + operatorNS + "/../operator.key.pem");
309307

310308
StringBuffer opKeyCmd = new StringBuffer("grep externalOperatorKey ");
311309
opKeyCmd

0 commit comments

Comments
 (0)