Skip to content

Commit 4c92a1e

Browse files
authored
Merge pull request #1029 from oracle/restartversiontests
Restartversiontests
2 parents 8e677e1 + 4d6a02a commit 4c92a1e

File tree

5 files changed

+574
-0
lines changed

5 files changed

+574
-0
lines changed

integration-tests/USECASES.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Basic Use Cases described above are verified in all the domain configurations. A
7676
| Server pods restarted by changing containerSecurityContext | Verify admin and managed server pods being restarted by adding property change: containerSecurityContext: runAsUser: 1000 fsGroup: 2000 |
7777
| Server pods restarted by changing podSecurityContex | Verify admin and managed server pods being restarted by adding property change: podSecurityContext: runAsUser: 1000 fsGroup: 2000 |
7878
| 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" |
79+
| Server pods restarted by changing restartVersion at admin level | Verify admin pod restarted by adding restartVersion property at admin server level: `restartVersion: "v1.1"` |
80+
| Server pods restarted by changing restartVersion at cluster level | Verify managed server pods part of the dynamic cluster are restarted by adding restartVersion property at cluster level : `restartVersion: "v1.1"` |
81+
| Server pods restarted by changing restartVersion at domain level | Verify all the server pods in the weblogic domain are restarted by adding restartVersion property at domain level: `restartVersion: "v1.1"` |
7982

8083
Configuration Overrides Usecases
8184

integration-tests/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@
6161
<artifactId>guava</artifactId>
6262
<version>${guava-version}</version>
6363
</dependency>
64+
<!-- JSON processing: jackson -->
65+
<dependency>
66+
<groupId>com.fasterxml.jackson.core</groupId>
67+
<artifactId>jackson-core</artifactId>
68+
<version>${jackson-version}</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.fasterxml.jackson.core</groupId>
72+
<artifactId>jackson-annotations</artifactId>
73+
<version>${jackson-version}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>com.fasterxml.jackson.core</groupId>
77+
<artifactId>jackson-databind</artifactId>
78+
<version>${jackson-version}</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.fasterxml.jackson.dataformat</groupId>
82+
<artifactId>jackson-dataformat-yaml</artifactId>
83+
<version>${jackson-version}</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>com.fasterxml.jackson.datatype</groupId>
87+
<artifactId>jackson-datatype-joda</artifactId>
88+
<version>${jackson-version}</version>
89+
</dependency>
6490
<dependency>
6591
<groupId>org.yaml</groupId>
6692
<artifactId>snakeyaml</artifactId>

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

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44

55
package oracle.kubernetes.operator;
66

7+
import java.nio.charset.Charset;
8+
import java.nio.charset.StandardCharsets;
79
import java.nio.file.Files;
10+
import java.nio.file.Path;
811
import java.nio.file.Paths;
12+
import java.util.HashMap;
913
import java.util.Map;
14+
import java.util.logging.Level;
1015
import oracle.kubernetes.operator.utils.Domain;
16+
import oracle.kubernetes.operator.utils.DomainCRD;
17+
import oracle.kubernetes.operator.utils.ExecResult;
18+
import oracle.kubernetes.operator.utils.K8sTestUtils;
1119
import oracle.kubernetes.operator.utils.Operator;
1220
import oracle.kubernetes.operator.utils.TestUtils;
1321
import org.junit.AfterClass;
@@ -29,6 +37,8 @@ public class ITPodsRestart extends BaseTest {
2937
private static Domain domain = null;
3038
private static Operator operator1;
3139
private static String domainUid = "";
40+
private static String restartTmpDir = "";
41+
private static String originalYaml;
3242

3343
/**
3444
* This method gets called only once before any of the test methods are executed. It does the
@@ -48,8 +58,15 @@ public static void staticPrepare() throws Exception {
4858
if (operator1 == null) {
4959
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
5060
}
61+
restartTmpDir = BaseTest.getResultDir() + "/restarttemp";
62+
Files.createDirectories(Paths.get(restartTmpDir));
5163

5264
domain = createPodsRestartdomain();
65+
originalYaml =
66+
BaseTest.getUserProjectsDir()
67+
+ "/weblogic-domains/"
68+
+ domain.getDomainUid()
69+
+ "/domain.yaml";
5370
Assert.assertNotNull(domain);
5471
}
5572
}
@@ -305,6 +322,209 @@ public void testServerPodsRestartByChangingResource() throws Exception {
305322
logger.info("SUCCESS - " + testMethodName);
306323
}
307324

325+
/**
326+
* Add restartVersion:v1.1 at adminServer level and verify the admin pod is Terminated and
327+
* recreated
328+
*
329+
* @throws Exception when domain.yaml cannot be read or modified to include the
330+
* restartVersion:v1.1
331+
*/
332+
@Test
333+
public void testAdminServerRestartVersion() throws Exception {
334+
Assume.assumeFalse(QUICKTEST);
335+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
336+
logTestBegin(testMethodName);
337+
String podName = domainUid + "-" + domain.getAdminServerName();
338+
339+
try {
340+
// Modify the original domain yaml to include restartVersion in admin server node
341+
DomainCRD crd = new DomainCRD(originalYaml);
342+
Map<String, String> admin = new HashMap();
343+
admin.put("restartVersion", "v1.1");
344+
crd.addObjectNodeToAdminServer(admin);
345+
String modYaml = crd.getYamlTree();
346+
logger.info(modYaml);
347+
348+
// Write the modified yaml to a new file
349+
Path path = Paths.get(restartTmpDir, "restart.admin.yaml");
350+
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
351+
Charset charset = StandardCharsets.UTF_8;
352+
Files.write(path, modYaml.getBytes(charset));
353+
354+
// Apply the new yaml to update the domain
355+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
356+
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
357+
logger.info(exec.stdout());
358+
359+
logger.info("Verifying if the admin server is terminating");
360+
verifyPodStatus(podName, "Terminating");
361+
verifyPodStatus(podName, "Running");
362+
363+
} finally {
364+
logger.log(
365+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
366+
TestUtils.exec("kubectl apply -f " + originalYaml);
367+
logger.info("Verifying if the admin server is terminating");
368+
verifyPodStatus(podName, "Terminating");
369+
verifyPodStatus(podName, "Running");
370+
}
371+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
372+
}
373+
374+
/**
375+
* Add restartVersion:v1.1 at cluster level and verify the managed servers pods are Terminated and
376+
* recreated
377+
*
378+
* @throws Exception when domain.yaml cannot be read or modified to include the
379+
* restartVersion:v1.1
380+
*/
381+
@Test
382+
public void testClusterRestartVersion() throws Exception {
383+
Assume.assumeFalse(QUICKTEST);
384+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
385+
logTestBegin(testMethodName);
386+
String podName = domainUid + "-managed-server1";
387+
388+
try {
389+
// Modify the original domain yaml to include restartVersion in admin server node
390+
DomainCRD crd = new DomainCRD(originalYaml);
391+
Map<String, String> cluster = new HashMap();
392+
cluster.put("restartVersion", "v1.1");
393+
crd.addObjectNodeToCluster("cluster-1", cluster);
394+
String modYaml = crd.getYamlTree();
395+
logger.info(modYaml);
396+
397+
// Write the modified yaml to a new file
398+
Path path = Paths.get(restartTmpDir, "restart.cluster.yaml");
399+
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
400+
Charset charset = StandardCharsets.UTF_8;
401+
Files.write(path, modYaml.getBytes(charset));
402+
403+
// Apply the new yaml to update the domain crd
404+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
405+
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
406+
logger.info(exec.stdout());
407+
logger.info("Verifying if the cluster is restarted");
408+
verifyPodStatus(podName, "Terminating");
409+
verifyPodStatus(podName, "Running");
410+
} finally {
411+
logger.log(
412+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
413+
TestUtils.exec("kubectl apply -f " + originalYaml);
414+
logger.info("Verifying if the cluster is restarted");
415+
verifyPodStatus(podName, "Terminating");
416+
verifyPodStatus(podName, "Running");
417+
}
418+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
419+
}
420+
421+
/**
422+
* Add restartVersion:v1.1 at managed server level and verify the managed server pod are
423+
* Terminated and recreated
424+
*
425+
* <p>Currently failing and tracked by bug in BugDB - 29489387
426+
*
427+
* @throws Exception when domain.yaml cannot be read or modified to include the
428+
* restartVersion:v1.1
429+
*/
430+
// @Test
431+
public void testMSRestartVersion() throws Exception {
432+
Assume.assumeFalse(QUICKTEST);
433+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
434+
logTestBegin(testMethodName);
435+
String podName = domainUid + "-managed-server1";
436+
437+
try {
438+
// Modify the original domain yaml to include restartVersion in admin server node
439+
DomainCRD crd = new DomainCRD(originalYaml);
440+
Map<String, String> ms = new HashMap();
441+
ms.put("restartVersion", "v1.1");
442+
ms.put("serverStartPolicy", "IF_NEEDED");
443+
ms.put("serverStartState", "RUNNING");
444+
crd.addObjectNodeToMS("managed-server1", ms);
445+
String modYaml = crd.getYamlTree();
446+
logger.info(modYaml);
447+
448+
// Write the modified yaml to a new file
449+
Path path = Paths.get(restartTmpDir, "restart.managed.yaml");
450+
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
451+
Charset charset = StandardCharsets.UTF_8;
452+
Files.write(path, modYaml.getBytes(charset));
453+
454+
// Apply the new yaml to update the domain crd
455+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
456+
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
457+
logger.info(exec.stdout());
458+
logger.info("Verifying if the managed server is restarted");
459+
verifyPodStatus(podName, "Terminating");
460+
verifyPodStatus(podName, "Running");
461+
} finally {
462+
logger.log(
463+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
464+
TestUtils.exec("kubectl apply -f " + originalYaml);
465+
logger.info("Verifying if the managed server is restarted");
466+
verifyPodStatus(podName, "Terminating");
467+
verifyPodStatus(podName, "Running");
468+
}
469+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
470+
}
471+
472+
/**
473+
* Add restartVersion:v1.1 at doamin level and verify all of the server pods are Terminated and
474+
* recreated
475+
*
476+
* @throws Exception when domain.yaml cannot be read or modified to include the
477+
* restartVersion:v1.1
478+
*/
479+
@Test
480+
public void testDomainRestartVersion() throws Exception {
481+
Assume.assumeFalse(QUICKTEST);
482+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
483+
logTestBegin(testMethodName);
484+
String adminPod = domainUid + "-" + domain.getAdminServerName();
485+
String msPod = domainUid + "-managed-server1";
486+
487+
try {
488+
// Modify the original domain yaml to include restartVersion in admin server node
489+
DomainCRD crd = new DomainCRD(originalYaml);
490+
Map<String, String> domain = new HashMap();
491+
domain.put("restartVersion", "v1.1");
492+
crd.addObjectNodeToDomain(domain);
493+
String modYaml = crd.getYamlTree();
494+
logger.info(modYaml);
495+
496+
// Write the modified yaml to a new file
497+
Path path = Paths.get(restartTmpDir, "restart.domain.yaml");
498+
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
499+
Charset charset = StandardCharsets.UTF_8;
500+
Files.write(path, modYaml.getBytes(charset));
501+
502+
// Apply the new yaml to update the domain crd
503+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
504+
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
505+
logger.info(exec.stdout());
506+
logger.info("Verifying if the domain is restarted");
507+
logger.info("Verifying if the admin server is restarted");
508+
verifyPodStatus(adminPod, "Terminating");
509+
verifyPodStatus(adminPod, "Running");
510+
logger.info("Verifying if the managed server is restarted");
511+
verifyPodStatus(msPod, "Terminating");
512+
verifyPodStatus(msPod, "Running");
513+
} finally {
514+
logger.log(
515+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
516+
TestUtils.exec("kubectl apply -f " + originalYaml);
517+
logger.info("Verifying if the domain is restarted");
518+
logger.info("Verifying if the admin server is restarted");
519+
verifyPodStatus(adminPod, "Terminating");
520+
verifyPodStatus(adminPod, "Running");
521+
logger.info("Verifying if the managed server is restarted");
522+
verifyPodStatus(msPod, "Terminating");
523+
verifyPodStatus(msPod, "Running");
524+
}
525+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
526+
}
527+
308528
private static Domain createPodsRestartdomain() throws Exception {
309529

310530
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
@@ -325,4 +545,35 @@ private static void destroyPodsRestartdomain() throws Exception {
325545
domain.destroy();
326546
}
327547
}
548+
549+
/**
550+
* Utility method to check if a pod is in Terminating or Running status
551+
*
552+
* @param podName - String name of the pod to check the status for
553+
* @param podStatusExpected - String the expected status of Terminating || RUnning
554+
* @throws InterruptedException when thread is interrupted
555+
*/
556+
private void verifyPodStatus(String podName, String podStatusExpected)
557+
throws InterruptedException {
558+
K8sTestUtils testUtil = new K8sTestUtils();
559+
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", domainUid);
560+
String namespace = domain.getDomainNS();
561+
boolean gotExpected = false;
562+
for (int i = 0; i < BaseTest.getMaxIterationsPod(); i++) {
563+
if (podStatusExpected.equals("Terminating")) {
564+
if (testUtil.isPodTerminating(namespace, domain1LabelSelector, podName)) {
565+
gotExpected = true;
566+
break;
567+
}
568+
} else if (podStatusExpected.equals("Running")) {
569+
if (testUtil.isPodRunning(namespace, domain1LabelSelector, podName)) {
570+
gotExpected = true;
571+
break;
572+
}
573+
}
574+
575+
Thread.sleep(BaseTest.getWaitTimePod() * 1000);
576+
}
577+
Assert.assertTrue("Didn't get the expected pod status", gotExpected);
578+
}
328579
}

0 commit comments

Comments
 (0)