Skip to content

Commit 329de94

Browse files
authored
Merge pull request #978 from oracle/podrestart-java-integ-test
PR: server scope podrestart-java-integ-test
2 parents 04b4b42 + 56bfa47 commit 329de94

File tree

6 files changed

+313
-16
lines changed

6 files changed

+313
-16
lines changed

integration-tests/USECASES.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Basic Use Cases described above are verified in all the domain configurations. A
7373
| Server pods restarted by changing imagePullPolicy | Verify admin and managed server pods being restarted by property change: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never |
7474
| Server pods restarted by changing includeServerOutInPodLog | Verify admin and managed server pods being restarted by property change: includeServerOutInPodLog: true --> includeServerOutInPodLog: false |
7575
| Server pods restarted by changing logHomeEnable | Verify admin and managed server pods being restarted by property change: logHomeEnabled: true --> logHomeEnabled: false |
76+
| Server pods restarted by changing containerSecurityContext | Verify admin and managed server pods being restarted by adding property change: containerSecurityContext: runAsUser: 1000 fsGroup: 2000 |
77+
| Server pods restarted by changing podSecurityContex | Verify admin and managed server pods being restarted by adding property change: podSecurityContext: runAsUser: 1000 fsGroup: 2000 |
78+
| Server pods restarted by changing resources | Verify admin and managed server pods being restarted by adding property change: resources: limits: cpu: "1" requests: cpu: "0.5" args: - -cpus - "2" |
7679

7780
Configuration Overrides Usecases
7881

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

Lines changed: 128 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package oracle.kubernetes.operator;
66

7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
79
import java.util.Map;
810
import oracle.kubernetes.operator.utils.Domain;
911
import oracle.kubernetes.operator.utils.Operator;
@@ -26,6 +28,7 @@ public class ITPodsRestart extends BaseTest {
2628

2729
private static Domain domain = null;
2830
private static Operator operator1;
31+
private static String domainUid = "";
2932

3033
/**
3134
* This method gets called only once before any of the test methods are executed. It does the
@@ -84,10 +87,10 @@ public void testServerPodsRestartByChangingEnvProperty() throws Exception {
8487
logTestBegin(testMethodName);
8588

8689
logger.info(
87-
"About to testDomainServerPodRestart for Domain: "
90+
"About to verifyDomainServerPodRestart for Domain: "
8891
+ domain.getDomainUid()
8992
+ " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true");
90-
domain.testDomainServerPodRestart(
93+
domain.verifyDomainServerPodRestart(
9194
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
9295

9396
logger.info("SUCCESS - " + testMethodName);
@@ -107,10 +110,10 @@ public void testServerPodsRestartByChangingLogHomeEnabled() throws Exception {
107110
logTestBegin(testMethodName);
108111

109112
logger.info(
110-
"About to testDomainServerPodRestart for Domain: "
113+
"About to verifyDomainServerPodRestart for Domain: "
111114
+ domain.getDomainUid()
112115
+ " logHomeEnabled: true --> logHomeEnabled: false");
113-
domain.testDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false");
116+
domain.verifyDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false");
114117

115118
logger.info("SUCCESS - " + testMethodName);
116119
}
@@ -129,10 +132,10 @@ public void testServerPodsRestartByChangingImagePullPolicy() throws Exception {
129132
logTestBegin(testMethodName);
130133

131134
logger.info(
132-
"About to testDomainServerPodRestart for Domain: "
135+
"About to verifyDomainServerPodRestart for Domain: "
133136
+ domain.getDomainUid()
134137
+ " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never ");
135-
domain.testDomainServerPodRestart(
138+
domain.verifyDomainServerPodRestart(
136139
"imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" ");
137140

138141
logger.info("SUCCESS - " + testMethodName);
@@ -152,10 +155,10 @@ public void testServerPodsRestartByChangingIncludeServerOutInPodLog() throws Exc
152155
logTestBegin(testMethodName);
153156

154157
logger.info(
155-
"About to testDomainServerPodRestart for Domain: "
158+
"About to verifyDomainServerPodRestart for Domain: "
156159
+ domain.getDomainUid()
157160
+ " includeServerOutInPodLog: true --> includeServerOutInPodLog: false");
158-
domain.testDomainServerPodRestart(
161+
domain.verifyDomainServerPodRestart(
159162
"includeServerOutInPodLog: true", "includeServerOutInPodLog: false");
160163

161164
logger.info("SUCCESS - " + testMethodName);
@@ -176,12 +179,12 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
176179

177180
try {
178181
logger.info(
179-
"About to testDomainServerPodRestart for Domain: "
182+
"About to verifyDomainServerPodRestart for Domain: "
180183
+ domain.getDomainUid()
181184
+ " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate");
182185

183186
TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate");
184-
domain.testDomainServerPodRestart(
187+
domain.verifyDomainServerPodRestart(
185188
"\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\"");
186189
} finally {
187190
TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate");
@@ -190,13 +193,127 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
190193
logger.info("SUCCESS - " + testMethodName);
191194
}
192195

196+
/**
197+
* Modify/Add the containerSecurityContext section at ServerPod Level using kubectl apply -f
198+
* cont.security.context.domain.yaml. Verify all the pods re-started. The property tested is:
199+
* serverPod: containerSecurityContext: runAsUser: 1000 fsGroup: 1000.
200+
*
201+
* @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers
202+
* are not restarted or after restart the server yaml file doesn't include the new added
203+
* property
204+
*/
205+
@Test
206+
public void testServerPodsRestartByChangingContSecurityContext() throws Exception {
207+
Assume.assumeFalse(QUICKTEST);
208+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
209+
logTestBegin(testMethodName);
210+
211+
// firstly ensure that original domain.yaml doesn't include the property-to-be-added
212+
String domainFileName =
213+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
214+
boolean result =
215+
(new String(Files.readAllBytes(Paths.get(domainFileName)))).contains("fsGroup: 1000");
216+
Assert.assertFalse(result);
217+
218+
// domainYaml: the yaml file name with changed property under resources dir
219+
String domainYaml = "cont.security.context.domain.yaml";
220+
logger.info(
221+
"About to verifyDomainServerPodRestart for Domain: "
222+
+ domain.getDomainUid()
223+
+ " change container securityContext:\n"
224+
+ " runAsUser: 1000\n"
225+
+ " fsGroup: 1000 ");
226+
domain.verifyDomainServerPodRestart(domainYaml);
227+
domain.findServerPropertyChange("securityContext", "admin-server");
228+
domain.findServerPropertyChange("securityContext", "managed-server1");
229+
230+
logger.info("SUCCESS - " + testMethodName);
231+
}
232+
233+
/**
234+
* Modify/Add the podSecurityContext section at ServerPod level using kubectl apply -f
235+
* pod.security.context.domain.yaml. Verify all the pods re-started. The property tested is:
236+
* podSecurityContext: runAsUser: 1000 fsGroup: 2000.
237+
*
238+
* @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers
239+
* are not restarted or after restart the server yaml file doesn't include the new added
240+
* property
241+
*/
242+
@Test
243+
public void testServerPodsRestartByChangingPodSecurityContext() throws Exception {
244+
Assume.assumeFalse(QUICKTEST);
245+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
246+
logTestBegin(testMethodName);
247+
248+
// firstly ensure that original domain.yaml doesn't include the property-to-be-added
249+
String domainFileName =
250+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
251+
boolean result =
252+
(new String(Files.readAllBytes(Paths.get(domainFileName)))).contains("fsGroup: 2000");
253+
Assert.assertFalse(result);
254+
255+
// domainYaml: the yaml file name with changed property under resources dir
256+
String domainYaml = "pod.security.context.domain.yaml";
257+
258+
logger.info(
259+
"About to verifyDomainServerPodRestart for Domain: "
260+
+ domain.getDomainUid()
261+
+ " change securityContext:\n"
262+
+ " runAsUser: 1000\n"
263+
+ " fsGroup: 2000 ");
264+
domain.verifyDomainServerPodRestart(domainYaml);
265+
domain.findServerPropertyChange("fsGroup: 2000", "admin-server");
266+
domain.findServerPropertyChange("fsGroup: 2000", "managed-server1");
267+
268+
logger.info("SUCCESS - " + testMethodName);
269+
}
270+
271+
/**
272+
* Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml. Verify all pods
273+
* re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: -
274+
* -cpus - "2".
275+
*
276+
* @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers
277+
* are not restarted or after restart the server yaml file doesn't include the new added
278+
* property
279+
*/
280+
@Test
281+
public void testServerPodsRestartByChangingResource() throws Exception {
282+
Assume.assumeFalse(QUICKTEST);
283+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
284+
logTestBegin(testMethodName);
285+
286+
// firstly ensure that original domain.yaml doesn't include the property-to-be-addeded
287+
String domainFileName =
288+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
289+
boolean result =
290+
(new String(Files.readAllBytes(Paths.get(domainFileName)))).contains("cpu: 500m");
291+
Assert.assertFalse(result);
292+
293+
// domainYaml: the yaml file name with changed property under resources dir
294+
String domainYaml = "resource.domain.yaml";
295+
296+
logger.info(
297+
"About to verifyDomainServerPodRestart for Domain: "
298+
+ domain.getDomainUid()
299+
+ " change resource:\n"
300+
+ " cpu: 500m");
301+
domain.verifyDomainServerPodRestart(domainYaml);
302+
domain.findServerPropertyChange("cpu: 500m", "admin-server");
303+
domain.findServerPropertyChange("cpu: 500m", "managed-server1");
304+
305+
logger.info("SUCCESS - " + testMethodName);
306+
}
307+
193308
private static Domain createPodsRestartdomain() throws Exception {
194309

195310
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
196311
domainMap.put("domainUID", "domainpodsrestart");
197312
domainMap.put("initialManagedServerReplicas", new Integer("1"));
198313

199-
logger.info("Creating Domain domain& verifing the domain creation");
314+
domainUid = (String) domainMap.get("domainUID");
315+
logger.info("Creating and verifying the domain creation with domainUid: " + domainUid);
316+
200317
domain = TestUtils.createDomain(domainMap);
201318
domain.verifyDomainCreated();
202319

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

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ private void createPV() throws Exception {
815815
}
816816

817817
/**
818-
* verify domain server pods get restarted after a property change
818+
* Verify domain server pods get restarted after a property change.
819819
*
820-
* @param oldPropertyString
821-
* @param newPropertyString
822-
* @throws Exception
820+
* @param oldPropertyString - the old property value
821+
* @param newPropertyString - the new property value
822+
* @throws Exception - IOException or errors occurred if the tested server is not restarted
823823
*/
824-
public void testDomainServerPodRestart(String oldPropertyString, String newPropertyString)
824+
public void verifyDomainServerPodRestart(String oldPropertyString, String newPropertyString)
825825
throws Exception {
826826
logger.info("Inside testDomainServerPodRestart");
827827
String content =
@@ -871,6 +871,91 @@ public void testDomainServerPodRestart(String oldPropertyString, String newPrope
871871
logger.info("Done - testDomainServerPodRestart");
872872
}
873873

874+
/**
875+
* Get runtime server yaml file and verify the changed property is in that file.
876+
*
877+
* @param changedProperty - the changed/added property
878+
* @param serverName - server name that is being tested
879+
* @throws Exception - test FAILURE Exception if the changed property is not found in the server
880+
* yaml file
881+
*/
882+
public void findServerPropertyChange(String changedProperty, String serverName) throws Exception {
883+
logger.info("Inside findServerPropertyChange");
884+
// get runtime server pod yaml file
885+
String outDir = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/";
886+
StringBuffer command = new StringBuffer();
887+
command
888+
.append("kubectl get po/")
889+
.append(
890+
domainUid
891+
+ "-"
892+
+ serverName
893+
+ " -o yaml -n "
894+
+ domainNS
895+
+ "|"
896+
+ "grep "
897+
+ "\""
898+
+ changedProperty
899+
+ "\"");
900+
logger.info("kubectl execut with command: " + command.toString());
901+
TestUtils.exec(command.toString());
902+
903+
String result = ((TestUtils.exec(command.toString())).stdout());
904+
logger.info(
905+
"in the method findServerPropertyChange, " + command.toString() + " return " + result);
906+
if (!result.contains(changedProperty)) {
907+
throw new Exception(
908+
"FAILURE: didn't find the property: " + changedProperty + " for the server" + serverName);
909+
}
910+
911+
logger.info("Done - findServerPropertyChange");
912+
}
913+
914+
/**
915+
* Verify domain server pods get restarted after the property change by kubectl apply -f new
916+
* domain yaml file with added/changed property.
917+
*
918+
* @param fileNameWithChangedProperty - the fragment of domain yaml file with new added property
919+
* change
920+
* @throws Exception - IOException or errors occurred if the tested server is not restarted
921+
*/
922+
public void verifyDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception {
923+
logger.info("Inside testDomainServerPodRestart domainYamlWithChangedProperty");
924+
925+
String newDomainYamlFile =
926+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml";
927+
String domainYamlFile =
928+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
929+
String fileWithChangedProperty =
930+
BaseTest.getProjectRoot()
931+
+ "/integration-tests/src/test/resources/"
932+
+ fileNameWithChangedProperty;
933+
934+
// copy the original domain.yaml to domain_new.yaml
935+
TestUtils.copyFile(domainYamlFile, newDomainYamlFile);
936+
937+
// append the file with changed property to the end of domain_new.yaml
938+
Files.write(
939+
Paths.get(newDomainYamlFile),
940+
Files.readAllBytes(Paths.get(fileWithChangedProperty)),
941+
StandardOpenOption.APPEND);
942+
943+
// kubectl apply the new constructed domain_new.yaml
944+
StringBuffer command = new StringBuffer();
945+
command.append("kubectl apply -f ").append(newDomainYamlFile);
946+
logger.info("kubectl execut with command: " + command.toString());
947+
TestUtils.exec(command.toString());
948+
949+
// verify the servers in the domain are being restarted in a sequence
950+
verifyAdminServerRestarted();
951+
verifyManagedServersRestarted();
952+
953+
// make domain.yaml include the new changed property
954+
TestUtils.copyFile(newDomainYamlFile, domainYamlFile);
955+
956+
logger.info("Done - testDomainServerPodRestart with domainYamlWithChangedProperty");
957+
}
958+
874959
/**
875960
* verify that admin server pod gets restarted.
876961
*
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Add podSecurityContext section at ServerPod Level
2+
# Make sure all pod(s) re-started
3+
#serverPod:
4+
# containerSecurityContext:
5+
# runAsUser: 1000
6+
# fsGroup: 1000
7+
# The generated server pods should look like:
8+
#spec:
9+
# containers:
10+
# - name: weblogic.server
11+
# securityContext:
12+
13+
serverPod:
14+
containerSecurityContext:
15+
runAsUser: 1000
16+
fsGroup: 1000
17+
env:
18+
- name: JAVA_OPTIONS
19+
value: "-Dweblogic.StdoutDebugEnabled=false"
20+
- name: USER_MEM_ARGS
21+
value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m "
22+
volumes:
23+
- name: weblogic-domain-storage-volume
24+
persistentVolumeClaim:
25+
claimName: domainpodsrestart-weblogic-sample-pvc
26+
volumeMounts:
27+
- mountPath: /shared
28+
name: weblogic-domain-storage-volume
29+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Add podSecurityContext section at ServerPod Level
2+
# Make sure all pod(s) re-started
3+
#serverPod:
4+
# podSecurityContext:
5+
# runAsUser: 1000
6+
# fsGroup: 2000
7+
# The generated server pods should look like:
8+
#spec:
9+
# securityContext:
10+
# runAsUser: 1000
11+
# fsGroup: 2000
12+
13+
serverPod:
14+
podSecurityContext:
15+
runAsUser: 1000
16+
fsGroup: 2000
17+
env:
18+
- name: JAVA_OPTIONS
19+
value: "-Dweblogic.StdoutDebugEnabled=false"
20+
- name: USER_MEM_ARGS
21+
value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m "
22+
volumes:
23+
- name: weblogic-domain-storage-volume
24+
persistentVolumeClaim:
25+
claimName: domainpodsrestart-weblogic-sample-pvc
26+
volumeMounts:
27+
- mountPath: /shared
28+
name: weblogic-domain-storage-volume
29+

0 commit comments

Comments
 (0)