Skip to content

Commit 94f7c7f

Browse files
sankarpnTom Barnes
andauthored
Add tests for overrideDistributionStrategy (#1768)
* Adding config distribution strategy tests * Adding distribution stratgey test * Adding configmap in patch string * fix configmap name * wip * wip * wip * patch the domain after config change * adding test with distributionstrategy as DYNAMIC * increment the introspect version * Added more test scenarios * Add configuration property reader servlet * Deploy the application right after creating domain * Formatting * change the attribute value * wip * add a restart method * Fix formatting * Add the patching * Fix pod check * Get the pod creation timestamp after restart * move the podready after startdomain * wip * wip * Adding data source related tests * wip * wip * wip * wip * wip * wip * override datasource with new url and user/password * remove open option * add secrets in the configuration * correct the path for secrets * Print jdbc data source attributes * add checks for jdbc ds params * move verify overrides to separate method * Refactor and cleanup code * fix t3channelport for domain * lookup jdbc resource mbean from runtimeservicembean * Fix the attribute values * fix url * Refactor the code * use static imports * Fix shutdown domain * Remove overrides and secrets when restoring domain * Add a flag for debug printing * Move the iintrospector check and pod state checks to separate methods * javadoc cleanup * Use static imports * Fix typo * Move the copy operations in its own try/catch block to prevent build failure * Remove the override verifications since patching fails with invalid values for overridestrategy * don't assert the patching in afterEach * Introduced a dynamic wait until config is updated. Introduced introspector run check during cold restart. * Correct param index * Addressed Bhavani's review comments * Addressing Marina's review comments * liveness probe script 'copy new sit cfg' fix * minor IT test fix - Always --> IfNotPresent * revert minor IT test fix - IfNotPresent goes back to Always, fix missing import * Adding a new cluster as part of override * add a test method for resource restart * Restart datasource * Split the patching into multiple parts * Corrected the patch string, replicas should be a number not a string * Correct debug params * Correct typo * Refactor for new cluster * Create second data source * Fix listServers * Refactor the code to create new cluster through onliine WLST and bring up cluster using introspection * add namespace for NGINX * Fix typo * correct typo * correct syntax error * Fix string concat * Uninstall NGINX * Move the confgi update check after new cluster startup verification * Add ingress controller * Fix nginx * fix * Add all targets for application clusterview * rename vars * Separate adding the new cluster and config overrides into separate usecases * Add a check for new servers * fix imports * Revert changes to ingress creation * javadoc fix * move the for out of try catch * put domainRuntime lookup inside try catch since it is only available in admin server * deploy app to admin server as well * Provide a empty string to delete overridesconfigmap * Remove everything under configuration * move delete secrets to on_restart test * cleanup comments * change the secret name * Disable the failing tests until bug https://jira.oraclecorp.com/jira/browse/OWLS-82977 is fixed * Checking for the default token in default service account to fix the test failures in kind cluster runs * Using a utlity method to increment the introspectVersion * Added a new test scenario where configmap is recreated with new override content and applying the override through introspection * Test fixes made based on the bug fix https://jira.oraclecorp.com/jira/browse/OWLS-82977 * Fix secret name Co-authored-by: Tom Barnes <tom.barnes@oracle.com>
1 parent c9d0697 commit 94f7c7f

File tree

20 files changed

+2132
-38
lines changed

20 files changed

+2132
-38
lines changed

new-integration-tests/src/test/java/oracle/weblogic/domain/Configuration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public class Configuration {
3434
+ " it overrides the Operator's config map data.introspectorJobActiveDeadlineSeconds value.")
3535
private Long introspectorJobActiveDeadlineSeconds;
3636

37+
@ApiModelProperty(
38+
"Determines how updated configuration overrides are distributed to already running WebLogic servers "
39+
+ "following introspection when the domainHomeSourceType is PersistentVolume or Image. Configuration overrides "
40+
+ "are generated during introspection from secrets, the overrideConfigMap field, and WebLogic domain topology. "
41+
+ "Legal values are DYNAMIC (the default) and ON_RESTART. See also introspectVersion.")
42+
private String overrideDistributionStrategy;
43+
3744
@ApiModelProperty("Istio service mesh integration")
3845
private Istio istio;
3946

@@ -80,6 +87,19 @@ public List<String> secrets() {
8087
return secrets;
8188
}
8289

90+
public Configuration overrideDistributionStrategy(String overrideDistributionStrategy) {
91+
this.overrideDistributionStrategy = overrideDistributionStrategy;
92+
return this;
93+
}
94+
95+
public String getOverrideDistributionStrategy() {
96+
return overrideDistributionStrategy;
97+
}
98+
99+
public void setOverrideDistributionStrategy(String overrideDistributionStrategy) {
100+
this.overrideDistributionStrategy = overrideDistributionStrategy;
101+
}
102+
83103
/**
84104
* Adds item to secrets list.
85105
* @param secretsItem Secret

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItConfigDistributionStrategy.java

Lines changed: 1270 additions & 0 deletions
Large diffs are not rendered by default.

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIntrospectVersion.java

Lines changed: 111 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.io.FileOutputStream;
88
import java.io.IOException;
9+
import java.net.http.HttpResponse;
910
import java.nio.file.Files;
1011
import java.nio.file.Path;
1112
import java.nio.file.Paths;
@@ -98,6 +99,7 @@
9899
import static oracle.weblogic.kubernetes.actions.TestActions.createPersistentVolumeClaim;
99100
import static oracle.weblogic.kubernetes.actions.TestActions.getDomainCustomResource;
100101
import static oracle.weblogic.kubernetes.actions.TestActions.getJob;
102+
import static oracle.weblogic.kubernetes.actions.TestActions.getNextIntrospectVersion;
101103
import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog;
102104
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
103105
import static oracle.weblogic.kubernetes.actions.TestActions.getServicePort;
@@ -182,15 +184,6 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
182184
assertNotNull(namespaces.get(2), "Namespace is null");
183185
nginxNamespace = namespaces.get(2);
184186

185-
186-
// build the clusterview application
187-
Path distDir = BuildApplication.buildApplication(Paths.get(APP_DIR, "clusterview"), null, null,
188-
"dist", introDomainNamespace);
189-
assertTrue(Paths.get(distDir.toString(),
190-
"clusterview.war").toFile().exists(),
191-
"Application archive is not available");
192-
clusterViewAppPath = Paths.get(distDir.toString(), "clusterview.war");
193-
194187
// install operator and verify its running in ready state
195188
installAndVerifyOperator(opNamespace, introDomainNamespace);
196189

@@ -212,6 +205,14 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
212205
createOCRRepoSecret(introDomainNamespace);
213206
}
214207

208+
// build the clusterview application
209+
Path distDir = BuildApplication.buildApplication(Paths.get(APP_DIR, "clusterview"), null, null,
210+
"dist", introDomainNamespace);
211+
assertTrue(Paths.get(distDir.toString(),
212+
"clusterview.war").toFile().exists(),
213+
"Application archive is not available");
214+
clusterViewAppPath = Paths.get(distDir.toString(), "clusterview.war");
215+
215216
}
216217

217218

@@ -393,10 +394,11 @@ public void testDomainIntrospectVersionNotRolling() {
393394
executeWLSTScript(configScript, wlstPropertiesFile.toPath(), introDomainNamespace);
394395

395396
// patch the domain to increase the replicas of the cluster and add introspectVersion field
397+
String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, introDomainNamespace));
396398
String patchStr =
397399
"["
398400
+ "{\"op\": \"replace\", \"path\": \"/spec/clusters/0/replicas\", \"value\": 3},"
399-
+ "{\"op\": \"add\", \"path\": \"/spec/introspectVersion\", \"value\": \"2\"}"
401+
+ "{\"op\": \"add\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
400402
+ "]";
401403

402404
logger.info("Updating replicas in cluster {0} using patch string: {1}", clusterName, patchStr);
@@ -486,7 +488,7 @@ public void conditionEvaluated(EvaluatedCondition condition) {
486488
logger.info("Deploying clusterview app {0} to cluster {1}",
487489
clusterViewAppPath, clusterName);
488490
deployUsingWlst(K8S_NODEPORT_HOST, Integer.toString(t3channelNodePort),
489-
ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, clusterName, clusterViewAppPath,
491+
ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, adminServerName + "," + clusterName, clusterViewAppPath,
490492
introDomainNamespace);
491493

492494
//access application in managed servers through NGINX load balancer
@@ -613,6 +615,104 @@ public void testDomainIntrospectVersionRolling() {
613615

614616
}
615617

618+
/**
619+
* Test brings up a new cluster and verifies it can successfully start by doing the following.
620+
* a. Creates new WebLogic static cluster using WLST.
621+
* b. Patch the Domain Resource with cluster
622+
* c. Update the introspectVersion version
623+
* d. Verifies the servers in the new WebLogic cluster comes up without affecting any of the running servers on
624+
* pre-existing WebLogic cluster.
625+
*/
626+
@Order(3)
627+
@Test
628+
@DisplayName("Test new cluster creation on demand using WLST and introspection")
629+
public void testCreateNewCluster() {
630+
631+
final String domainUid = "mydomain";
632+
final String clusterName = "cl2";
633+
634+
final String adminServerName = "admin-server";
635+
final String adminServerPodName = domainUid + "-" + adminServerName;
636+
637+
final String managedServerNameBase = "cl2-ms-";
638+
String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase;
639+
640+
final int replicaCount = 2;
641+
642+
logger.info("Getting node port for default channel");
643+
int adminServerT3Port = getServiceNodePort(introDomainNamespace, adminServerPodName + "-external", "t3channel");
644+
645+
// create a temporary WebLogic WLST property file
646+
File wlstPropertiesFile = assertDoesNotThrow(() -> File.createTempFile("wlst", "properties"),
647+
"Creating WLST properties file failed");
648+
Properties p = new Properties();
649+
p.setProperty("admin_host", K8S_NODEPORT_HOST);
650+
p.setProperty("admin_port", Integer.toString(adminServerT3Port));
651+
p.setProperty("admin_username", ADMIN_USERNAME_DEFAULT);
652+
p.setProperty("admin_password", ADMIN_PASSWORD_DEFAULT);
653+
p.setProperty("test_name", "create_cluster");
654+
p.setProperty("cluster_name", clusterName);
655+
p.setProperty("server_prefix", managedServerNameBase);
656+
p.setProperty("server_count", "3");
657+
assertDoesNotThrow(() -> p.store(new FileOutputStream(wlstPropertiesFile), "wlst properties file"),
658+
"Failed to write the WLST properties to file");
659+
660+
// changet the admin server port to a different value to force pod restart
661+
Path configScript = Paths.get(RESOURCE_DIR, "python-scripts", "introspect_version_script.py");
662+
executeWLSTScript(configScript, wlstPropertiesFile.toPath(), introDomainNamespace);
663+
664+
String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, introDomainNamespace));
665+
666+
logger.info("patch the domain resource with new cluster and introspectVersion");
667+
String patchStr
668+
= "["
669+
+ "{\"op\": \"add\",\"path\": \"/spec/clusters/-\", \"value\": "
670+
+ " {\"clusterName\" : \"" + clusterName + "\", \"replicas\": 2, \"serverStartState\": \"RUNNING\"}"
671+
+ "},"
672+
+ "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
673+
+ "]";
674+
logger.info("Updating domain configuration using patch string: {0}\n", patchStr);
675+
V1Patch patch = new V1Patch(patchStr);
676+
assertTrue(patchDomainCustomResource(domainUid, introDomainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
677+
"Failed to patch domain");
678+
679+
//verify the introspector pod is created and runs
680+
String introspectPodName = domainUid + "-" + "introspect-domain-job";
681+
682+
checkPodExists(introspectPodName, domainUid, introDomainNamespace);
683+
checkPodDoesNotExist(introspectPodName, domainUid, introDomainNamespace);
684+
685+
// verify new cluster managed server services created
686+
for (int i = 1; i <= replicaCount; i++) {
687+
logger.info("Checking managed server service {0} is created in namespace {1}",
688+
managedServerPodNamePrefix + i, introDomainNamespace);
689+
checkServiceExists(managedServerPodNamePrefix + i, introDomainNamespace);
690+
}
691+
692+
// verify new cluster managed server pods are ready
693+
for (int i = 1; i <= replicaCount; i++) {
694+
logger.info("Waiting for managed server pod {0} to be ready in namespace {1}",
695+
managedServerPodNamePrefix + i, introDomainNamespace);
696+
checkPodReady(managedServerPodNamePrefix + i, domainUid, introDomainNamespace);
697+
}
698+
699+
String baseUri = "http://" + K8S_NODEPORT_HOST + ":" + adminServerT3Port + "/clusterview/";
700+
701+
String serverListUri = "ClusterViewServlet?listServers=true";
702+
HttpResponse<String> response = assertDoesNotThrow(() -> OracleHttpClient.get(baseUri + serverListUri, true));
703+
704+
assertEquals(200, response.statusCode(), "Status code not equals to 200");
705+
706+
// verify managed server pods are ready
707+
for (int i = 1; i <= replicaCount; i++) {
708+
logger.info("Checking {0} health", managedServerNameBase + i);
709+
assertTrue(response.body().contains(managedServerNameBase + i + ":HEALTH_OK"),
710+
"Didn't get " + managedServerNameBase + i + ":HEALTH_OK");
711+
}
712+
713+
}
714+
715+
616716
/**
617717
* Create a WebLogic domain on a persistent volume by doing the following.
618718
* Create a configmap containing WLST script and property file.

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItOperatorTwoDomains.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLS_BASE_IMAGE_NAME;
6868
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLS_BASE_IMAGE_TAG;
6969
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
70-
import static oracle.weblogic.kubernetes.actions.TestActions.restartDomain;
7170
import static oracle.weblogic.kubernetes.actions.TestActions.shutdownDomain;
71+
import static oracle.weblogic.kubernetes.actions.TestActions.startDomain;
7272
import static oracle.weblogic.kubernetes.assertions.TestAssertions.adminNodePortAccessible;
7373
import static oracle.weblogic.kubernetes.assertions.TestAssertions.podStateNotChanged;
7474
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodDoesNotExist;
@@ -528,19 +528,19 @@ private void restartDomain1AndVerifyNoImpactOnDomain2() {
528528
verifyDomain2NotChanged();
529529

530530
// restart domain1
531-
logger.info("Restarting domain1");
532-
assertTrue(restartDomain(domain1Uid, domain1Namespace),
533-
String.format("restart domain %s in namespace %s failed", domain1Uid, domain1Namespace));
531+
logger.info("Starting domain1");
532+
assertTrue(startDomain(domain1Uid, domain1Namespace),
533+
String.format("start domain %s in namespace %s failed", domain1Uid, domain1Namespace));
534534

535535
// verify domain1 is restarted
536536
// check domain1 admin server pod is ready, also check admin service exists in the domain1 namespace
537-
logger.info("Checking admin server pod in domain1 was restarted");
537+
logger.info("Checking admin server pod in domain1 was started");
538538
checkPodReadyAndServiceExists(domain1AdminServerPodName, domain1Uid, domain1Namespace);
539539
checkPodRestarted(domain1Uid, domain1Namespace, domain1AdminServerPodName,
540540
domainAdminPodOriginalTimestamps.get(0));
541541

542542
// check managed server pods in domain1
543-
logger.info("Checking managed server pods in domain1 were restarted");
543+
logger.info("Checking managed server pods in domain1 were started");
544544
for (int i = 1; i <= replicasAfterScale; i++) {
545545
String domain1ManagedServerPodName = domain1Uid + "-" + MANAGED_SERVER_NAME_BASE + i;
546546
checkPodReadyAndServiceExists(domain1ManagedServerPodName, domain1Uid, domain1Namespace);
@@ -549,7 +549,7 @@ private void restartDomain1AndVerifyNoImpactOnDomain2() {
549549
}
550550

551551
// verify domain2 was not changed after domain1 was restarted
552-
logger.info("Verifying that domain2 was not changed after domain1 was restarted");
552+
logger.info("Verifying that domain2 was not changed after domain1 was started");
553553
verifyDomain2NotChanged();
554554
}
555555

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/TestConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,7 @@ public interface TestConstants {
138138
// istio constants
139139
public static final String ISTIO_VERSION = "1.5.4";
140140

141+
//MySQL database constants
142+
public static final String MYSQL_VERSION = "5.6";
143+
141144
}

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ public static boolean shutdownDomain(String domainUid, String namespace) {
177177
* @param namespace name of namespace
178178
* @return true on success, false otherwise
179179
*/
180-
public static boolean restartDomain(String domainUid, String namespace) {
181-
return Domain.restart(domainUid, namespace);
180+
public static boolean startDomain(String domainUid, String namespace) {
181+
return Domain.start(domainUid, namespace);
182182
}
183183

184184
/**
@@ -222,6 +222,28 @@ public static boolean patchDomainResourceWithNewIntrospectVersion(
222222
return Domain.patchDomainResourceWithNewIntrospectVersion(domainUid, namespace);
223223
}
224224

225+
/**
226+
* Get next introspectVersion for a given domain.
227+
*
228+
* @param domainUid domain id
229+
* @param namespace namespace in which the domain resource exists
230+
* @return String containing next introspectVersion
231+
* @throws ApiException when getting domain resource fails
232+
*/
233+
public static String getNextIntrospectVersion(String domainUid, String namespace) throws ApiException {
234+
LoggingFacade logger = getLogger();
235+
oracle.weblogic.domain.Domain domain = Domain.getDomainCustomResource(domainUid, namespace);
236+
String introspectVersion = domain.getSpec().getIntrospectVersion();
237+
if (null != introspectVersion) {
238+
logger.info("current introspectVersion: {0}", introspectVersion);
239+
introspectVersion = Integer.toString(Integer.valueOf(introspectVersion) + 1);
240+
logger.info("modified introspectVersion: {0}", introspectVersion);
241+
} else {
242+
introspectVersion = Integer.toString(1);
243+
}
244+
return introspectVersion;
245+
}
246+
225247
/**
226248
* Scale the cluster of the domain in the specified namespace by patching the domain resource.
227249
*

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/Domain.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static boolean shutdown(String domainUid, String namespace) {
8686
// change the /spec/serverStartPolicy to NEVER to shut down all servers in the domain
8787
// create patch string to shut down the domain
8888
StringBuffer patchStr = new StringBuffer("[{")
89-
.append("\"op\": \"add\", ")
89+
.append("\"op\": \"replace\", ")
9090
.append("\"path\": \"/spec/serverStartPolicy\", ")
9191
.append("\"value\": \"NEVER\"")
9292
.append("}]");
@@ -100,13 +100,13 @@ public static boolean shutdown(String domainUid, String namespace) {
100100
}
101101

102102
/**
103-
* Restart a domain in the specified namespace.
103+
* Start domain in the specified namespace.
104104
*
105105
* @param domainUid the domain to restart
106106
* @param namespace the namespace in which the domain exists
107107
* @return true if patching domain resource succeeded, false otherwise
108108
*/
109-
public static boolean restart(String domainUid, String namespace) {
109+
public static boolean start(String domainUid, String namespace) {
110110
LoggingFacade logger = getLogger();
111111
// change the /spec/serverStartPolicy to IF_NEEDED to start all servers in the domain
112112
// create patch string to start the domain

0 commit comments

Comments
 (0)