Skip to content

Commit f82861e

Browse files
change class ITOperatorLifecycle to ITPodsRestart and one test method --> one property
1 parent 969bf4d commit f82861e

File tree

4 files changed

+323
-35
lines changed

4 files changed

+323
-35
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,4 +520,29 @@ private void callWebAppAndVerifyScaling(Domain domain, int replicas) throws Exce
520520
TestUtils.checkServiceCreated(podName, domainNS);
521521
}
522522
}
523+
524+
public static void tearDown() throws Exception {
525+
StringBuffer cmd =
526+
new StringBuffer("export RESULT_ROOT=$RESULT_ROOT && export PV_ROOT=$PV_ROOT && ");
527+
cmd.append(BaseTest.getProjectRoot())
528+
.append("/integration-tests/src/test/resources/statedump.sh");
529+
logger.info("Running " + cmd);
530+
531+
ExecResult result = ExecCommand.exec(cmd.toString());
532+
if (result.exitValue() == 0) {
533+
logger.info("Executed statedump.sh " + result.stdout());
534+
} else {
535+
logger.info("Execution of statedump.sh failed, " + result.stderr() + "\n" + result.stdout());
536+
}
537+
538+
// if (JENKINS) {
539+
result = cleanup();
540+
logger.info("cleanup result =" + result.stdout() + "\n " + result.stderr());
541+
// }
542+
543+
if (getLeaseId() != "") {
544+
logger.info("Release the k8s cluster lease");
545+
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
546+
}
547+
}
523548
}
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator;
6+
7+
import java.util.Map;
8+
import oracle.kubernetes.operator.utils.Domain;
9+
import oracle.kubernetes.operator.utils.Operator;
10+
import oracle.kubernetes.operator.utils.TestUtils;
11+
import org.junit.AfterClass;
12+
import org.junit.Assert;
13+
import org.junit.Assume;
14+
import org.junit.BeforeClass;
15+
import org.junit.FixMethodOrder;
16+
import org.junit.Test;
17+
import org.junit.runners.MethodSorters;
18+
19+
/**
20+
* Simple JUnit test file used for testing Operator.
21+
*
22+
* <p>This test is used for testing pods being restarted by some properties change.
23+
*/
24+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
25+
public class ITPodsRestart extends BaseTest {
26+
27+
// property file used to customize operator properties for operator inputs yaml
28+
private static String operator1File = "operator1.yaml";
29+
30+
// file used to customize domain properties for domain, PV and LB inputs yaml
31+
private static Domain domain = null;
32+
private static String domainonpvwlstFile = "domainonpvwlst.yaml";
33+
34+
// property file used to configure constants for integration tests
35+
private static String appPropsFile = "OperatorIT.properties";
36+
37+
private static Operator operator1;
38+
39+
private static boolean QUICKTEST;
40+
private static boolean SMOKETEST;
41+
private static boolean JENKINS;
42+
private static boolean INGRESSPERDOMAIN = true;
43+
44+
// Set QUICKTEST env var to true to run a small subset of tests.
45+
// Set SMOKETEST env var to true to run an even smaller subset
46+
// of tests, plus leave domain1 up and running when the test completes.
47+
// set INGRESSPERDOMAIN to false to create LB's ingress by kubectl yaml file
48+
static {
49+
QUICKTEST =
50+
System.getenv("QUICKTEST") != null && System.getenv("QUICKTEST").equalsIgnoreCase("true");
51+
SMOKETEST =
52+
System.getenv("SMOKETEST") != null && System.getenv("SMOKETEST").equalsIgnoreCase("true");
53+
if (SMOKETEST) QUICKTEST = true;
54+
if (System.getenv("JENKINS") != null) {
55+
JENKINS = new Boolean(System.getenv("JENKINS")).booleanValue();
56+
}
57+
if (System.getenv("INGRESSPERDOMAIN") != null) {
58+
INGRESSPERDOMAIN = new Boolean(System.getenv("INGRESSPERDOMAIN")).booleanValue();
59+
}
60+
}
61+
62+
/**
63+
* This method gets called only once before any of the test methods are executed. It does the
64+
* initialization of the integration test properties defined in OperatorIT.properties and setting
65+
* the resultRoot, pvRoot and projectRoot attributes. Create Operator1 and domainOnPVUsingWLST
66+
* with admin server and 1 managed server if they are not running
67+
*
68+
* @throws Exception
69+
*/
70+
@BeforeClass
71+
public static void staticPrepare() throws Exception {
72+
// initialize test properties and create the directories
73+
if (!QUICKTEST) {
74+
initialize(appPropsFile);
75+
76+
logger.info("Checking if operator1 and domain are running, if not creating");
77+
if (operator1 == null) {
78+
operator1 = TestUtils.createOperator(operator1File);
79+
}
80+
81+
domain = createPodsRestartdomain();
82+
Assert.assertNotNull(domain);
83+
}
84+
}
85+
86+
/**
87+
* Releases k8s cluster lease, archives result, pv directories
88+
*
89+
* @throws Exception
90+
*/
91+
@AfterClass
92+
public static void staticUnPrepare() throws Exception {
93+
if (!QUICKTEST) {
94+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
95+
logger.info("BEGIN");
96+
logger.info("Run once, release cluster lease");
97+
98+
// destroyPodsRestartdomain();
99+
// tearDown();
100+
101+
if (!"".equals(getLeaseId())) {
102+
logger.info("Release the k8s cluster lease");
103+
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
104+
}
105+
106+
logger.info("SUCCESS");
107+
}
108+
}
109+
110+
/**
111+
* The properties tested is: env: "-Dweblogic.StdoutDebugEnabled=false"-->
112+
* "-Dweblogic.StdoutDebugEnabled=true"
113+
*
114+
* @throws Exception
115+
*/
116+
@Test
117+
public void testServerRestartByChangingEnvProperty() throws Exception {
118+
Assume.assumeFalse(QUICKTEST);
119+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
120+
logTestBegin(testMethodName);
121+
122+
boolean testCompletedSuccessfully = false;
123+
logger.info(
124+
"About to testDomainServerRestart for Domain: "
125+
+ domain.getDomainUid()
126+
+ " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true");
127+
domain.testDomainServerRestart(
128+
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
129+
130+
logger.info("SUCCESS - " + testMethodName);
131+
}
132+
133+
/**
134+
* The properties tested is: logHomeEnabled: true --> logHomeEnabled: false
135+
*
136+
* @throws Exception
137+
*/
138+
@Test
139+
public void testServerRestartByChangingLogHomeEnabled() throws Exception {
140+
Assume.assumeFalse(QUICKTEST);
141+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
142+
logTestBegin(testMethodName);
143+
144+
boolean testCompletedSuccessfully = false;
145+
146+
logger.info(
147+
"About to testDomainServerRestart for Domain: "
148+
+ domain.getDomainUid()
149+
+ " logHomeEnabled: true --> logHomeEnabled: false");
150+
domain.testDomainServerRestart("logHomeEnabled: true", "logHomeEnabled: false");
151+
152+
logger.info("SUCCESS - " + testMethodName);
153+
}
154+
155+
/**
156+
* The properties tested is: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never
157+
*
158+
* @throws Exception
159+
*/
160+
@Test
161+
public void testServerRestartByChangingImagePullPolicy() throws Exception {
162+
Assume.assumeFalse(QUICKTEST);
163+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
164+
logTestBegin(testMethodName);
165+
166+
boolean testCompletedSuccessfully = false;
167+
168+
logger.info(
169+
"About to testDomainServerRestart for Domain: "
170+
+ domain.getDomainUid()
171+
+ " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never ");
172+
domain.testDomainServerRestart(
173+
"imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" ");
174+
175+
logger.info("SUCCESS - " + testMethodName);
176+
}
177+
178+
/**
179+
* The properties tested is: includeServerOutInPodLog: true --> includeServerOutInPodLog: false
180+
*
181+
* @throws Exception
182+
*/
183+
@Test
184+
public void testServerRestartByChangingIncludeServerOutInPodLog() throws Exception {
185+
Assume.assumeFalse(QUICKTEST);
186+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
187+
logTestBegin(testMethodName);
188+
189+
boolean testCompletedSuccessfully = false;
190+
191+
logger.info(
192+
"About to testDomainServerRestart for Domain: "
193+
+ domain.getDomainUid()
194+
+ " includeServerOutInPodLog: true --> includeServerOutInPodLog: false");
195+
domain.testDomainServerRestart(
196+
"includeServerOutInPodLog: true", "includeServerOutInPodLog: false");
197+
198+
logger.info("SUCCESS - " + testMethodName);
199+
}
200+
201+
/**
202+
* The properties tested is: image: "store/oracle/weblogic:12.2.1.3" --> image:
203+
* "store/oracle/weblogic:duplicate"
204+
*
205+
* @throws Exception
206+
*/
207+
@Test
208+
public void testServerRestartByChangingImage() throws Exception {
209+
Assume.assumeFalse(QUICKTEST);
210+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
211+
logTestBegin(testMethodName);
212+
213+
boolean testCompletedSuccessfully = false;
214+
215+
logger.info(
216+
"About to testDomainServerRestart for Domain: "
217+
+ domain.getDomainUid()
218+
+ " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate");
219+
TestUtils.dockerTagImage("store/oracle/weblogic:12.2.1.3", "store/oracle/weblogic:duplicate");
220+
domain.testDomainServerRestart(
221+
"\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\"");
222+
TestUtils.dockerRemoveImage("store/oracle/weblogic:duplicate");
223+
224+
logger.info("SUCCESS - " + testMethodName);
225+
}
226+
227+
private static Domain createPodsRestartdomain() throws Exception {
228+
229+
Map<String, Object> domainMap = TestUtils.loadYaml(domainonpvwlstFile);
230+
domainMap.put("domainUID", "domainpodsrestart");
231+
domainMap.put("adminNodePort", new Integer("30707"));
232+
domainMap.put("t3ChannelPort", new Integer("30081"));
233+
domainMap.put("initialManagedServerReplicas", new Integer("1"));
234+
235+
logger.info("Creating Domain domain& verifing the domain creation");
236+
domain = TestUtils.createDomain(domainMap);
237+
domain.verifyDomainCreated();
238+
239+
return domain;
240+
}
241+
242+
private static void destroyPodsRestartdomain() throws Exception {
243+
if (domain != null) {
244+
domain.destroy();
245+
}
246+
}
247+
}

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,16 @@ private void createPV() throws Exception {
853853
public void testDomainServerRestart(String oldPropertyString, String newPropertyString)
854854
throws Exception {
855855
logger.info("Inside testDomainServerPodRestart");
856-
boolean result = false;
857-
result =
858-
TestUtils.findFileContainString(
859-
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml",
860-
newPropertyString);
861-
logger.info("The search result for " + newPropertyString + " is: " + result); // TODO
856+
String content =
857+
new String(
858+
Files.readAllBytes(
859+
Paths.get(
860+
BaseTest.getUserProjectsDir()
861+
+ "/weblogic-domains/"
862+
+ domainUid
863+
+ "/domain.yaml")));
864+
boolean result = content.indexOf(newPropertyString) >= 0;
865+
logger.info("The search result for " + newPropertyString + " is: " + result);
862866
if (!result) {
863867
TestUtils.createNewYamlFile(
864868
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml",
@@ -893,7 +897,11 @@ public void testDomainServerRestart(String oldPropertyString, String newProperty
893897

894898
// verify the servers in the domain are being restarted in a sequence
895899
verifyAdminServerRestarted();
896-
verifyManagedServerRestarted();
900+
verifyManagedServersRestarted();
901+
// let domain.yaml include the new changed property
902+
TestUtils.copyFile(
903+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml",
904+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml");
897905
}
898906
logger.info("Done - testDomainServerPodRestart");
899907
}
@@ -907,7 +915,7 @@ public void verifyAdminServerRestarted() throws Exception {
907915
Thread.sleep(10 * 1000);
908916
}
909917

910-
public void verifyManagedServerRestarted() throws Exception {
918+
public void verifyManagedServersRestarted() throws Exception {
911919
if (domainMap.get("serverStartPolicy") == null
912920
|| (domainMap.get("serverStartPolicy") != null
913921
&& !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) {

0 commit comments

Comments
 (0)