Skip to content

Commit afcb1e2

Browse files
authored
Add test to patch the domain with updated base image in a running AI domain (#2456)
* Add test to patch the domain with updated base image in a running AI domain
1 parent c3e2ab1 commit afcb1e2

File tree

1 file changed

+95
-10
lines changed

1 file changed

+95
-10
lines changed

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

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
2121
import oracle.weblogic.kubernetes.annotations.Namespaces;
2222
import oracle.weblogic.kubernetes.logging.LoggingFacade;
23+
import oracle.weblogic.kubernetes.utils.TestUtils;
2324
import org.apache.commons.io.FileUtils;
2425
import org.awaitility.core.ConditionFactory;
2526
import org.junit.jupiter.api.BeforeAll;
@@ -34,6 +35,7 @@
3435
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
3536
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
3637
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_IMAGES_REPO;
38+
import static oracle.weblogic.kubernetes.TestConstants.KIND_REPO;
3739
import static oracle.weblogic.kubernetes.TestConstants.MII_AUXILIARY_IMAGE_NAME;
3840
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME;
3941
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
@@ -49,16 +51,20 @@
4951
import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams;
5052
import static oracle.weblogic.kubernetes.actions.TestActions.deleteImage;
5153
import static oracle.weblogic.kubernetes.actions.TestActions.dockerPush;
54+
import static oracle.weblogic.kubernetes.actions.TestActions.dockerTag;
5255
import static oracle.weblogic.kubernetes.actions.TestActions.getDomainCustomResource;
5356
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
5457
import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource;
5558
import static oracle.weblogic.kubernetes.assertions.TestAssertions.verifyRollingRestartOccurred;
5659
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createDomainResource;
60+
import static oracle.weblogic.kubernetes.utils.CommonPatchTestUtils.patchDomainResource;
61+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
5762
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkSystemResourceConfig;
5863
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkSystemResourceConfiguration;
5964
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createDomainAndVerify;
6065
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createOcirRepoSecret;
6166
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword;
67+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.dockerLoginAndPushImageToRegistry;
6268
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getExternalServicePodName;
6369
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getPodsWithTimeStamps;
6470
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyOperator;
@@ -235,12 +241,7 @@ public void testCreateDomainUsingMultipleAuxiliaryImages() {
235241
adminServerPodName, managedServerPrefix, replicaCount);
236242

237243
// check configuration for JMS
238-
int adminServiceNodePort
239-
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
240-
assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid");
241-
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort, "JMSSystemResources",
242-
"TestClusterJmsModule2", "200"), "JMSSystemResources not found");
243-
logger.info("Found the JMSSystemResource configuration");
244+
checkConfiguredJMSresouce(domainNamespace, adminServerPodName);
244245

245246
//checking the order of loading for the common mount images, expecting file with content =2
246247
assertDoesNotThrow(() -> FileUtils.deleteQuietly(Paths.get(RESULTS_ROOT, "/test.txt").toFile()));
@@ -300,11 +301,75 @@ public void testUpdateDataSourceInDomainUsingAuxiliaryImage() {
300301

301302
patchDomainWithAuxiliaryImageAndVerify(miiAuxiliaryImage1, miiAuxiliaryImage3, domainUid, domainNamespace);
302303

303-
assertTrue(checkSystemResourceConfig(adminServiceNodePort,
304-
"JDBCSystemResources/TestDataSource/JDBCResource/JDBCDriverParams",
305-
"jdbc:oracle:thin:@\\/\\/localhost:7001\\/dbsvc"), "Can't find expected URL configuration for DataSource");
304+
checkConfiguredJDBCresouce(domainNamespace, adminServerPodName);
305+
}
306+
307+
/**
308+
* Patch the domain with the different base image name.
309+
* Verify all the pods are restarted and back to ready state.
310+
* Verify configured JMS and JDBC resources.
311+
*/
312+
@Test
313+
@Order(3)
314+
@DisplayName("Test to update Base Weblogic Image Name")
315+
public void testUpdateBaseImageName() {
316+
// get the original domain resource before update
317+
Domain domain1 = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
318+
String.format("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s",
319+
domainUid, domainNamespace));
320+
assertNotNull(domain1, "Got null domain resource");
321+
assertNotNull(domain1.getSpec(), domain1 + "/spec is null");
322+
323+
// get the map with server pods and their original creation timestamps
324+
podsWithTimeStamps = getPodsWithTimeStamps(domainNamespace, adminServerPodName, managedServerPrefix,
325+
replicaCount);
326+
327+
//print out the original image name
328+
String imageName = domain1.getSpec().getImage();
329+
logger.info("Currently the image name used for the domain is: {0}", imageName);
330+
331+
//change image name to imageUpdate
332+
String imageTag = TestUtils.getDateAndTimeStamp();
333+
String imageUpdate = KIND_REPO != null ? KIND_REPO
334+
+ (WEBLOGIC_IMAGE_NAME + ":" + imageTag).substring(TestConstants.BASE_IMAGES_REPO.length() + 1)
335+
: WEBLOGIC_IMAGE_NAME + ":" + imageTag;
336+
dockerTag(imageName, imageUpdate);
337+
dockerLoginAndPushImageToRegistry(imageUpdate);
338+
339+
StringBuffer patchStr = null;
340+
patchStr = new StringBuffer("[{");
341+
patchStr.append("\"op\": \"replace\",")
342+
.append(" \"path\": \"/spec/image\",")
343+
.append("\"value\": \"")
344+
.append(imageUpdate)
345+
.append("\"}]");
346+
logger.info("PatchStr for imageUpdate: {0}", patchStr.toString());
347+
348+
assertTrue(patchDomainResource(domainUid, domainNamespace, patchStr),
349+
"patchDomainCustomResource(imageUpdate) failed");
350+
351+
domain1 = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
352+
String.format("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s",
353+
domainUid, domainNamespace));
354+
assertNotNull(domain1, "Got null domain resource after patching");
355+
assertNotNull(domain1.getSpec(), domain1 + " /spec is null");
356+
357+
//print out image name in the new patched domain
358+
logger.info("In the new patched domain image name is: {0}", domain1.getSpec().getImage());
359+
360+
// verify the server pods are rolling restarted and back to ready state
361+
logger.info("Verifying rolling restart occurred for domain {0} in namespace {1}",
362+
domainUid, domainNamespace);
363+
assertTrue(verifyRollingRestartOccurred(podsWithTimeStamps, 1, domainNamespace),
364+
String.format("Rolling restart failed for domain %s in namespace %s", domainUid, domainNamespace));
365+
366+
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);
367+
368+
// check configuration for JMS
369+
checkConfiguredJMSresouce(domainNamespace, adminServerPodName);
370+
//check configuration for JDBC
371+
checkConfiguredJDBCresouce(domainNamespace, adminServerPodName);
306372

307-
logger.info("Found the DataResource configuration");
308373
}
309374

310375
private static void patchDomainWithAuxiliaryImageAndVerify(String oldImageName, String newImageName,
@@ -400,4 +465,24 @@ private void createAuxiliaryImage(String stageDirPath, String dockerFileLocation
400465
.command(cmdToExecute))
401466
.execute(), String.format("Failed to execute", cmdToExecute));
402467
}
468+
469+
private void checkConfiguredJMSresouce(String domainNamespace, String adminServerPodName) {
470+
int adminServiceNodePort
471+
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
472+
assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid");
473+
assertTrue(checkSystemResourceConfiguration(adminServiceNodePort, "JMSSystemResources",
474+
"TestClusterJmsModule2", "200"), "JMSSystemResources not found");
475+
logger.info("Found the JMSSystemResource configuration");
476+
}
477+
478+
private void checkConfiguredJDBCresouce(String domainNamespace, String adminServerPodName) {
479+
int adminServiceNodePort
480+
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
481+
assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid");
482+
assertTrue(checkSystemResourceConfig(adminServiceNodePort,
483+
"JDBCSystemResources/TestDataSource/JDBCResource/JDBCDriverParams",
484+
"jdbc:oracle:thin:@\\/\\/localhost:7001\\/dbsvc"), "Can't find expected URL configuration for DataSource");
485+
logger.info("Found the DataResource configuration");
486+
}
487+
403488
}

0 commit comments

Comments
 (0)