Skip to content

Commit a024453

Browse files
committed
merge
1 parent 52edb58 commit a024453

File tree

1 file changed

+105
-132
lines changed

1 file changed

+105
-132
lines changed

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

Lines changed: 105 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
4-
package oracle.kubernetes.operator;
54

6-
import static oracle.kubernetes.operator.BaseTest.logger;
5+
package oracle.kubernetes.operator;
76

8-
import java.nio.charset.Charset;
9-
import java.nio.charset.StandardCharsets;
107
import java.nio.file.Files;
11-
import java.nio.file.Path;
128
import java.nio.file.Paths;
139
import java.util.Map;
1410
import oracle.kubernetes.operator.utils.Domain;
15-
import oracle.kubernetes.operator.utils.DomainCRD;
16-
import oracle.kubernetes.operator.utils.ExecResult;
1711
import oracle.kubernetes.operator.utils.Operator;
1812
import oracle.kubernetes.operator.utils.TestUtils;
1913
import org.junit.AfterClass;
@@ -34,8 +28,7 @@ public class ITPodsRestart extends BaseTest {
3428

3529
private static Domain domain = null;
3630
private static Operator operator1;
37-
private static String KUBE_EXEC_CMD;
38-
private static String restartTmpDir = "";
31+
private static String domainUid = "";
3932

4033
/**
4134
* This method gets called only once before any of the test methods are executed. It does the
@@ -55,8 +48,6 @@ public static void staticPrepare() throws Exception {
5548
if (operator1 == null) {
5649
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
5750
}
58-
restartTmpDir = BaseTest.getResultDir() + "/restarttemp";
59-
Files.createDirectories(Paths.get(restartTmpDir));
6051

6152
domain = createPodsRestartdomain();
6253
Assert.assertNotNull(domain);
@@ -76,7 +67,7 @@ public static void staticUnPrepare() throws Exception {
7667
logger.info("Run once, release cluster lease");
7768

7869
destroyPodsRestartdomain();
79-
tearDown();
70+
tearDown(new Object() {}.getClass().getEnclosingClass().getSimpleName());
8071

8172
logger.info("SUCCESS");
8273
}
@@ -96,10 +87,10 @@ public void testServerPodsRestartByChangingEnvProperty() throws Exception {
9687
logTestBegin(testMethodName);
9788

9889
logger.info(
99-
"About to testDomainServerPodRestart for Domain: "
90+
"About to verifyDomainServerPodRestart for Domain: "
10091
+ domain.getDomainUid()
10192
+ " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true");
102-
domain.testDomainServerPodRestart(
93+
domain.verifyDomainServerPodRestart(
10394
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
10495

10596
logger.info("SUCCESS - " + testMethodName);
@@ -119,10 +110,10 @@ public void testServerPodsRestartByChangingLogHomeEnabled() throws Exception {
119110
logTestBegin(testMethodName);
120111

121112
logger.info(
122-
"About to testDomainServerPodRestart for Domain: "
113+
"About to verifyDomainServerPodRestart for Domain: "
123114
+ domain.getDomainUid()
124115
+ " logHomeEnabled: true --> logHomeEnabled: false");
125-
domain.testDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false");
116+
domain.verifyDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false");
126117

127118
logger.info("SUCCESS - " + testMethodName);
128119
}
@@ -141,10 +132,10 @@ public void testServerPodsRestartByChangingImagePullPolicy() throws Exception {
141132
logTestBegin(testMethodName);
142133

143134
logger.info(
144-
"About to testDomainServerPodRestart for Domain: "
135+
"About to verifyDomainServerPodRestart for Domain: "
145136
+ domain.getDomainUid()
146137
+ " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never ");
147-
domain.testDomainServerPodRestart(
138+
domain.verifyDomainServerPodRestart(
148139
"imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" ");
149140

150141
logger.info("SUCCESS - " + testMethodName);
@@ -164,10 +155,10 @@ public void testServerPodsRestartByChangingIncludeServerOutInPodLog() throws Exc
164155
logTestBegin(testMethodName);
165156

166157
logger.info(
167-
"About to testDomainServerPodRestart for Domain: "
158+
"About to verifyDomainServerPodRestart for Domain: "
168159
+ domain.getDomainUid()
169160
+ " includeServerOutInPodLog: true --> includeServerOutInPodLog: false");
170-
domain.testDomainServerPodRestart(
161+
domain.verifyDomainServerPodRestart(
171162
"includeServerOutInPodLog: true", "includeServerOutInPodLog: false");
172163

173164
logger.info("SUCCESS - " + testMethodName);
@@ -188,12 +179,12 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
188179

189180
try {
190181
logger.info(
191-
"About to testDomainServerPodRestart for Domain: "
182+
"About to verifyDomainServerPodRestart for Domain: "
192183
+ domain.getDomainUid()
193184
+ " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate");
194185

195186
TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate");
196-
domain.testDomainServerPodRestart(
187+
domain.verifyDomainServerPodRestart(
197188
"\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\"");
198189
} finally {
199190
TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate");
@@ -202,135 +193,115 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
202193
logger.info("SUCCESS - " + testMethodName);
203194
}
204195

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+
*/
205205
@Test
206-
public void testAdminServerRestartVersions() throws Exception {
206+
public void testServerPodsRestartByChangingContSecurityContext() throws Exception {
207207
Assume.assumeFalse(QUICKTEST);
208208
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
209209
logTestBegin(testMethodName);
210-
String originalYaml =
211-
BaseTest.getUserProjectsDir()
212-
+ "/weblogic-domains/"
213-
+ domain.getDomainUid()
214-
+ "/domain.yaml";
215-
try {
216-
DomainCRD crd = new DomainCRD();
217-
String yaml =
218-
crd.addRestartVersionToAdminServer(
219-
TestUtils.exec(
220-
"kubectl get Domain "
221-
+ domain.getDomainUid()
222-
+ " -n "
223-
+ domain.getDomainNS()
224-
+ " --output json")
225-
.stdout(),
226-
"v1.1");
227-
Path path = Paths.get(restartTmpDir, "restart.admin.yaml");
228-
Charset charset = StandardCharsets.UTF_8;
229-
Files.write(path, yaml.getBytes(charset));
230-
logger.info(TestUtils.exec("kubectl apply -f " + path.toString()).stdout());
231-
domain.verifyAdminServerRestarted();
232-
} finally {
233-
TestUtils.exec("kubectl apply -f " + originalYaml);
234-
domain.verifyAdminServerRestarted();
235-
}
236-
logger.info("SUCCESS - " + testMethodName);
237-
}
238210

239-
// @Test
240-
public void testClusterRestartVersions() throws Exception {
241-
Assume.assumeFalse(QUICKTEST);
242-
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
243-
logTestBegin(testMethodName);
244-
ExecResult result;
245-
String originalYaml =
246-
BaseTest.getUserProjectsDir()
247-
+ "/weblogic-domains/"
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: "
248222
+ domain.getDomainUid()
249-
+ "/domain.yaml";
250-
try {
251-
result =
252-
TestUtils.exec(
253-
"kubectl get Domain "
254-
+ domain.getDomainUid()
255-
+ " -n "
256-
+ domain.getDomainNS()
257-
+ " --output json");
258-
DomainCRD parser = new DomainCRD();
259-
String yaml =
260-
parser.addRestartVersionToCluster(
261-
result.stdout(), domain.getDomainMap().get("clusterName").toString(), "v1.1");
262-
Path path = Paths.get(restartTmpDir, "restart.cluster.yaml");
263-
Charset charset = StandardCharsets.UTF_8;
264-
Files.write(path, yaml.getBytes(charset));
265-
result = TestUtils.exec("kubectl apply -f " + path.toString());
266-
// TODO - verify that the pod is restarting
267-
} finally {
268-
result = TestUtils.exec("kubectl apply -f " + originalYaml);
269-
}
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+
270230
logger.info("SUCCESS - " + testMethodName);
271231
}
272232

273-
// @Test
274-
public void testMSRestartVersions() throws Exception {
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 {
275244
Assume.assumeFalse(QUICKTEST);
276245
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
277246
logTestBegin(testMethodName);
278-
ExecResult result;
279-
String originalYaml =
280-
BaseTest.getUserProjectsDir()
281-
+ "/weblogic-domains/"
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: "
282260
+ domain.getDomainUid()
283-
+ "/domain.yaml";
284-
try {
285-
result =
286-
TestUtils.exec(
287-
"kubectl get Domain "
288-
+ domain.getDomainUid()
289-
+ " -n "
290-
+ domain.getDomainNS()
291-
+ " --output json");
292-
DomainCRD parser = new DomainCRD();
293-
String yaml = parser.addRestartVersionToMS(result.stdout(), "managed-server1", "v1.1");
294-
Path path = Paths.get(restartTmpDir, "restart.ms.yaml");
295-
Charset charset = StandardCharsets.UTF_8;
296-
Files.write(path, yaml.getBytes(charset));
297-
result = TestUtils.exec("kubectl apply -f " + path.toString());
298-
// TODO - verify that the pod is restarting
299-
} finally {
300-
result = TestUtils.exec("kubectl apply -f " + originalYaml);
301-
}
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+
302268
logger.info("SUCCESS - " + testMethodName);
303269
}
304270

305-
// @Test
306-
public void testDomainRestartVersions() throws Exception {
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 {
307282
Assume.assumeFalse(QUICKTEST);
308283
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
309284
logTestBegin(testMethodName);
310-
ExecResult result;
311-
String originalYaml =
312-
BaseTest.getUserProjectsDir()
313-
+ "/weblogic-domains/"
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: "
314298
+ domain.getDomainUid()
315-
+ "/domain.yaml";
316-
try {
317-
result =
318-
TestUtils.exec(
319-
"kubectl get Domain "
320-
+ domain.getDomainUid()
321-
+ " -n "
322-
+ domain.getDomainNS()
323-
+ " --output json");
324-
DomainCRD parser = new DomainCRD();
325-
String yaml = parser.addRestartVersionToDomain(result.stdout(), "v1.1");
326-
Path path = Paths.get(restartTmpDir, "restart.ms.yaml");
327-
Charset charset = StandardCharsets.UTF_8;
328-
Files.write(path, yaml.getBytes(charset));
329-
result = TestUtils.exec("kubectl apply -f " + path.toString());
330-
// TODO - verify that the pod is restarting
331-
} finally {
332-
result = TestUtils.exec("kubectl apply -f " + originalYaml);
333-
}
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+
334305
logger.info("SUCCESS - " + testMethodName);
335306
}
336307

@@ -340,7 +311,9 @@ private static Domain createPodsRestartdomain() throws Exception {
340311
domainMap.put("domainUID", "domainpodsrestart");
341312
domainMap.put("initialManagedServerReplicas", new Integer("1"));
342313

343-
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+
344317
domain = TestUtils.createDomain(domainMap);
345318
domain.verifyDomainCreated();
346319

0 commit comments

Comments
 (0)