Skip to content

Commit 2aaa5aa

Browse files
authored
Merge pull request #923 from oracle/lifecycle-java-integ-test
PR: ready to be merged - Lifecycle java integ test
2 parents 920bfe7 + 4163770 commit 2aaa5aa

File tree

4 files changed

+395
-0
lines changed

4 files changed

+395
-0
lines changed

integration-tests/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ Basic Use Cases described above are verified in all the domain configurations. A
7777
| Two Operators using same External Https Port | create chart using same https rest port as already running first operator, verify that deployment fails with expected error |
7878
| Two Operators using same target domains namespace | create chart using target domains namespace as already running first operator, verify that deployment fails with expected error |
7979
| Operator Helm Chart using not preexisted target domains namespace | create chart using not preexisted target domains namespace as already running first operator, verify that deployment fails with expected error |
80+
81+
| Server Pods Restarted by modifying properties on the domain resource| Use Case |
82+
| --- | --- |
83+
| Server pods restarted by changing Env property | Verify admin and managed server pods being restarted by property change: "-Dweblogic.StdoutDebugEnabled=false" --> "-Dweblogic.StdoutDebugEnabled=true" |
84+
| Server pods restarted by changing image | Verify admin and managed server pods being restarted by property change: image: "store/oracle/weblogic:12.2.1.3" --> image: "store/oracle/weblogic:duplicate" |
85+
| Server pods restarted by changing imagePullPolicy | Verify admin and managed server pods being restarted by property change: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never |
86+
| Server pods restarted by changing includeServerOutInPodLog | Verify admin and managed server pods being restarted by property change: includeServerOutInPodLog: true --> includeServerOutInPodLog: false |
87+
| Server pods restarted by changing logHomeEnable | Verify admin and managed server pods being restarted by property change: logHomeEnabled: true --> logHomeEnabled: false |
8088

8189

8290

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
// Copyright 2019, 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+
private static Domain domain = null;
28+
private static Operator operator1;
29+
30+
/**
31+
* This method gets called only once before any of the test methods are executed. It does the
32+
* initialization of the integration test properties defined in OperatorIT.properties and setting
33+
* the resultRoot, pvRoot and projectRoot attributes. Create Operator1 and domainOnPVUsingWLST
34+
* with admin server and 1 managed server if they are not running
35+
*
36+
* @throws Exception
37+
*/
38+
@BeforeClass
39+
public static void staticPrepare() throws Exception {
40+
// initialize test properties and create the directories
41+
if (!QUICKTEST) {
42+
initialize(APP_PROPS_FILE);
43+
44+
logger.info("Checking if operator1 and domain are running, if not creating");
45+
if (operator1 == null) {
46+
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
47+
}
48+
49+
domain = createPodsRestartdomain();
50+
Assert.assertNotNull(domain);
51+
}
52+
}
53+
54+
/**
55+
* Releases k8s cluster lease, archives result, pv directories
56+
*
57+
* @throws Exception
58+
*/
59+
@AfterClass
60+
public static void staticUnPrepare() throws Exception {
61+
if (!QUICKTEST) {
62+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
63+
logger.info("BEGIN");
64+
logger.info("Run once, release cluster lease");
65+
66+
destroyPodsRestartdomain();
67+
tearDown();
68+
69+
logger.info("SUCCESS");
70+
}
71+
}
72+
73+
/**
74+
* Modify the domain scope env property on the domain resource using kubectl apply -f domain.yaml
75+
* Verify that all the server pods in the domain got re-started. The property tested is: env:
76+
* "-Dweblogic.StdoutDebugEnabled=false"--> "-Dweblogic.StdoutDebugEnabled=true"
77+
*
78+
* @throws Exception
79+
*/
80+
@Test
81+
public void testServerPodsRestartByChangingEnvProperty() throws Exception {
82+
Assume.assumeFalse(QUICKTEST);
83+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
84+
logTestBegin(testMethodName);
85+
86+
logger.info(
87+
"About to testDomainServerPodRestart for Domain: "
88+
+ domain.getDomainUid()
89+
+ " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true");
90+
domain.testDomainServerPodRestart(
91+
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
92+
93+
logger.info("SUCCESS - " + testMethodName);
94+
}
95+
96+
/**
97+
* Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml
98+
* Verify that all the server pods in the domain got re-started. The property tested is:
99+
* logHomeEnabled: true --> logHomeEnabled: false
100+
*
101+
* @throws Exception
102+
*/
103+
@Test
104+
public void testServerPodsRestartByChangingLogHomeEnabled() throws Exception {
105+
Assume.assumeFalse(QUICKTEST);
106+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
107+
logTestBegin(testMethodName);
108+
109+
logger.info(
110+
"About to testDomainServerPodRestart for Domain: "
111+
+ domain.getDomainUid()
112+
+ " logHomeEnabled: true --> logHomeEnabled: false");
113+
domain.testDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false");
114+
115+
logger.info("SUCCESS - " + testMethodName);
116+
}
117+
118+
/**
119+
* Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml
120+
* Verify that all the server pods in the domain got re-started. The property tested is:
121+
* imagePullPolicy: IfNotPresent --> imagePullPolicy: Never
122+
*
123+
* @throws Exception
124+
*/
125+
@Test
126+
public void testServerPodsRestartByChangingImagePullPolicy() throws Exception {
127+
Assume.assumeFalse(QUICKTEST);
128+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
129+
logTestBegin(testMethodName);
130+
131+
logger.info(
132+
"About to testDomainServerPodRestart for Domain: "
133+
+ domain.getDomainUid()
134+
+ " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never ");
135+
domain.testDomainServerPodRestart(
136+
"imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" ");
137+
138+
logger.info("SUCCESS - " + testMethodName);
139+
}
140+
141+
/**
142+
* Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml
143+
* Verify that all the server pods in the domain got re-started. The property tested is:
144+
* includeServerOutInPodLog: true --> includeServerOutInPodLog: false
145+
*
146+
* @throws Exception
147+
*/
148+
@Test
149+
public void testServerPodsRestartByChangingIncludeServerOutInPodLog() throws Exception {
150+
Assume.assumeFalse(QUICKTEST);
151+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
152+
logTestBegin(testMethodName);
153+
154+
logger.info(
155+
"About to testDomainServerPodRestart for Domain: "
156+
+ domain.getDomainUid()
157+
+ " includeServerOutInPodLog: true --> includeServerOutInPodLog: false");
158+
domain.testDomainServerPodRestart(
159+
"includeServerOutInPodLog: true", "includeServerOutInPodLog: false");
160+
161+
logger.info("SUCCESS - " + testMethodName);
162+
}
163+
164+
/**
165+
* Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml
166+
* Verify that all the server pods in the domain got re-started .The property tested is: image:
167+
* "store/oracle/weblogic:12.2.1.3" --> image: "store/oracle/weblogic:duplicate"
168+
*
169+
* @throws Exception
170+
*/
171+
@Test
172+
public void testServerPodsRestartByChangingZImage() throws Exception {
173+
Assume.assumeFalse(QUICKTEST);
174+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
175+
logTestBegin(testMethodName);
176+
177+
try {
178+
logger.info(
179+
"About to testDomainServerPodRestart for Domain: "
180+
+ domain.getDomainUid()
181+
+ " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate");
182+
183+
TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate");
184+
domain.testDomainServerPodRestart(
185+
"\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\"");
186+
} finally {
187+
TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate");
188+
}
189+
190+
logger.info("SUCCESS - " + testMethodName);
191+
}
192+
193+
private static Domain createPodsRestartdomain() throws Exception {
194+
195+
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
196+
domainMap.put("domainUID", "domainpodsrestart");
197+
domainMap.put("initialManagedServerReplicas", new Integer("1"));
198+
199+
logger.info("Creating Domain domain& verifing the domain creation");
200+
domain = TestUtils.createDomain(domainMap);
201+
domain.verifyDomainCreated();
202+
203+
return domain;
204+
}
205+
206+
private static void destroyPodsRestartdomain() throws Exception {
207+
if (domain != null) {
208+
domain.destroy();
209+
}
210+
}
211+
}

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,108 @@ private void createPV() throws Exception {
850850
new PersistentVolume("/scratch/acceptance_test_pv/persistentVolume-" + domainUid, pvMap);
851851
}
852852

853+
/**
854+
* verify domain server pods get restarted after a property change
855+
*
856+
* @param oldPropertyString
857+
* @param newPropertyString
858+
* @throws Exception
859+
*/
860+
public void testDomainServerPodRestart(String oldPropertyString, String newPropertyString)
861+
throws Exception {
862+
logger.info("Inside testDomainServerPodRestart");
863+
String content =
864+
new String(
865+
Files.readAllBytes(
866+
Paths.get(
867+
BaseTest.getUserProjectsDir()
868+
+ "/weblogic-domains/"
869+
+ domainUid
870+
+ "/domain.yaml")));
871+
boolean result = content.indexOf(newPropertyString) >= 0;
872+
logger.info("The search result for " + newPropertyString + " is: " + result);
873+
if (!result) {
874+
TestUtils.createNewYamlFile(
875+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml",
876+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml",
877+
oldPropertyString,
878+
newPropertyString);
879+
logger.info(
880+
"Done - generate new domain.yaml for "
881+
+ domainUid
882+
+ " oldProperty: "
883+
+ oldPropertyString
884+
+ " newProperty: "
885+
+ newPropertyString);
886+
887+
// kubectl apply the new generated domain yaml file with changed property
888+
StringBuffer command = new StringBuffer();
889+
command
890+
.append("kubectl apply -f ")
891+
.append(
892+
BaseTest.getUserProjectsDir()
893+
+ "/weblogic-domains/"
894+
+ domainUid
895+
+ "/domain_new.yaml");
896+
logger.info("kubectl execut with command: " + command.toString());
897+
TestUtils.exec(command.toString());
898+
899+
// verify the servers in the domain are being restarted in a sequence
900+
verifyAdminServerRestarted();
901+
verifyManagedServersRestarted();
902+
// make domain.yaml include the new changed property
903+
TestUtils.copyFile(
904+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml",
905+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml");
906+
}
907+
logger.info("Done - testDomainServerPodRestart");
908+
}
909+
910+
/**
911+
* verify that admin server pod gets restarted.
912+
*
913+
* @throws Exception
914+
*/
915+
public void verifyAdminServerRestarted() throws Exception {
916+
logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Terminating");
917+
TestUtils.checkPodTerminating(domainUid + "-" + adminServerName, domainNS);
918+
919+
logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Running");
920+
TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS);
921+
}
922+
923+
/**
924+
* verify that managed server pods get restarted.
925+
*
926+
* @throws Exception
927+
*/
928+
public void verifyManagedServersRestarted() throws Exception {
929+
if (domainMap.get("serverStartPolicy") == null
930+
|| (domainMap.get("serverStartPolicy") != null
931+
&& !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) {
932+
// check managed server pods
933+
for (int i = 1; i <= initialManagedServerReplicas; i++) {
934+
logger.info(
935+
"Checking if managed pod("
936+
+ domainUid
937+
+ "-"
938+
+ managedServerNameBase
939+
+ i
940+
+ ") is Terminating");
941+
TestUtils.checkPodTerminating(domainUid + "-" + managedServerNameBase + i, domainNS);
942+
943+
logger.info(
944+
"Checking if managed pod("
945+
+ domainUid
946+
+ "-"
947+
+ managedServerNameBase
948+
+ i
949+
+ ") is Running");
950+
TestUtils.checkPodCreated(domainUid + "-" + managedServerNameBase + i, domainNS);
951+
}
952+
}
953+
}
954+
853955
private void createSecret() throws Exception {
854956
Secret secret =
855957
new Secret(

0 commit comments

Comments
 (0)