Skip to content

Commit 469033c

Browse files
authored
Integration Test: Add error path testing for Auxiliary Image feature (#2457)
* Add error path testing for Auxiliary Image feature
1 parent e44f4eb commit 469033c

File tree

7 files changed

+576
-49
lines changed

7 files changed

+576
-49
lines changed

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE;
4242
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
4343
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION;
44-
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_VERSION;
4544
import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE;
4645
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
4746
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
@@ -58,12 +57,12 @@
5857
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
5958
import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithRestApi;
6059
import static oracle.weblogic.kubernetes.actions.TestActions.uninstallOperator;
61-
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainDoesNotExist;
6260
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodDoesNotExist;
6361
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
6462
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createDomainAndVerify;
6563
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createOcirRepoSecret;
6664
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword;
65+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.deleteDomainResource;
6766
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyOperator;
6867
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.scaleAndVerifyCluster;
6968
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.setPodAntiAffinity;
@@ -382,23 +381,6 @@ private void checkUpgradeFailedToAddNSManagedByAnotherOperator() {
382381
+ " managed by other operator");
383382
}
384383

385-
private void deleteDomainResource(String domainNS, String domainUid) {
386-
//clean up domain resources in namespace and set namespace to label , managed by operator
387-
logger.info("deleting domain custom resource {0}", domainUid);
388-
assertTrue(deleteDomainCustomResource(domainUid, domainNS));
389-
390-
// wait until domain was deleted
391-
withStandardRetryPolicy
392-
.conditionEvaluationListener(
393-
condition -> logger.info("Waiting for domain {0} to be deleted in namespace {1} "
394-
+ "(elapsed time {2}ms, remaining time {3}ms)",
395-
domainUid,
396-
domainNS,
397-
condition.getElapsedTimeInMS(),
398-
condition.getRemainingTimeInMS()))
399-
.until(domainDoesNotExist(domainUid, DOMAIN_VERSION, domainNS));
400-
}
401-
402384
private HelmParams installAndVerifyOperatorCanManageDomainBySelector(Map<String,String> managedDomains,
403385
Map<String,String> unmanagedDomains,
404386
String selector, String selectorValue,

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

Lines changed: 387 additions & 2 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterRoleBindingExists;
120120
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterRoleExists;
121121
import static oracle.weblogic.kubernetes.utils.CommonPatchTestUtils.patchDomainResource;
122+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodLogContainsString;
122123
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReady;
123124
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
124125
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createDomainAndVerify;
@@ -306,7 +307,7 @@ public void testOperatorLogSevereMsg() {
306307
createMiiDomainNegative("miidomainnegative", miiDomainNegativeNamespace);
307308
String operatorPodName =
308309
assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace));
309-
waitForPodLogContainsString(opNamespace, operatorPodName,
310+
checkPodLogContainsString(opNamespace, operatorPodName,
310311
"Domain miidomainnegative is not valid: RuntimeEncryption secret '" + encryptionSecretName
311312
+ "' not found in namespace '" + miiDomainNegativeNamespace + "'");
312313
}
@@ -1545,31 +1546,6 @@ private void waitForFileExistsInPod(String namespace, String podName, String fil
15451546
"fileExistsInPod failed with IOException, ApiException or InterruptedException"));
15461547
}
15471548

1548-
private Callable<Boolean> podLogContainsString(String namespace, String podName, String expectedString) {
1549-
return () -> {
1550-
logger.info("pod name: {0}", podName);
1551-
String podLog = getPodLog(podName, namespace);
1552-
logger.info("pod log: {0}", podLog);
1553-
return podLog.contains(expectedString);
1554-
};
1555-
}
1556-
1557-
private void waitForPodLogContainsString(String namespace, String podName, String expectedString) {
1558-
1559-
logger.info("Wait for string {0} existing in pod {1} in namespace {2}", expectedString, podName, namespace);
1560-
withStandardRetryPolicy
1561-
.conditionEvaluationListener(
1562-
condition -> logger.info("Waiting for string {0} existing in pod {1} in namespace {2} "
1563-
+ "(elapsed time {3}ms, remaining time {4}ms)",
1564-
expectedString,
1565-
podName,
1566-
namespace,
1567-
condition.getElapsedTimeInMS(),
1568-
condition.getRemainingTimeInMS()))
1569-
.until(assertDoesNotThrow(() -> podLogContainsString(namespace, podName, expectedString),
1570-
"podLogContainsString failed with IOException, ApiException or InterruptedException"));
1571-
}
1572-
15731549
/**
15741550
* Negative test case for creating a model-in-image domain without encryption secret created.
15751551
* The admin server service/pod will not be created.

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,51 @@ public static Domain createDomainResource(
299299
return domainCR;
300300
}
301301

302+
/**
303+
* Create a domain object for a Kubernetes domain custom resource using the basic WLS image and auxiliary image.
304+
*
305+
* @param domainResourceName name of the domain resource
306+
* @param domNamespace Kubernetes namespace that the domain is hosted
307+
* @param baseImageName name of the base image to use
308+
* @param adminSecretName name of the new WebLogic admin credentials secret
309+
* @param repoSecretName name of the secret for pulling the WebLogic image
310+
* @param encryptionSecretName name of the secret used to encrypt the models
311+
* @param replicaCount number of managed servers to start
312+
* @param clusterName name of the cluster to add in domain
313+
* @param auxiliaryImageVolumes list of AuxiliaryImageVolumes
314+
* @param auxiliaryImages list of AuxiliaryImages
315+
* @return domain object of the domain resource
316+
*/
317+
public static Domain createDomainResourceWithAuxiliaryImage(
318+
String domainResourceName,
319+
String domNamespace,
320+
String baseImageName,
321+
String adminSecretName,
322+
String repoSecretName,
323+
String encryptionSecretName,
324+
int replicaCount,
325+
String clusterName,
326+
List<AuxiliaryImageVolume> auxiliaryImageVolumes,
327+
List<AuxiliaryImage> auxiliaryImages) {
328+
329+
Domain domainCR = CommonMiiTestUtils.createDomainResource(domainResourceName, domNamespace,
330+
baseImageName, adminSecretName, repoSecretName,
331+
encryptionSecretName, replicaCount, clusterName);
332+
333+
for (AuxiliaryImageVolume auxiliaryImageVolume : auxiliaryImageVolumes) {
334+
domainCR.spec().addAuxiliaryImageVolumesItem(auxiliaryImageVolume);
335+
domainCR.spec().configuration().model()
336+
.withModelHome(auxiliaryImageVolume.getMountPath() + "/models")
337+
.withWdtInstallHome(auxiliaryImageVolume.getMountPath() + "/weblogic-deploy");
338+
}
339+
340+
for (AuxiliaryImage auxiliaryImage : auxiliaryImages) {
341+
domainCR.spec().serverPod().addAuxiliaryImagesItem(auxiliaryImage);
342+
}
343+
344+
return domainCR;
345+
}
346+
302347
/**
303348
* Create a domain object for a Kubernetes domain custom resource using the basic model-in-image
304349
* image.

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

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.kubernetes.client.custom.Quantity;
2929
import io.kubernetes.client.custom.V1Patch;
3030
import io.kubernetes.client.openapi.ApiException;
31+
import io.kubernetes.client.openapi.models.CoreV1Event;
3132
import io.kubernetes.client.openapi.models.NetworkingV1beta1HTTPIngressPath;
3233
import io.kubernetes.client.openapi.models.NetworkingV1beta1HTTPIngressRuleValue;
3334
import io.kubernetes.client.openapi.models.NetworkingV1beta1IngressBackend;
@@ -185,12 +186,14 @@
185186
import static oracle.weblogic.kubernetes.actions.TestActions.createService;
186187
import static oracle.weblogic.kubernetes.actions.TestActions.createServiceAccount;
187188
import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams;
189+
import static oracle.weblogic.kubernetes.actions.TestActions.deleteDomainCustomResource;
188190
import static oracle.weblogic.kubernetes.actions.TestActions.dockerLogin;
189191
import static oracle.weblogic.kubernetes.actions.TestActions.dockerPush;
190192
import static oracle.weblogic.kubernetes.actions.TestActions.getJob;
191193
import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorImageName;
192194
import static oracle.weblogic.kubernetes.actions.TestActions.getPersistentVolume;
193195
import static oracle.weblogic.kubernetes.actions.TestActions.getPersistentVolumeClaim;
196+
import static oracle.weblogic.kubernetes.actions.TestActions.getPod;
194197
import static oracle.weblogic.kubernetes.actions.TestActions.getPodCreationTimestamp;
195198
import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog;
196199
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
@@ -220,6 +223,7 @@
220223
import static oracle.weblogic.kubernetes.assertions.TestAssertions.credentialsNotValid;
221224
import static oracle.weblogic.kubernetes.assertions.TestAssertions.credentialsValid;
222225
import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist;
226+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainDoesNotExist;
223227
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists;
224228
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainStatusReasonMatches;
225229
import static oracle.weblogic.kubernetes.assertions.TestAssertions.isApacheReady;
@@ -247,6 +251,8 @@
247251
import static oracle.weblogic.kubernetes.assertions.TestAssertions.serviceExists;
248252
import static oracle.weblogic.kubernetes.utils.ExecCommand.exec;
249253
import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory;
254+
import static oracle.weblogic.kubernetes.utils.K8sEvents.checkDomainEvent;
255+
import static oracle.weblogic.kubernetes.utils.K8sEvents.getEvent;
250256
import static oracle.weblogic.kubernetes.utils.TestUtils.callWebAppAndCheckForServerNameInResponse;
251257
import static oracle.weblogic.kubernetes.utils.TestUtils.callWebAppAndWaitTillReady;
252258
import static oracle.weblogic.kubernetes.utils.TestUtils.getNextFreePort;
@@ -3866,6 +3872,27 @@ public static String getIntrospectJobName(String domainUid) {
38663872
return domainUid + TestConstants.DEFAULT_INTROSPECTOR_JOB_NAME_SUFFIX;
38673873
}
38683874

3875+
/**
3876+
* Get the introspector pod name.
3877+
* @param domainUid domain uid of the domain
3878+
* @param domainNamespace domain namespace in which introspector runs
3879+
* @return the introspector pod name
3880+
* @throws ApiException if Kubernetes API calls fail
3881+
*/
3882+
public static String getIntrospectorPodName(String domainUid, String domainNamespace) throws ApiException {
3883+
checkPodExists(getIntrospectJobName(domainUid), domainUid, domainNamespace);
3884+
3885+
String labelSelector = String.format("weblogic.domainUID in (%s)", domainUid);
3886+
3887+
V1Pod introspectorPod = getPod(domainNamespace, labelSelector, getIntrospectJobName(domainUid));
3888+
3889+
if (introspectorPod != null && introspectorPod.getMetadata() != null) {
3890+
return introspectorPod.getMetadata().getName();
3891+
} else {
3892+
return "";
3893+
}
3894+
}
3895+
38693896
/**
38703897
* Set the inter-pod anti-affinity for the domain custom resource
38713898
* so that server instances spread over the available Nodes.
@@ -4352,4 +4379,116 @@ public static String getDockerExtraArgs() {
43524379
}
43534380
return extraArgs.toString();
43544381
}
4382+
4383+
/**
4384+
* Wait until a given event is logged by the operator.
4385+
*
4386+
* @param opNamespace namespace in which the operator is running
4387+
* @param domainNamespace namespace in which the domain exists
4388+
* @param domainUid UID of the domain
4389+
* @param reason event to check for Created, Changed, deleted, processing etc
4390+
* @param type type of event, Normal of Warning
4391+
* @param timestamp the timestamp after which to see events
4392+
*/
4393+
public static void checkEvent(
4394+
String opNamespace, String domainNamespace, String domainUid,
4395+
String reason, String type, OffsetDateTime timestamp) {
4396+
withStandardRetryPolicy
4397+
.conditionEvaluationListener(condition ->
4398+
getLogger().info("Waiting for domain event {0} to be logged in namespace {1} "
4399+
+ "(elapsed time {2}ms, remaining time {3}ms)",
4400+
reason,
4401+
domainNamespace,
4402+
condition.getElapsedTimeInMS(),
4403+
condition.getRemainingTimeInMS()))
4404+
.until(checkDomainEvent(opNamespace, domainNamespace, domainUid, reason, type, timestamp));
4405+
}
4406+
4407+
/**
4408+
* Delete a domain in the specified namespace.
4409+
* @param domainNS the namespace in which the domain exists
4410+
* @param domainUid domain uid
4411+
*/
4412+
public static void deleteDomainResource(String domainNS, String domainUid) {
4413+
//clean up domain resources in namespace and set namespace to label , managed by operator
4414+
getLogger().info("deleting domain custom resource {0}", domainUid);
4415+
assertTrue(deleteDomainCustomResource(domainUid, domainNS));
4416+
4417+
// wait until domain was deleted
4418+
withStandardRetryPolicy
4419+
.conditionEvaluationListener(
4420+
condition -> getLogger().info("Waiting for domain {0} to be deleted in namespace {1} "
4421+
+ "(elapsed time {2}ms, remaining time {3}ms)",
4422+
domainUid,
4423+
domainNS,
4424+
condition.getElapsedTimeInMS(),
4425+
condition.getRemainingTimeInMS()))
4426+
.until(domainDoesNotExist(domainUid, DOMAIN_VERSION, domainNS));
4427+
}
4428+
4429+
private static Callable<Boolean> podLogContainsString(String namespace, String podName, String expectedString) {
4430+
return () -> {
4431+
String podLog;
4432+
try {
4433+
podLog = getPodLog(podName, namespace);
4434+
getLogger().info("pod log for pod {0} in namespace {1} : {2}", podName, namespace, podLog);
4435+
} catch (ApiException apiEx) {
4436+
getLogger().severe("got ApiException while getting pod log: ", apiEx);
4437+
return false;
4438+
}
4439+
4440+
return podLog.contains(expectedString);
4441+
};
4442+
}
4443+
4444+
/**
4445+
* Wait and check the pod log contains the expected string.
4446+
* @param namespace the namespace in which the pod exists
4447+
* @param podName the pod to get the log
4448+
* @param expectedString the expected string to check in the pod log
4449+
*/
4450+
public static void checkPodLogContainsString(String namespace, String podName, String expectedString) {
4451+
4452+
getLogger().info("Wait for string {0} existing in pod {1} in namespace {2}", expectedString, podName, namespace);
4453+
withStandardRetryPolicy
4454+
.conditionEvaluationListener(
4455+
condition -> getLogger().info("Waiting for string {0} existing in pod {1} in namespace {2} "
4456+
+ "(elapsed time {3}ms, remaining time {4}ms)",
4457+
expectedString,
4458+
podName,
4459+
namespace,
4460+
condition.getElapsedTimeInMS(),
4461+
condition.getRemainingTimeInMS()))
4462+
.until(assertDoesNotThrow(() -> podLogContainsString(namespace, podName, expectedString),
4463+
"podLogContainsString failed with IOException, ApiException or InterruptedException"));
4464+
}
4465+
4466+
/**
4467+
* Check the domain event contains the expected error msg.
4468+
*
4469+
* @param opNamespace namespace in which the operator is running
4470+
* @param domainNamespace namespace in which the domain exists
4471+
* @param domainUid UID of the domain
4472+
* @param reason event to check for Created, Changed, deleted, processing etc
4473+
* @param type type of event, Normal of Warning
4474+
* @param timestamp the timestamp after which to see events
4475+
* @param expectedMsg the expected message in the domain event message
4476+
*/
4477+
public static void checkDomainEventContainsExpectedMsg(String opNamespace,
4478+
String domainNamespace,
4479+
String domainUid,
4480+
String reason,
4481+
String type,
4482+
OffsetDateTime timestamp,
4483+
String expectedMsg) {
4484+
checkEvent(opNamespace, domainNamespace, domainUid, reason, type, timestamp);
4485+
CoreV1Event event =
4486+
getEvent(opNamespace, domainNamespace, domainUid, reason, type, timestamp);
4487+
if (event != null && event.getMessage() != null) {
4488+
assertTrue(event.getMessage().contains(expectedMsg),
4489+
String.format("The event message does not contain the expected msg %s", expectedMsg));
4490+
} else {
4491+
fail("event is null or event message is null");
4492+
}
4493+
}
43554494
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static boolean domainEventExists(
159159
}
160160
}
161161
} catch (ApiException ex) {
162-
Logger.getLogger(ItKubernetesEvents.class.getName()).log(Level.SEVERE, null, ex);
162+
logger.log(Level.SEVERE, null, ex);
163163
}
164164
return false;
165165
}

integration-tests/src/test/resources/auxiliaryimage/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818

1919
FROM busybox
20-
ARG AUXILIARY_IMAGE_PATH=/common
20+
ARG AUXILIARY_IMAGE_PATH=/auxiliary
2121
ARG USER=oracle
2222
ARG USERID=1000
2323
ARG GROUP=root

0 commit comments

Comments
 (0)