Skip to content

Commit 5200fef

Browse files
authored
Backport to release/3.4: Add Functional Regression tests for OWLS-106473, OWLS-106637 (#4068)
* add Functional Regression tests for OWLS-106473, OWLS-106637
1 parent 78a60a2 commit 5200fef

11 files changed

+987
-18
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWDTModelNoServer.java

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

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonMiiTestUtils.java

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes.utils;
@@ -237,6 +237,77 @@ public static Domain createMiiDomainAndVerify(
237237
return domain;
238238
}
239239

240+
/**
241+
* Create a basic Kubernetes domain resource and verify the domain is created.
242+
*
243+
* @param domainNamespace Kubernetes namespace that the pod is running in
244+
* @param domainUid identifier of the domain
245+
* @param imageName name of the image including its tag
246+
* @param replicaCount number of managed servers to start
247+
* @param clusterName names of cluster
248+
* @param setDataHome whether to set dataHome in the domain spec
249+
* @param dataHome dataHome override in the domain spec
250+
* @return DomainResource
251+
*/
252+
public static Domain createMiiDomain(
253+
String domainNamespace,
254+
String domainUid,
255+
String imageName,
256+
int replicaCount,
257+
String clusterName,
258+
boolean setDataHome,
259+
String dataHome) {
260+
261+
LoggingFacade logger = getLogger();
262+
// this secret is used only for non-kind cluster
263+
logger.info("Create the repo secret {0} to pull the image", TEST_IMAGES_REPO_SECRET_NAME);
264+
assertDoesNotThrow(() -> createTestRepoSecret(domainNamespace),
265+
String.format("createSecret failed for %s", TEST_IMAGES_REPO_SECRET_NAME));
266+
267+
// create secret for admin credentials
268+
logger.info("Create secret for admin credentials");
269+
String adminSecretName = "weblogic-credentials";
270+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(
271+
adminSecretName,
272+
domainNamespace,
273+
ADMIN_USERNAME_DEFAULT,
274+
ADMIN_PASSWORD_DEFAULT),
275+
String.format("createSecret failed for %s", adminSecretName));
276+
277+
// create encryption secret
278+
logger.info("Create encryption secret");
279+
String encryptionSecretName = "encryptionsecret";
280+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(
281+
encryptionSecretName,
282+
domainNamespace,
283+
"weblogicenc",
284+
"weblogicenc"),
285+
String.format("createSecret failed for %s", encryptionSecretName));
286+
287+
// create the domain custom resource
288+
logger.info("Create domain resource {0} object in namespace {1} and verify that it is created",
289+
domainUid, domainNamespace);
290+
Domain domain = createDomainResource(domainUid,
291+
domainNamespace,
292+
imageName,
293+
adminSecretName,
294+
new String[]{TEST_IMAGES_REPO_SECRET_NAME},
295+
encryptionSecretName,
296+
replicaCount,
297+
clusterName);
298+
299+
// set the dataHome in the domain spec
300+
if (setDataHome) {
301+
DomainSpec domainSpec = domain.getSpec();
302+
domainSpec.dataHome(dataHome);
303+
domain.spec(domainSpec);
304+
}
305+
306+
createDomainAndVerify(domain, domainNamespace);
307+
308+
return domain;
309+
}
310+
240311
/**
241312
* Create a domain object for a Kubernetes domain custom resource using the basic model-in-image
242313
* image.
@@ -295,15 +366,18 @@ public static Domain createDomainResource(
295366
.addChannelsItem(new oracle.weblogic.domain.Channel()
296367
.channelName("default")
297368
.nodePort(0))))
298-
.addClustersItem(new oracle.weblogic.domain.Cluster()
299-
.clusterName(clusterName)
300-
.replicas(replicaCount)
301-
.serverStartState("RUNNING"))
302369
.configuration(new oracle.weblogic.domain.Configuration()
303370
.model(new oracle.weblogic.domain.Model()
304371
.domainType("WLS")
305372
.runtimeEncryptionSecret(encryptionSecretName))
306373
.introspectorJobActiveDeadlineSeconds(300L)));
374+
375+
if (clusterName != null && !clusterName.isEmpty()) {
376+
domain.spec().addClustersItem(new oracle.weblogic.domain.Cluster()
377+
.clusterName(clusterName)
378+
.replicas(replicaCount)
379+
.serverStartState("RUNNING"));
380+
}
307381
domain.spec().setImagePullSecrets(secrets);
308382

309383
setPodAntiAffinity(domain);

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonTestUtils.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes.utils;
@@ -824,6 +824,32 @@ public static boolean checkSystemResourceConfig(String adminSvcExtHost, int node
824824
.executeAndVerify(expectedValue);
825825
}
826826

827+
/**
828+
* Check the system resource configuration using REST API.
829+
* @param adminSvcExtHost Used only in OKD env - this is the route host created for AS external service
830+
* @param nodePort admin node port
831+
* @param expectedValue expected value returned in the REST call
832+
* @return true if the REST API results matches expected status code
833+
*/
834+
public static boolean checkSystemResourceDomainConfig(String adminSvcExtHost, int nodePort,
835+
String expectedValue) {
836+
final LoggingFacade logger = getLogger();
837+
838+
String hostAndPort = (OKD) ? adminSvcExtHost : K8S_NODEPORT_HOST + ":" + nodePort;
839+
logger.info("hostAndPort = {0} ", hostAndPort);
840+
841+
StringBuffer curlString = new StringBuffer("curl --user ");
842+
curlString.append(ADMIN_USERNAME_DEFAULT + ":" + ADMIN_PASSWORD_DEFAULT)
843+
.append(" http://" + hostAndPort)
844+
.append("/management/weblogic/latest/domainConfig/");
845+
846+
logger.info("checkSystemResource: curl command {0}", new String(curlString));
847+
return Command
848+
.withParams(new CommandParams()
849+
.command(curlString.toString()))
850+
.executeAndVerify(expectedValue);
851+
}
852+
827853
/**
828854
* Check the system resource runtime using REST API.
829855
* @param adminSvcExtHost Used only in OKD env - this is the route host created for AS external service

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/DomainUtils.java

Lines changed: 192 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2021, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes.utils;
@@ -90,15 +90,20 @@
9090
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainDoesNotExist;
9191
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists;
9292
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainStatusReasonMatches;
93+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.pvExists;
94+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.pvcExists;
9395
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
9496
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
9597
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getUniqueName;
98+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
9699
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withStandardRetryPolicy;
97100
import static oracle.weblogic.kubernetes.utils.ImageUtils.createBaseRepoSecret;
98101
import static oracle.weblogic.kubernetes.utils.ImageUtils.createImageAndVerify;
99102
import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret;
100103
import static oracle.weblogic.kubernetes.utils.ImageUtils.dockerLoginAndPushImageToRegistry;
101104
import static oracle.weblogic.kubernetes.utils.JobUtils.createJobAndWaitUntilComplete;
105+
import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPV;
106+
import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPVC;
102107
import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPVPVCAndVerify;
103108
import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createfixPVCOwnerContainer;
104109
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodDoesNotExist;
@@ -166,25 +171,46 @@ public static void createDomainAndVerify(Domain domain,
166171
public static void createDomainAndVerify(String domainUid, Domain domain,
167172
String domainNamespace, String adminServerPodName,
168173
String managedServerPodNamePrefix, int replicaCount) {
174+
createDomainAndVerify(domainUid, domain, domainNamespace, adminServerPodName, managedServerPodNamePrefix,
175+
replicaCount, true);
176+
}
177+
178+
/**
179+
* Create a domain in the specified namespace, wait up to five minutes until the domain exists and
180+
* verify the servers are running.
181+
*
182+
* @param domainUid domain
183+
* @param domain the oracle.weblogic.domain.Domain object to create domain custom resource
184+
* @param domainNamespace namespace in which the domain will be created
185+
* @param adminServerPodName admin server pod name
186+
* @param managedServerPodNamePrefix managed server pod prefix
187+
* @param replicaCount replica count
188+
* @param verifyServerPods whether to verify server pods of the domain
189+
*/
190+
public static void createDomainAndVerify(String domainUid, Domain domain,
191+
String domainNamespace, String adminServerPodName,
192+
String managedServerPodNamePrefix, int replicaCount,
193+
boolean verifyServerPods) {
169194
LoggingFacade logger = getLogger();
170195

171196
// create domain and verify
172197
createDomainAndVerify(domain, domainNamespace);
173198

174-
// check that admin service/pod exists in the domain namespace
175-
logger.info("Checking that admin service/pod {0} exists in namespace {1}",
176-
adminServerPodName, domainNamespace);
177-
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);
199+
if (verifyServerPods) {
200+
// check that admin service/pod exists in the domain namespace
201+
logger.info("Checking that admin service/pod {0} exists in namespace {1}",
202+
adminServerPodName, domainNamespace);
203+
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);
178204

179-
for (int i = 1; i <= replicaCount; i++) {
180-
String managedServerPodName = managedServerPodNamePrefix + i;
205+
for (int i = 1; i <= replicaCount; i++) {
206+
String managedServerPodName = managedServerPodNamePrefix + i;
181207

182-
// check that ms service/pod exists in the domain namespace
183-
logger.info("Checking that clustered ms service/pod {0} exists in namespace {1}",
184-
managedServerPodName, domainNamespace);
185-
checkPodReadyAndServiceExists(managedServerPodName, domainUid, domainNamespace);
208+
// check that ms service/pod exists in the domain namespace
209+
logger.info("Checking that clustered ms service/pod {0} exists in namespace {1}",
210+
managedServerPodName, domainNamespace);
211+
checkPodReadyAndServiceExists(managedServerPodName, domainUid, domainNamespace);
212+
}
186213
}
187-
188214
}
189215

190216
/**
@@ -328,6 +354,109 @@ public static Domain createDomainOnPvUsingWdt(String domainUid,
328354
return domain;
329355
}
330356

357+
/**
358+
* Create a domain in PV using WDT.
359+
*
360+
* @param domainUid uid of the domain
361+
* @param domainNamespace namespace in which the domain will be created
362+
* @param wlSecretName WLS secret name
363+
* @param clusterName WLS domain cluster name
364+
* @param replicaCount domain replica count
365+
* @param testClassName the test class name calling this method
366+
* @param wdtModelFile WDT model file to create the domain
367+
* @param verifyServerPods whether to verify the server pods
368+
* @return oracle.weblogic.domain.Domain objects
369+
*/
370+
public static Domain createDomainOnPvUsingWdt(String domainUid,
371+
String domainNamespace,
372+
String wlSecretName,
373+
String clusterName,
374+
int replicaCount,
375+
String testClassName,
376+
String wdtModelFile,
377+
boolean verifyServerPods) {
378+
379+
int t3ChannelPort = getNextFreePort();
380+
381+
final String pvName = getUniqueName(domainUid + "-pv-"); // name of the persistent volume
382+
final String pvcName = getUniqueName(domainUid + "-pvc-"); // name of the persistent volume claim
383+
384+
// create pull secrets for WebLogic image when running in non Kind Kubernetes cluster
385+
// this secret is used only for non-kind cluster
386+
createBaseRepoSecret(domainNamespace);
387+
388+
// create WebLogic domain credential secret
389+
createSecretWithUsernamePassword(wlSecretName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);
390+
391+
// create persistent volume and persistent volume claim for domain
392+
// these resources should be labeled with domainUid for cleanup after testing
393+
394+
createPV(pvName, domainUid, testClassName);
395+
createPVC(pvName, pvcName, domainUid, domainNamespace);
396+
397+
String labelSelector = String.format("weblogic.domainUid in (%s)", domainUid);
398+
LoggingFacade logger = getLogger();
399+
// check the persistent volume and persistent volume claim exist
400+
testUntil(
401+
assertDoesNotThrow(() -> pvExists(pvName, labelSelector),
402+
String.format("pvExists failed with ApiException when checking pv %s", pvName)),
403+
logger,
404+
"persistent volume {0} exists",
405+
pvName);
406+
407+
testUntil(
408+
assertDoesNotThrow(() -> pvcExists(pvcName, domainNamespace),
409+
String.format("pvcExists failed with ApiException when checking pvc %s in namespace %s",
410+
pvcName, domainNamespace)),
411+
logger,
412+
"persistent volume claim {0} exists in namespace {1}",
413+
pvcName,
414+
domainNamespace);
415+
416+
417+
// create a temporary WebLogic domain property file as a input for WDT model file
418+
File domainPropertiesFile = assertDoesNotThrow(() -> createTempFile("domainonpv" + domainUid, "properties"),
419+
"Failed to create domain properties file");
420+
421+
Properties p = new Properties();
422+
p.setProperty("adminUsername", ADMIN_USERNAME_DEFAULT);
423+
p.setProperty("adminPassword", ADMIN_PASSWORD_DEFAULT);
424+
p.setProperty("domainName", domainUid);
425+
p.setProperty("adminServerName", ADMIN_SERVER_NAME_BASE);
426+
p.setProperty("productionModeEnabled", "true");
427+
p.setProperty("clusterName", clusterName);
428+
p.setProperty("configuredManagedServerCount", "4");
429+
p.setProperty("managedServerNameBase", MANAGED_SERVER_NAME_BASE);
430+
p.setProperty("t3ChannelPort", Integer.toString(t3ChannelPort));
431+
p.setProperty("t3PublicAddress", K8S_NODEPORT_HOST);
432+
p.setProperty("managedServerPort", "8001");
433+
p.setProperty("adminServerSslPort", "7002");
434+
assertDoesNotThrow(() ->
435+
p.store(new FileOutputStream(domainPropertiesFile), "WDT properties file"),
436+
"Failed to write domain properties file");
437+
438+
// shell script to download WDT and run the WDT createDomain script
439+
Path wdtScript = get(RESOURCE_DIR, "bash-scripts", "setup_wdt.sh");
440+
441+
// create configmap and domain in persistent volume using WDT
442+
runCreateDomainOnPVJobUsingWdt(wdtScript, get(RESOURCE_DIR, "wdt-models", wdtModelFile),
443+
domainPropertiesFile.toPath(),
444+
domainUid, pvName, pvcName, domainNamespace, testClassName);
445+
446+
Domain domain = createDomainResourceForDomainOnPV(domainUid, domainNamespace, wlSecretName, pvName, pvcName,
447+
clusterName, replicaCount);
448+
449+
// Verify the domain custom resource is created.
450+
// Also verify the admin server pod and managed server pods are up and running.
451+
if (verifyServerPods) {
452+
createDomainAndVerify(domainUid, domain, domainNamespace, domainUid + "-" + ADMIN_SERVER_NAME_BASE,
453+
domainUid + "-" + MANAGED_SERVER_NAME_BASE, replicaCount);
454+
} else {
455+
createDomainAndVerify(domain, domainNamespace);
456+
}
457+
return domain;
458+
}
459+
331460
/**
332461
* Create domain with domain-on-pv type and verify the domain is created.
333462
* Also verify the admin server pod and managed server pods are up and running.
@@ -642,6 +771,57 @@ public static Domain createAndVerifyDomainInImageUsingWdt(String domainUid,
642771
clusterName, replicaCount);
643772
}
644773

774+
/**
775+
* Create a WebLogic domain in image using WDT.
776+
*
777+
* @param domainUid domain uid
778+
* @param domainNamespace namespace in which the domain to be created
779+
* @param wdtModelFileForDomainInImage WDT model file used to create domain image
780+
* @param appSrcDirList list of the app src in WDT model file
781+
* @param propertyFiles list of property files
782+
* @param wlSecretName wls admin secret name
783+
* @param clusterName cluster name
784+
* @param replicaCount replica count of the cluster
785+
* @return oracle.weblogic.domain.Domain object
786+
*/
787+
public static Domain createDomainInImageUsingWdt(String domainUid,
788+
String domainNamespace,
789+
String wdtModelFileForDomainInImage,
790+
List<String> appSrcDirList,
791+
List<String> propertyFiles,
792+
String wlSecretName,
793+
String clusterName,
794+
int replicaCount) {
795+
796+
// create secret for admin credentials
797+
getLogger().info("Create secret for admin credentials");
798+
createSecretWithUsernamePassword(wlSecretName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);
799+
800+
// create image with model files
801+
getLogger().info("Creating image with model file and verify");
802+
String domainInImageWithWDTImage = createImageAndVerify("domaininimage-wdtimage",
803+
Collections.singletonList(MODEL_DIR + "/" + wdtModelFileForDomainInImage), appSrcDirList,
804+
propertyFiles,
805+
WEBLOGIC_IMAGE_NAME, WEBLOGIC_IMAGE_TAG, WLS_DOMAIN_TYPE, false,
806+
domainUid, false);
807+
808+
// repo login and push image to registry if necessary
809+
dockerLoginAndPushImageToRegistry(domainInImageWithWDTImage);
810+
811+
// Create the repo secret to pull the image
812+
// this secret is used only for non-kind cluster
813+
createTestRepoSecret(domainNamespace);
814+
815+
// create the domain custom resource
816+
Domain domain = createDomainResourceForDomainInImage(domainUid, domainNamespace, domainInImageWithWDTImage,
817+
wlSecretName, clusterName, replicaCount);
818+
819+
// create domain and verify
820+
createDomainAndVerify(domain, domainNamespace);
821+
822+
return domain;
823+
}
824+
645825
/**
646826
* Create domain resource with domain-in-image type.
647827
*

0 commit comments

Comments
 (0)