Skip to content

Commit 5a190d1

Browse files
committed
added Operator/Domain interaction usability testcases
1 parent 029faf1 commit 5a190d1

File tree

5 files changed

+125
-16
lines changed

5 files changed

+125
-16
lines changed

integration-tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ 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-
80+
| Operator Helm Chart add/delete target domains namespace ( domain1, domain2) | create chart , use upgrade to add/remove target domains ( domain1,domain2), verify that operator is able to manage added domain (domain2, not able to access the deleted one(domain1), after delete operator, verify that domain2 is still functional |
8181

8282

8383
# Directory Configuration and Structure
@@ -88,7 +88,7 @@ A new module "integration-tests" is added to the Maven project `weblogic-kuberne
8888

8989
`weblogic-kubernetes-operator/integration-tests` - location of module pom.xml
9090
`weblogic-kubernetes-operator/integration-tests/src/test/java` - integration test(JUnit) classes and utility classes
91-
`weblogic-kubernetes-operator/integration-tests/src/test/resources` - properties, YAML files (see Configuration Files section) and other scripts.
91+
`weblogic-kubernetes-operator/integration-tests/src/test/resources` - properties, YAML files (see Configuration Files section) and other scripts
9292

9393
Directory structure used for the test run:
9494

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

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@
66

77
import java.util.ArrayList;
88
import java.util.Map;
9-
import oracle.kubernetes.operator.utils.ExecCommand;
10-
import oracle.kubernetes.operator.utils.ExecResult;
11-
import oracle.kubernetes.operator.utils.Operator;
9+
import oracle.kubernetes.operator.utils.*;
1210
import oracle.kubernetes.operator.utils.Operator.RESTCertType;
13-
import oracle.kubernetes.operator.utils.TestUtils;
14-
import org.junit.AfterClass;
15-
import org.junit.Assume;
16-
import org.junit.BeforeClass;
17-
import org.junit.FixMethodOrder;
18-
import org.junit.Test;
11+
import org.junit.*;
1912
import org.junit.runners.MethodSorters;
2013

2114
/**
@@ -596,4 +589,87 @@ public void testCreateWithDefaultTargetDomainInstall() throws Exception {
596589
}
597590
logger.info("SUCCESS - " + testMethodName);
598591
}
592+
/**
593+
* Create operator and verify its deployed successfully. Create domain1 and verify domain is
594+
* started. Call helm upgrade to add domainnew to manage, verify both domains are managed by
595+
* operator Call helm upgrade to remove first domain from operator target domains, verify it can't
596+
* not be managed by operator anymore Delete operator and make sure domainnew is still functional
597+
*
598+
* @throws Exception
599+
*/
600+
@Test
601+
public void testAddRemoveDomainUpdateOperatorHC() throws Exception {
602+
Assume.assumeFalse(QUICKTEST);
603+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
604+
logTestBegin(testMethodName);
605+
logger.info("Creating Operator & waiting for the script to complete execution");
606+
// create operator
607+
Map<String, Object> operatorMap = TestUtils.createOperatorMap(number, true);
608+
Operator operator = new Operator(operatorMap, RESTCertType.SELF_SIGNED);
609+
operator.callHelmInstall();
610+
Domain domain = null;
611+
Domain domainnew = null;
612+
boolean testCompletedSuccessfully = false;
613+
logger.info("kubectl create namespace test" + (number + 1));
614+
ExecCommand.exec("kubectl create namespace test" + (number + 1));
615+
logger.info("create domain with UID : test" + number);
616+
domain = TestUtils.createDomain(TestUtils.createDomainMap(number));
617+
domain.verifyDomainCreated();
618+
testAdminT3Channel(domain);
619+
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
620+
logger.info("verify that domain is managed by operator");
621+
operator.verifyDomainExists(domain.getDomainUid());
622+
logger.info("update operator with new target domain");
623+
operator.callHelmUpgrade("domainNamespaces={test" + number + ",test" + (number + 1) + "}");
624+
625+
ArrayList<String> targetDomainsNS =
626+
(ArrayList<String>) (operator.getOperatorMap().get("domainNamespaces"));
627+
targetDomainsNS.add("test" + (number + 1));
628+
operatorMap.replace("domainNamespaces", targetDomainsNS);
629+
domainnew = TestUtils.createDomain(TestUtils.createDomainMap(number + 1));
630+
domainnew.verifyDomainCreated();
631+
testAdminT3Channel(domainnew);
632+
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
633+
logger.info("verify that new domain is managed by operator after upgrade");
634+
operator.verifyDomainExists(domainnew.getDomainUid());
635+
logger.info("verify that old domain is managed by operator after upgrade");
636+
operator.verifyDomainExists(domain.getDomainUid());
637+
logger.info("Upgrade to remove first domain");
638+
operator.callHelmUpgrade("domainNamespaces={test" + (number + 1) + "}");
639+
targetDomainsNS = (ArrayList<String>) (operator.getOperatorMap().get("domainNamespaces"));
640+
targetDomainsNS.remove("test" + (number));
641+
operatorMap.replace("domainNamespaces", targetDomainsNS);
642+
Thread.sleep(30 * 1000);
643+
try {
644+
logger.info("verify that old domain is not managed by operator");
645+
operator.verifyDomainExists(domain.getDomainUid());
646+
throw new RuntimeException(
647+
"FAILURE: After Helm Upgrade for the domainNamespaces operator still able to manage old namespace ");
648+
} catch (Exception ex) {
649+
if (!ex.getMessage()
650+
.contains(
651+
" Response {\"status\":404,\"detail\":\"/operator/latest/domains/test"
652+
+ number
653+
+ "\""))
654+
throw new RuntimeException(
655+
"FAILURE: Exception does not report the expected error message " + ex.getMessage());
656+
logger.info("Deleting operator to check that domain functionality is not effected");
657+
operator.destroy();
658+
operator = null;
659+
Thread.sleep(20 * 1000);
660+
domainnew.testWlsLivenessProbe();
661+
testCompletedSuccessfully = true;
662+
} finally {
663+
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) domain.destroy();
664+
if (domainnew != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully))
665+
domainnew.destroy();
666+
667+
if (operator != null) {
668+
operator.destroy();
669+
}
670+
number++;
671+
}
672+
673+
logger.info("SUCCESS - " + testMethodName);
674+
}
599675
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public void verifyHasClusterServiceChannelPort(String protocol, int port, String
362362
public void deployWebAppViaREST(
363363
String webappName, String webappLocation, String username, String password) throws Exception {
364364
StringBuffer cmd = new StringBuffer();
365-
cmd.append("curl --noproxy '*' --silent --user ")
365+
cmd.append("curl --silent --user ")
366366
.append(username)
367367
.append(":")
368368
.append(password)
@@ -479,7 +479,7 @@ public void callWebAppAndVerifyLoadBalancing(String webappName, boolean verifyLo
479479
}
480480
testAppUrl.append(webappName).append("/");
481481
// curl cmd to call webapp
482-
StringBuffer curlCmd = new StringBuffer("curl --silent ");
482+
StringBuffer curlCmd = new StringBuffer("curl --noproxy '*' --silent ");
483483
curlCmd
484484
.append(" -H 'host: ")
485485
.append(domainUid)

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -496,7 +496,9 @@ public static String getLegacyAccessToken(Operator operator) throws Exception {
496496
}
497497

498498
public static String getAccessToken(Operator operator) throws Exception {
499-
StringBuffer secretCmd = new StringBuffer("kubectl get serviceaccount weblogic-operator ");
499+
StringBuffer secretCmd =
500+
new StringBuffer(
501+
"kubectl get serviceaccount " + operator.getOperatorMap().get("serviceAccount"));
500502
secretCmd
501503
.append(" -n ")
502504
.append(operator.getOperatorNamespace())
@@ -785,6 +787,21 @@ public static Map<String, Object> createOperatorMap(int number, boolean restEnab
785787
return operatorMap;
786788
}
787789

790+
public static Map<String, Object> createDomainMap(int number) {
791+
Map<String, Object> domainMap = new HashMap<>();
792+
ArrayList<String> targetDomainsNS = new ArrayList<String>();
793+
targetDomainsNS.add("test" + number);
794+
domainMap.put("domainUID", "test" + number);
795+
domainMap.put("namespace", "test" + number);
796+
domainMap.put("configuredManagedServerCount", 4);
797+
domainMap.put("initialManagedServerReplicas", 2);
798+
domainMap.put("exposeAdminT3Channel", true);
799+
domainMap.put("exposeAdminNodePort", true);
800+
domainMap.put("adminNodePort", 30700 + number);
801+
domainMap.put("t3ChannelPort", 30000 + number);
802+
return domainMap;
803+
}
804+
788805
public static String callShellScriptByExecToPod(
789806
String scriptPath, String arguments, String podName, String namespace) throws Exception {
790807

0 commit comments

Comments
 (0)