Skip to content

Commit 8eea247

Browse files
authored
Merge pull request #943 from oracle/marinatest
added usability test cases for Operator/Domain interaction
2 parents 0fa767f + 6f47c1c commit 8eea247

File tree

4 files changed

+197
-16
lines changed

4 files changed

+197
-16
lines changed

integration-tests/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ 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+
| Operator Helm Chart add/delete target domain namespaces (domain1, domain2) | create operator helm chart managing domain1, use upgrade to add domain2. Verify that operator is able to manage added domain (domain2). Use helm upgrade to remove domain1, verify that operator not able to manage anymore the deleted one(domain1) |
81+
| Operator Helm Chart delete operator helm chart, leave domain running | create operator helm chart and start domain1, delete operator helm chart, verify domain1 is still functional |
8082

8183
| Server Pods Restarted by modifying properties on the domain resource| Use Case |
8284
| --- | --- |
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 Env property | Verify admin and managed server pods being restarted by property change: `-Dweblogic.StdoutDebugEnabled=false` --> `-Dweblogic.StdoutDebugEnabled=true` |
86+
| 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` |
8587
| Server pods restarted by changing imagePullPolicy | Verify admin and managed server pods being restarted by property change: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never |
8688
| Server pods restarted by changing includeServerOutInPodLog | Verify admin and managed server pods being restarted by property change: includeServerOutInPodLog: true --> includeServerOutInPodLog: false |
8789
| Server pods restarted by changing logHomeEnable | Verify admin and managed server pods being restarted by property change: logHomeEnabled: true --> logHomeEnabled: false |
@@ -95,6 +97,7 @@ Configuration Overrides Usecases
9597
| JMS Resource Override | Override UniformDistributedTopic Delivery Failure Parameters, `redelivery-limit` and `expiration-policy`. The JMX test client verifies the serverConfig MBean tree for the expected delivery failure parameters, `redelivery-limit` and `expiration-policy`. |
9698
| WLDF Resource Override | Override `wldf-instrumentation-monitor` and `harvester` in a diagnostics module. The test client verifies the new instrumentation monitors/harvesters set by getting the WLDF resource from serverConfig tree with expected values. |
9799

100+
98101
# Directory Configuration and Structure
99102

100103
Directory structure of source code:
@@ -103,7 +106,7 @@ A new module "integration-tests" is added to the Maven project `weblogic-kuberne
103106

104107
`weblogic-kubernetes-operator/integration-tests` - location of module pom.xml
105108
`weblogic-kubernetes-operator/integration-tests/src/test/java` - integration test(JUnit) classes and utility classes
106-
`weblogic-kubernetes-operator/integration-tests/src/test/resources` - properties, YAML files (see Configuration Files section) and other scripts.
109+
`weblogic-kubernetes-operator/integration-tests/src/test/resources` - properties, YAML files (see Configuration Files section) and other scripts
107110

108111
Directory structure used for the test run:
109112

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

Lines changed: 154 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// 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.
44

55
package oracle.kubernetes.operator;
66

77
import java.util.ArrayList;
88
import java.util.Map;
9+
import oracle.kubernetes.operator.utils.Domain;
910
import oracle.kubernetes.operator.utils.ExecCommand;
1011
import oracle.kubernetes.operator.utils.ExecResult;
1112
import oracle.kubernetes.operator.utils.Operator;
@@ -28,6 +29,8 @@ public class ITUsabilityOperatorHelmChart extends BaseTest {
2829

2930
private static int number = 3;
3031
String oprelease = "op" + number;
32+
private int waitTime = 5;
33+
private int maxIterations = 60;
3134

3235
/**
3336
* This method gets called only once before any of the test methods are executed. It does the
@@ -560,14 +563,6 @@ public void testCreateWithEmptyTargetDomainInstall() throws Exception {
560563
logger.info("SUCCESS - " + testMethodName);
561564
}
562565

563-
private void upgradeOperator(Operator operator, String upgradeSet) throws Exception {
564-
Assume.assumeFalse(QUICKTEST);
565-
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
566-
logTestBegin(testMethodName);
567-
operator.callHelmUpgrade(upgradeSet);
568-
logger.info("SUCCESS - " + testMethodName);
569-
}
570-
571566
/**
572567
* Helm installs the operator with default target domains namespaces
573568
*
@@ -596,4 +591,154 @@ public void testCreateWithDefaultTargetDomainInstall() throws Exception {
596591
}
597592
logger.info("SUCCESS - " + testMethodName);
598593
}
594+
595+
/**
596+
* Create operator and verify its deployed successfully. Create domain1 and verify domain is
597+
* started. Call helm upgrade to add domainnew to manage, verify both domains are managed by
598+
* operator Call helm upgrade to remove first domain from operator target domains, verify it can't
599+
* not be managed by operator anymore
600+
*
601+
* @throws Exception
602+
*/
603+
@Test
604+
public void testAddRemoveDomainUpdateOperatorHC() throws Exception {
605+
Assume.assumeFalse(QUICKTEST);
606+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
607+
logTestBegin(testMethodName);
608+
logger.info("Creating Operator & waiting for the script to complete execution");
609+
// create operator
610+
Map<String, Object> operatorMap = TestUtils.createOperatorMap(number, true);
611+
Operator operator = new Operator(operatorMap, RESTCertType.SELF_SIGNED);
612+
operator.callHelmInstall();
613+
Domain domain = null;
614+
Domain domainnew = null;
615+
boolean testCompletedSuccessfully = false;
616+
try {
617+
logger.info("kubectl create namespace test" + (number + 1));
618+
ExecCommand.exec("kubectl create namespace test" + (number + 1));
619+
domain = createVerifyDomain(number, operator);
620+
ArrayList<String> targetDomainsNS =
621+
(ArrayList<String>) (operator.getOperatorMap().get("domainNamespaces"));
622+
targetDomainsNS.add("test" + (number + 1));
623+
upgradeOperatorDomainNamespaces(operator, targetDomainsNS);
624+
domainnew = createVerifyDomain(number + 1, operator);
625+
logger.info("verify that old domain is managed by operator after upgrade");
626+
verifyOperatorDomainManagement(operator, domain, true);
627+
logger.info("Upgrade to remove first domain");
628+
targetDomainsNS.remove("test" + (number));
629+
upgradeOperatorDomainNamespaces(operator, targetDomainsNS);
630+
logger.info("verify that old domain is not managed by operator");
631+
verifyOperatorDomainManagement(operator, domain, false);
632+
verifyOperatorDomainManagement(operator, domainnew, true);
633+
testCompletedSuccessfully = true;
634+
} finally {
635+
if (domain != null) {
636+
TestUtils.deleteWeblogicDomainResources(domain.getDomainUid());
637+
}
638+
if (domainnew != null) {
639+
domainnew.destroy();
640+
}
641+
if (operator != null) {
642+
operator.destroy();
643+
}
644+
number++;
645+
}
646+
logger.info("SUCCESS - " + testMethodName);
647+
}
648+
649+
/**
650+
* Create operator and verify its deployed successfully. Create domain1 and verify domain is
651+
* started. Delete operator and make sure domain1 is still functional
652+
*
653+
* @throws Exception
654+
*/
655+
@Test
656+
public void testDeleteOperatorButNotDomain() throws Exception {
657+
Assume.assumeFalse(QUICKTEST);
658+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
659+
logTestBegin(testMethodName);
660+
logger.info("Creating Operator & waiting for the script to complete execution");
661+
// create operator
662+
Operator operator = null;
663+
Domain domain = null;
664+
boolean testCompletedSuccessfully = false;
665+
try {
666+
Map<String, Object> operatorMap = TestUtils.createOperatorMap(number, true);
667+
operator = new Operator(operatorMap, RESTCertType.SELF_SIGNED);
668+
operator.callHelmInstall();
669+
domain = createVerifyDomain(number, operator);
670+
logger.info("Deleting operator to check that domain functionality is not effected");
671+
operator.destroy();
672+
operator = null;
673+
domain.testWlsLivenessProbe();
674+
testCompletedSuccessfully = true;
675+
} finally {
676+
if (domain != null) {
677+
TestUtils.deleteWeblogicDomainResources(domain.getDomainUid());
678+
}
679+
if (operator != null) {
680+
operator.destroy();
681+
}
682+
number++;
683+
}
684+
logger.info("SUCCESS - " + testMethodName);
685+
}
686+
687+
private void verifyOperatorDomainManagement(
688+
Operator operator, Domain domain, boolean isAccessible) throws Exception {
689+
for (int i = 0; i < maxIterations; i++) {
690+
try {
691+
operator.verifyDomainExists(domain.getDomainUid());
692+
if (!isAccessible) {
693+
throw new RuntimeException("FAILURE: Operator still able to manage old namespace ");
694+
} else {
695+
break;
696+
}
697+
} catch (Exception ex) {
698+
if (!isAccessible) {
699+
if (!ex.getMessage()
700+
.contains(
701+
"Response {\"status\":404,\"detail\":\"/operator/latest/domains/test" + number)) {
702+
} else {
703+
break;
704+
}
705+
}
706+
}
707+
if (i == maxIterations - 1) {
708+
String errorMsg = "FAILURE: Operator can't access the domain " + domain.getDomainUid();
709+
if (!isAccessible) {
710+
errorMsg = "FAILURE: Operator still can access the domain " + domain.getDomainUid();
711+
}
712+
throw new RuntimeException(errorMsg);
713+
}
714+
logger.info("iteration " + i + " of " + maxIterations);
715+
Thread.sleep(waitTime * 1000);
716+
}
717+
}
718+
719+
private Domain createVerifyDomain(int number, Operator operator) throws Exception {
720+
logger.info("create domain with UID : test" + number);
721+
Domain domain = TestUtils.createDomain(TestUtils.createDomainMap(number));
722+
domain.verifyDomainCreated();
723+
testAdminT3Channel(domain);
724+
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
725+
logger.info("verify that domain is managed by operator");
726+
operator.verifyDomainExists(domain.getDomainUid());
727+
return domain;
728+
}
729+
730+
private void upgradeOperatorDomainNamespaces(
731+
Operator operator, ArrayList<String> targetNamespaces) throws Exception {
732+
logger.info("update operator with new target domain");
733+
String upgradeSet =
734+
"domainNamespaces="
735+
+ targetNamespaces
736+
.toString()
737+
.replaceAll("\\[", "{")
738+
.replaceAll("\\]", "}")
739+
.replaceAll(" ", "");
740+
logger.info("update operator with new target domain " + upgradeSet);
741+
operator.callHelmUpgrade(upgradeSet);
742+
operator.getOperatorMap().replace("domainNamespaces", targetNamespaces);
743+
}
599744
}

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 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.
44

@@ -311,9 +311,9 @@ public void callHelmUpgrade(String upgradeSet) throws Exception {
311311
.append(" && helm upgrade ")
312312
.append(operatorMap.get("releaseName"))
313313
.append(" kubernetes/charts/weblogic-operator ")
314-
.append(" --set ")
314+
.append(" --set \"")
315315
.append(upgradeSet)
316-
.append(" --reuse-values ")
316+
.append("\" --reuse-values ")
317317
.append(" --wait --timeout 60");
318318
logger.info("Running " + cmd);
319319
ExecResult result = ExecCommand.exec(cmd.toString());
@@ -324,6 +324,22 @@ public void callHelmUpgrade(String upgradeSet) throws Exception {
324324
logger.info("Command returned " + outputStr);
325325
}
326326

327+
public String getHelmValues() throws Exception {
328+
StringBuffer cmd = new StringBuffer("cd ");
329+
cmd.append(BaseTest.getProjectRoot())
330+
.append(" && helm get values ")
331+
.append(operatorMap.get("releaseName"));
332+
333+
logger.info("Running " + cmd);
334+
ExecResult result = ExecCommand.exec(cmd.toString());
335+
if (result.exitValue() != 0) {
336+
reportHelmFailure(cmd.toString(), result);
337+
}
338+
String outputStr = result.stdout().trim();
339+
logger.info("Command returned " + outputStr);
340+
return outputStr;
341+
}
342+
327343
private void reportHelmFailure(String cmd, ExecResult result) throws Exception {
328344
logger.info("reportHelmFailure " + result);
329345
throw new RuntimeException(getExecFailure(cmd, result));

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,9 @@ public static String getLegacyAccessToken(Operator operator) throws Exception {
517517
}
518518

519519
public static String getAccessToken(Operator operator) throws Exception {
520-
StringBuffer secretCmd = new StringBuffer("kubectl get serviceaccount weblogic-operator ");
520+
StringBuffer secretCmd =
521+
new StringBuffer(
522+
"kubectl get serviceaccount " + operator.getOperatorMap().get("serviceAccount"));
521523
secretCmd
522524
.append(" -n ")
523525
.append(operator.getOperatorNamespace())
@@ -806,6 +808,21 @@ public static Map<String, Object> createOperatorMap(int number, boolean restEnab
806808
return operatorMap;
807809
}
808810

811+
public static Map<String, Object> createDomainMap(int number) {
812+
Map<String, Object> domainMap = new HashMap<>();
813+
ArrayList<String> targetDomainsNS = new ArrayList<String>();
814+
targetDomainsNS.add("test" + number);
815+
domainMap.put("domainUID", "test" + number);
816+
domainMap.put("namespace", "test" + number);
817+
domainMap.put("configuredManagedServerCount", 4);
818+
domainMap.put("initialManagedServerReplicas", 2);
819+
domainMap.put("exposeAdminT3Channel", true);
820+
domainMap.put("exposeAdminNodePort", true);
821+
domainMap.put("adminNodePort", 30700 + number);
822+
domainMap.put("t3ChannelPort", 30000 + number);
823+
return domainMap;
824+
}
825+
809826
public static String callShellScriptByExecToPod(
810827
String scriptPath, String arguments, String podName, String namespace) throws Exception {
811828

0 commit comments

Comments
 (0)