Skip to content

Commit 9cbfb78

Browse files
sankarpnmarkxnelson
authored andcommitted
Add situational configuration override tests with running domain (#1168)
* update usecases doc for init container tests * adding situational config override after domain startup * fix the create jdbc resource * fix DOMAINUID * fix * make the domain as development * add the test in SitConfigTests.java * fix * fix the target * remove encryption * remove connections on reserve check and change db name * fix the descriptor * added config override usecase * fix the expected condition * add the tests in USECASES.md * restart using patch instead of recreating the domain * fix the patching * Verify the server pods are deleted * add assertion for verifying the startup/shutdown class length * Add documentation * add test for new secrets * Remove the create jdbc resource * Modify the config.xml as well * Modify secret in domainyaml * Add overwrite option * Add configoverridefiles * Fix the destination location * Apply the changes to domain.yaml * FIx * Make the db name a random character * fix
1 parent 898ce07 commit 9cbfb78

File tree

7 files changed

+444
-21
lines changed

7 files changed

+444
-21
lines changed

integration-tests/USECASES.MD

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ Configuration Overrides Usecases
100100
| JDBC Resource Override | Override JDBC connection pool properties; `initialCapacity`, `maxCapacity`, `test-connections-on-reserve`, `connection-harvest-max-count`, `inactive-connection-timeout-seconds`. Override the JDBC driver parameters like data source `URL`, `DB` `user` and `password` using kubernetes secret. The test verifies the overridden functionality datasource `URL`, `user`, `password` by getting the data source connection and running DDL statement it is connected to. |
101101
| 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`. |
102102
| 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. |
103+
| Configuration override with running domain | Override the administration server with Startup and Shutdown class by editing the configmap and recreating the domain CRD. The override is verified by JMX client connecting to the serverConfig MBean tree and the values are checked against the expected values. |
104+
| JDBC Resource Override with running domain | Override non dynamic JDBC connection pool properties; `ignore-in-use-connections`, `login-delay-Seconds`, `connection-cache-type`, `global-transactions-protocol` by editing the configmap and recreating the domain CRD. The test only verifies the expected values against the config tree |
103105

104106
| Session Migration | Use Case |
105107
| --- | --- |
@@ -151,11 +153,12 @@ Configuration Overrides Usecases
151153

152154
| Init Container | Use Case |
153155
| --- | --- |
154-
| Add initContainers to domain | Add a initContainers object to spec level and verify the init containers are created for weblogic server pods prior to starting it and runs to completion and then weblogic pod are started |
155-
| Add initContainers to adminServer | Add a initContainers object to adminServer level and verify the init container is created for administration server weblogic server pod prior to starting it and runs to completion and then weblogic pod is started |
156-
| Add initContainers to Clusters | Add a initContainers object to Clusters level and verify the init containers are created for weblogic server pods prior to starting the clusters and runs to completion and then weblogic pod are started |
157-
| Add initContainers to managedServers | Add a initContainers object to managed server level and verify the init container is created for managed server weblogic server pod prior to starting it and runs to completion and then weblogic pod is started |
158-
| Add bad initContainers to domain | Add a bad initContainers object to domain and verify the init container run fails and no weblogic pod is started |
159-
| Add multiple initContainers to domain | Add multiple initContainers object to domain level and verify all of the init container are run before weblogic server pod are started |
160-
| Add initContainers with different names at different level | Add a multiple initContainers object at domain level and server level and verify all of the init containers are run before weblogic server pods are started |
161-
| Add initContainers with same names at different level | Add a multiple initContainers object at domain level and server level and verify only the server level init containers are run before weblogic server pods are started |
156+
| Add initContainers to domain | Add a initContainers object to spec level and verify the init containers are created for Weblogic server pods prior to starting it and runs to completion and then Weblogic pod are started |
157+
| Add initContainers to adminServer | Add a initContainers object to adminServer level and verify the init container is created for administration server Weblogic server pod prior to starting it and runs to completion and then Weblogic pod is started |
158+
| Add initContainers to Clusters | Add a initContainers object to Clusters level and verify the init containers are created for Weblogic server pods prior to starting the clusters and runs to completion and then Weblogic pod are started |
159+
| Add initContainers to managedServers | Add a initContainers object to managed server level and verify the init container is created for managed server Weblogic server pod prior to starting it and runs to completion and then Weblogic pod is started |
160+
| Add bad initContainers to domain | Add a bad initContainers object to domain and verify the init container run fails and no Weblogic pod is started |
161+
| Add multiple initContainers to domain | Add multiple initContainers object to domain level and verify all of the init container are run before Weblogic server pod are started |
162+
| Add initContainers with different names at different level | Add a multiple initContainers object at domain level and server level and verify all of the init containers are run before Weblogic server pods are started |
163+
| Add initContainers with same names at different level | Add a multiple initContainers object at domain level and server level and verify only the server level init containers are run before Weblogic server pods are started |
164+

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

Lines changed: 229 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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-
54
package oracle.kubernetes.operator;
65

76
import java.io.IOException;
@@ -10,9 +9,10 @@
109
import java.nio.file.Files;
1110
import java.nio.file.Path;
1211
import java.nio.file.Paths;
12+
import java.nio.file.StandardCopyOption;
13+
import java.nio.file.StandardOpenOption;
1314
import java.util.Map;
1415
import java.util.logging.Level;
15-
1616
import oracle.kubernetes.operator.utils.Domain;
1717
import oracle.kubernetes.operator.utils.ExecResult;
1818
import oracle.kubernetes.operator.utils.Operator;
@@ -44,6 +44,8 @@ public class ItSitConfig extends BaseTest {
4444
private static String mysqltmpDir = "";
4545
private static String configOverrideDir = "";
4646
private static String mysqlYamlFile = "";
47+
private static String domainYaml;
48+
private static String JDBC_RES_SCRIPT;
4749

4850
/**
4951
* This method gets called only once before any of the test methods are executed. It does the
@@ -82,6 +84,11 @@ public static void staticPrepare() throws Exception {
8284
// create weblogic domain with configOverrides
8385
domain = createSitConfigDomain();
8486
Assert.assertNotNull(domain);
87+
domainYaml =
88+
BaseTest.getUserProjectsDir()
89+
+ "/weblogic-domains/"
90+
+ domain.getDomainUid()
91+
+ "/domain.yaml";
8592
// copy the jmx test client file the administratioin server weblogic server pod
8693
ADMINPODNAME = domain.getDomainUid() + "-" + domain.getAdminServerName();
8794
TestUtils.copyFileViaCat(
@@ -96,6 +103,7 @@ public static void staticPrepare() throws Exception {
96103
domain.getDomainNs());
97104
KUBE_EXEC_CMD =
98105
"kubectl -n " + domain.getDomainNs() + " exec -it " + ADMINPODNAME + " -- bash -c";
106+
JDBC_RES_SCRIPT = TEST_RES_DIR + "/sitconfig/scripts/create-jdbc-resource.py";
99107
}
100108
}
101109

@@ -217,6 +225,7 @@ public void testCustomSitConfigOverridesForDomain() throws Exception {
217225
boolean testCompletedSuccessfully = false;
218226
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
219227
logTestBegin(testMethod);
228+
transferTests();
220229
ExecResult result =
221230
TestUtils.exec(
222231
KUBE_EXEC_CMD
@@ -247,6 +256,7 @@ public void testCustomSitConfigOverridesForDomainMS() throws Exception {
247256
boolean testCompletedSuccessfully = false;
248257
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
249258
logTestBegin(testMethod);
259+
transferTests();
250260
ExecResult result =
251261
TestUtils.exec(
252262
KUBE_EXEC_CMD
@@ -282,6 +292,7 @@ public void testCustomSitConfigOverridesForJdbc() throws Exception {
282292
boolean testCompletedSuccessfully = false;
283293
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
284294
logTestBegin(testMethod);
295+
transferTests();
285296
ExecResult result =
286297
TestUtils.exec(
287298
KUBE_EXEC_CMD
@@ -315,6 +326,7 @@ public void testCustomSitConfigOverridesForJms() throws Exception {
315326
boolean testCompletedSuccessfully = false;
316327
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
317328
logTestBegin(testMethod);
329+
transferTests();
318330
ExecResult result =
319331
TestUtils.exec(
320332
KUBE_EXEC_CMD
@@ -348,6 +360,44 @@ public void testCustomSitConfigOverridesForWldf() throws Exception {
348360
boolean testCompletedSuccessfully = false;
349361
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
350362
logTestBegin(testMethod);
363+
transferTests();
364+
ExecResult result =
365+
TestUtils.exec(
366+
KUBE_EXEC_CMD
367+
+ " 'sh runSitConfigTests.sh "
368+
+ fqdn
369+
+ " "
370+
+ T3CHANNELPORT
371+
+ " weblogic welcome1 "
372+
+ testMethod
373+
+ "'");
374+
assertResult(result);
375+
testCompletedSuccessfully = true;
376+
logger.log(Level.INFO, "SUCCESS - {0}", testMethod);
377+
}
378+
379+
/**
380+
* Test to verify the configuration override after a domain is up and running. Modifies the
381+
* existing config.xml entries to add startup and shutdown classes verifies those are overridden
382+
* when domain is restarted.
383+
*
384+
* @throws Exception when assertions fail.
385+
*/
386+
@Test
387+
public void testConfigOverrideAfterDomainStartup() throws Exception {
388+
Assume.assumeFalse(QUICKTEST);
389+
boolean testCompletedSuccessfully = false;
390+
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
391+
logTestBegin(testMethod);
392+
// recreate the map with new situational config files
393+
String srcDir = TEST_RES_DIR + "/sitconfig/configoverrides";
394+
String dstDir = configOverrideDir;
395+
Files.copy(
396+
Paths.get(srcDir, "config_1.xml"),
397+
Paths.get(dstDir, "config.xml"),
398+
StandardCopyOption.REPLACE_EXISTING);
399+
recreateCRDWithNewConfigMap();
400+
transferTests();
351401
ExecResult result =
352402
TestUtils.exec(
353403
KUBE_EXEC_CMD
@@ -363,6 +413,183 @@ public void testCustomSitConfigOverridesForWldf() throws Exception {
363413
logger.log(Level.INFO, "SUCCESS - {0}", testMethod);
364414
}
365415

416+
/**
417+
* This test covers the overriding of JDBC system resource after a domain is up and running. It
418+
* creates a datasource , recreates the K8S configmap with updated JDBC descriptor and verifies
419+
* the new overridden values with restart of the WLS pods
420+
*
421+
* @throws Exception when assertions fail.
422+
*/
423+
@Test
424+
public void testOverrideJDBCResourceAfterDomainStart() throws Exception {
425+
Assume.assumeFalse(QUICKTEST);
426+
boolean testCompletedSuccessfully = false;
427+
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
428+
logTestBegin(testMethod);
429+
createJdbcResource();
430+
// recreate the map with new situational config files
431+
String srcDir = TEST_RES_DIR + "/sitconfig/configoverrides";
432+
String dstDir = configOverrideDir;
433+
Files.copy(
434+
Paths.get(srcDir, "jdbc-JdbcTestDataSource-1.xml"),
435+
Paths.get(dstDir, "jdbc-JdbcTestDataSource-1.xml"),
436+
StandardCopyOption.REPLACE_EXISTING);
437+
recreateCRDWithNewConfigMap();
438+
transferTests();
439+
ExecResult result =
440+
TestUtils.exec(
441+
KUBE_EXEC_CMD
442+
+ " 'sh runSitConfigTests.sh "
443+
+ fqdn
444+
+ " "
445+
+ T3CHANNELPORT
446+
+ " weblogic welcome1 "
447+
+ testMethod
448+
+ "'");
449+
assertResult(result);
450+
testCompletedSuccessfully = true;
451+
logger.log(Level.INFO, "SUCCESS - {0}", testMethod);
452+
}
453+
454+
/**
455+
* This test covers the overriding of JDBC system resource with new kubernetes secret name for
456+
* dbusername and dbpassword
457+
*
458+
* @throws Exception when assertions fail.
459+
*/
460+
@Test
461+
public void testOverrideJDBCResourceWithNewSecret() throws Exception {
462+
Assume.assumeFalse(QUICKTEST);
463+
boolean testCompletedSuccessfully = false;
464+
String testMethod = new Object() {}.getClass().getEnclosingMethod().getName();
465+
logTestBegin(testMethod);
466+
// recreate the map with new situational config files
467+
String files[] = {"config.xml", "jdbc-JdbcTestDataSource-0.xml"};
468+
String secretName = "test-secrets-new";
469+
for (String file : files) {
470+
Path path = Paths.get(sitconfigTmpDir, "configoverridefiles", file);
471+
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
472+
content = content.replaceAll("test-secrets", secretName);
473+
if (getWeblogicImageTag().contains(PS3_TAG)) {
474+
content = content.replaceAll(JDBC_DRIVER_NEW, JDBC_DRIVER_OLD);
475+
}
476+
Files.write(
477+
Paths.get(sitconfigTmpDir, "configoverridefiles", file),
478+
content.getBytes(StandardCharsets.UTF_8),
479+
StandardOpenOption.TRUNCATE_EXISTING);
480+
}
481+
String content = new String(Files.readAllBytes(Paths.get(domainYaml)), StandardCharsets.UTF_8);
482+
content = content.replaceAll("test-secrets", secretName);
483+
Files.write(
484+
Paths.get(domainYaml),
485+
content.getBytes(StandardCharsets.UTF_8),
486+
StandardOpenOption.TRUNCATE_EXISTING);
487+
488+
TestUtils.exec("kubectl delete secret " + domain.getDomainUid() + "-test-secrets", true);
489+
createNewSecret(secretName);
490+
TestUtils.exec("kubectl apply -f " + domainYaml, true);
491+
recreateCRDWithNewConfigMap();
492+
transferTests();
493+
ExecResult result =
494+
TestUtils.exec(
495+
KUBE_EXEC_CMD
496+
+ " 'sh runSitConfigTests.sh "
497+
+ fqdn
498+
+ " "
499+
+ T3CHANNELPORT
500+
+ " weblogic welcome1 "
501+
+ testMethod
502+
+ " "
503+
+ JDBC_URL
504+
+ "'");
505+
assertResult(result);
506+
testCompletedSuccessfully = true;
507+
logger.log(Level.INFO, "SUCCESS - {0}", testMethod);
508+
}
509+
510+
/**
511+
* Create a JDBC system resource in domain
512+
*
513+
* @throws Exception JDBC resource creation fails
514+
*/
515+
private void createJdbcResource() throws Exception {
516+
Path path = Paths.get(JDBC_RES_SCRIPT);
517+
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
518+
content = content.replaceAll("JDBC_URL", JDBC_URL);
519+
content = content.replaceAll("DOMAINUID", DOMAINUID);
520+
if (getWeblogicImageTag().contains(PS3_TAG)) {
521+
content = content.replaceAll(JDBC_DRIVER_NEW, JDBC_DRIVER_OLD);
522+
}
523+
Files.write(
524+
Paths.get(sitconfigTmpDir, "create-jdbc-resource.py"),
525+
content.getBytes(StandardCharsets.UTF_8));
526+
TestUtils.copyFileViaCat(
527+
Paths.get(sitconfigTmpDir, "create-jdbc-resource.py").toString(),
528+
"create-jdbc-resource.py",
529+
ADMINPODNAME,
530+
domain.getDomainNs());
531+
TestUtils.exec(KUBE_EXEC_CMD + " 'wlst.sh create-jdbc-resource.py'", true);
532+
}
533+
534+
/**
535+
* Update the configOverrides configmap and restart WLS pods.
536+
*
537+
* @throws Exception when pods restart fail
538+
*/
539+
private void recreateCRDWithNewConfigMap() throws Exception {
540+
int clusterReplicas =
541+
TestUtils.getClusterReplicas(DOMAINUID, domain.getClusterName(), domain.getDomainNs());
542+
543+
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}'";
544+
TestUtils.kubectlpatch(DOMAINUID, domain.getDomainNs(), patchStr);
545+
domain.verifyServerPodsDeleted(clusterReplicas);
546+
547+
String cmd =
548+
"kubectl create configmap "
549+
+ DOMAINUID
550+
+ "-sitconfigcm --from-file="
551+
+ configOverrideDir
552+
+ " -o yaml --dry-run | kubectl replace -f -";
553+
TestUtils.exec(cmd, true);
554+
555+
patchStr = "'{\"spec\":{\"serverStartPolicy\":\"IF_NEEDED\"}}'";
556+
TestUtils.kubectlpatch(DOMAINUID, domain.getDomainNs(), patchStr);
557+
domain.verifyDomainCreated();
558+
}
559+
560+
private void createNewSecret(String secretName) throws Exception {
561+
String cmd =
562+
"kubectl -n "
563+
+ domain.getDomainNs()
564+
+ " create secret generic "
565+
+ domain.getDomainUid()
566+
+ "-"
567+
+ secretName
568+
+ " --from-literal=hostname="
569+
+ TestUtils.getHostName()
570+
+ " --from-literal=dbusername=root"
571+
+ " --from-literal=dbpassword=root123";
572+
TestUtils.exec(cmd, true);
573+
}
574+
575+
/**
576+
* Transfer the tests to run in WLS pods
577+
*
578+
* @throws Exception
579+
*/
580+
private void transferTests() throws Exception {
581+
TestUtils.copyFileViaCat(
582+
TEST_RES_DIR + "sitconfig/java/SitConfigTests.java",
583+
"SitConfigTests.java",
584+
ADMINPODNAME,
585+
domain.getDomainNs());
586+
TestUtils.copyFileViaCat(
587+
TEST_RES_DIR + "sitconfig/scripts/runSitConfigTests.sh",
588+
"runSitConfigTests.sh",
589+
ADMINPODNAME,
590+
domain.getDomainNs());
591+
}
592+
366593
/**
367594
* Verifies the test run result doesn't contain any errors and exit status is 0.
368595
*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<d:domain xmlns:d="http://xmlns.oracle.com/weblogic/domain" xmlns:f="http://xmlns.oracle.com/weblogic/domain-fragment" xmlns:s="http://xmlns.oracle.com/weblogic/situational-config" >
3+
<d:server>
4+
<d:name>admin-server</d:name>
5+
<d:connect-timeout f:combine-mode="add">120</d:connect-timeout>
6+
<d:restart-max f:combine-mode="add">5</d:restart-max>
7+
<d:max-message-size f:combine-mode="add">78787878</d:max-message-size>
8+
<d:server-debug f:combine-mode="add">
9+
<d:debug-server-life-cycle f:combine-mode="add">true</d:debug-server-life-cycle>
10+
<d:debug-jmx-core f:combine-mode="replace">true</d:debug-jmx-core>
11+
</d:server-debug>
12+
<d:network-access-point>
13+
<d:name>T3Channel</d:name>
14+
<d:public-address f:combine-mode="replace">${secret:customsitconfigdomain-test-secrets.hostname}</d:public-address>
15+
</d:network-access-point>
16+
</d:server>
17+
<d:server-template>
18+
<d:name>cluster-1-template</d:name>
19+
<d:max-message-size f:combine-mode="add">77777777</d:max-message-size>
20+
</d:server-template>
21+
<d:shutdown-class f:combine-mode="add">
22+
<d:name>ShutdownClass-0</d:name>
23+
<d:target>admin-server,cluster-1</d:target>
24+
<d:deployment-order>6</d:deployment-order>
25+
<d:class-name>AddedShutdownClassOne</d:class-name>
26+
</d:shutdown-class>
27+
<d:startup-class f:combine-mode="add">
28+
<d:name>StartupClass-0</d:name>
29+
<d:target>admin-server,cluster-1</d:target>
30+
<d:deployment-order>5</d:deployment-order>
31+
<d:class-name>AddedStartupClassOne</d:class-name>
32+
<d:failure-is-fatal>false</d:failure-is-fatal>
33+
<d:load-before-app-deployments>true</d:load-before-app-deployments>
34+
<d:load-before-app-activation>true</d:load-before-app-activation>
35+
</d:startup-class>
36+
</d:domain>

0 commit comments

Comments
 (0)