diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAuxiliaryImage.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAuxiliaryImage.java index 938b5ac9fb1..1fdd06fcf25 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAuxiliaryImage.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAuxiliaryImage.java @@ -44,16 +44,18 @@ import static oracle.weblogic.kubernetes.TestConstants.OCIR_SECRET_NAME; import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_RELEASE_NAME; import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT; +import static oracle.weblogic.kubernetes.TestConstants.WDT_TEST_VERSION; import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_NAME; import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TAG; import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR; +import static oracle.weblogic.kubernetes.actions.ActionConstants.DOWNLOAD_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR; +import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_FILENAME_DEFAULT; import static oracle.weblogic.kubernetes.actions.TestActions.buildAppArchive; import static oracle.weblogic.kubernetes.actions.TestActions.createDomainCustomResource; import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams; import static oracle.weblogic.kubernetes.actions.TestActions.deleteImage; -import static oracle.weblogic.kubernetes.actions.TestActions.dockerPush; import static oracle.weblogic.kubernetes.actions.TestActions.dockerTag; import static oracle.weblogic.kubernetes.actions.TestActions.getDomainCustomResource; import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorPodName; @@ -104,11 +106,19 @@ public class ItMiiAuxiliaryImage { private static String opNamespace = null; private static String domainNamespace = null; private static String errorpathDomainNamespace = null; + private static String wdtDomainNamespace = null; private static LoggingFacade logger = null; private String domainUid = "domain1"; private static String miiAuxiliaryImage1 = MII_AUXILIARY_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG + "1"; private static String miiAuxiliaryImage2 = MII_AUXILIARY_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG + "2"; private static String miiAuxiliaryImage3 = MII_AUXILIARY_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG + "3"; + private static String miiAuxiliaryImage4 = MII_AUXILIARY_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG + "4"; + private static String miiAuxiliaryImage5 = MII_AUXILIARY_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG + "5"; + private static String miiAuxiliaryImage6 = MII_AUXILIARY_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG + "6"; + private static String errorPathAuxiliaryImage1 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage1"; + private static String errorPathAuxiliaryImage2 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage2"; + private static String errorPathAuxiliaryImage3 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage3"; + private static String errorPathAuxiliaryImage4 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage4"; private static Map podsWithTimeStamps = null; private final String adminServerPodName = domainUid + "-admin-server"; private final String managedServerPrefix = domainUid + "-managed-server"; @@ -123,11 +133,12 @@ public class ItMiiAuxiliaryImage { /** * Install Operator. + * * @param namespaces list of namespaces created by the IntegrationTestWatcher by the - * JUnit engine parameter resolution mechanism + * JUnit engine parameter resolution mechanism */ @BeforeAll - public static void initAll(@Namespaces(3) List namespaces) { + public static void initAll(@Namespaces(4) List namespaces) { logger = getLogger(); // get a new unique opNamespace logger.info("Creating unique namespace for Operator"); @@ -142,8 +153,12 @@ public static void initAll(@Namespaces(3) List namespaces) { assertNotNull(namespaces.get(2), "Namespace list is null"); errorpathDomainNamespace = namespaces.get(2); + logger.info("Creating unique namespace for wdtDomainNamespace"); + assertNotNull(namespaces.get(3), "Namespace list is null"); + wdtDomainNamespace = namespaces.get(3); + // install and verify operator - installAndVerifyOperator(opNamespace, domainNamespace, errorpathDomainNamespace); + installAndVerifyOperator(opNamespace, domainNamespace, errorpathDomainNamespace, wdtDomainNamespace); } @@ -178,8 +193,10 @@ public void testCreateDomainUsingMultipleAuxiliaryImages() { // create stage dir for first auxiliary image with image1 Path multipleAIPath1 = Paths.get(RESULTS_ROOT, "multipleauxiliaryimage1"); - assertDoesNotThrow(() -> FileUtils.deleteDirectory(multipleAIPath1.toFile())); - assertDoesNotThrow(() -> Files.createDirectories(multipleAIPath1)); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(multipleAIPath1.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(multipleAIPath1), + "Create directory failed"); Path multipleAIPathToFile1 = Paths.get(RESULTS_ROOT, "multipleauxiliaryimage1/test.txt"); String content = "1"; assertDoesNotThrow(() -> Files.write(multipleAIPathToFile1, content.getBytes()), @@ -205,7 +222,7 @@ public void testCreateDomainUsingMultipleAuxiliaryImages() { // copy app archive to models assertDoesNotThrow(() -> Files.copy( - Paths.get(ARCHIVE_DIR, MII_BASIC_APP_NAME + ".zip"), + Paths.get(ARCHIVE_DIR, MII_BASIC_APP_NAME + ".zip"), Paths.get(modelsPath1.toString(), MII_BASIC_APP_NAME + ".zip"), StandardCopyOption.REPLACE_EXISTING)); @@ -219,13 +236,15 @@ public void testCreateDomainUsingMultipleAuxiliaryImages() { // push image1 to repo for multi node cluster if (!DOMAIN_IMAGES_REPO.isEmpty()) { logger.info("docker push image {0} to registry {1}", miiAuxiliaryImage1, DOMAIN_IMAGES_REPO); - assertTrue(dockerPush(miiAuxiliaryImage1), String.format("docker push failed for image %s", miiAuxiliaryImage1)); + dockerLoginAndPushImageToRegistry(miiAuxiliaryImage1); } // create stage dir for second auxiliary image with image2 Path multipleAIPath2 = Paths.get(RESULTS_ROOT, "multipleauxiliaryimage2"); - assertDoesNotThrow(() -> FileUtils.deleteDirectory(multipleAIPath2.toFile())); - assertDoesNotThrow(() -> Files.createDirectories(multipleAIPath2)); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(multipleAIPath2.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(multipleAIPath2), + "Create directory failed"); // create models dir and copy model, archive files if any Path modelsPath2 = Paths.get(multipleAIPath2.toString(), "models"); @@ -246,7 +265,7 @@ public void testCreateDomainUsingMultipleAuxiliaryImages() { // push image2 to repo for multi node cluster if (!DOMAIN_IMAGES_REPO.isEmpty()) { logger.info("docker push image {0} to registry {1}", miiAuxiliaryImage2, DOMAIN_IMAGES_REPO); - assertTrue(dockerPush(miiAuxiliaryImage2), String.format("docker push failed for image %s", miiAuxiliaryImage2)); + dockerLoginAndPushImageToRegistry(miiAuxiliaryImage2); } // create domain custom resource using 2 auxiliary images @@ -266,16 +285,16 @@ public void testCreateDomainUsingMultipleAuxiliaryImages() { // check configuration for JMS checkConfiguredJMSresouce(domainNamespace, adminServerPodName); - //checking the order of loading for the common mount images, expecting file with content =2 + //checking the order of loading for the auxiliary images, expecting file with content =2 assertDoesNotThrow(() -> FileUtils.deleteQuietly(Paths.get(RESULTS_ROOT, "/test.txt").toFile())); assertDoesNotThrow(() -> copyFileFromPod(domainNamespace, adminServerPodName, "weblogic-server", auxiliaryImagePath + "/test.txt", Paths.get(RESULTS_ROOT, "/test.txt")), " Can't find file in the pod, or failed to copy"); - assertDoesNotThrow(() -> { + assertDoesNotThrow(() -> { String fileContent = Files.readAllLines(Paths.get(RESULTS_ROOT, "/test.txt")).get(0); - assertEquals("2", fileContent, "The content of the file from common mount path " + assertEquals("2", fileContent, "The content of the file from auxiliary image path " + fileContent + "does not match the expected 2"); }, "File from image2 was not loaded in the expected order"); } @@ -297,10 +316,10 @@ public void testUpdateDataSourceInDomainUsingAuxiliaryImage() { // replace DataSource URL info in the model file assertDoesNotThrow(() -> replaceStringInFile(Paths.get(modelsPath1.toString(), "/multi-model-one-ds.20.yaml").toString(), "xxx.xxx.x.xxx:1521", - "localhost:7001"),"Can't replace datasource url in the model file"); + "localhost:7001"), "Can't replace datasource url in the model file"); assertDoesNotThrow(() -> replaceStringInFile(Paths.get(modelsPath1.toString(), "/multi-model-one-ds.20.yaml").toString(), "ORCLCDB", - "dbsvc"),"Can't replace datasource url in the model file"); + "dbsvc"), "Can't replace datasource url in the model file"); // create image3 with model and wdt installation files createAuxiliaryImage(multipleAIPath1.toString(), @@ -309,7 +328,7 @@ public void testUpdateDataSourceInDomainUsingAuxiliaryImage() { // push image3 to repo for multi node cluster if (!DOMAIN_IMAGES_REPO.isEmpty()) { logger.info("docker push image {0} to registry {1}", miiAuxiliaryImage3, DOMAIN_IMAGES_REPO); - assertTrue(dockerPush(miiAuxiliaryImage3), String.format("docker push failed for image %s", miiAuxiliaryImage3)); + dockerLoginAndPushImageToRegistry(miiAuxiliaryImage3); } // check configuration for DataSource in the running domain @@ -318,7 +337,8 @@ public void testUpdateDataSourceInDomainUsingAuxiliaryImage() { assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid"); assertTrue(checkSystemResourceConfig(adminServiceNodePort, "JDBCSystemResources/TestDataSource/JDBCResource/JDBCDriverParams", - "jdbc:oracle:thin:@\\/\\/xxx.xxx.x.xxx:1521\\/ORCLCDB"),"Can't find expected URL configuration for DataSource"); + "jdbc:oracle:thin:@\\/\\/xxx.xxx.x.xxx:1521\\/ORCLCDB"), + "Can't find expected URL configuration for DataSource"); logger.info("Found the DataResource configuration"); @@ -399,7 +419,7 @@ public void testUpdateBaseImageName() { * Negative Test to create domain with mismatch mount path in auxiliary image and auxiliaryImageVolumes. * in auxiliaryImageVolumes, set mountPath to "/errorpath" * in auxiliary image, set AUXILIARY_IMAGE_PATH to "/auxiliary" - * Check the error msg is in introspector pod log, domain events and operator pod log. + * Check the error message is in introspector pod log, domain events and operator pod log. */ @Test @Order(3) @@ -407,7 +427,6 @@ public void testUpdateBaseImageName() { public void testErrorPathDomainMismatchMountPath() { OffsetDateTime timestamp = now(); - String errorPathAuxiliaryImage1 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage1"; final String auxiliaryImageVolumeName = "auxiliaryImageVolume1"; final String auxiliaryImagePath = "/errorpath"; @@ -416,8 +435,10 @@ public void testErrorPathDomainMismatchMountPath() { // create stage dir for auxiliary image Path errorpathAIPath1 = Paths.get(RESULTS_ROOT, "errorpathauxiimage1"); - assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath1.toFile())); - assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath1)); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath1.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath1), + "Create directory failed"); // create models dir and copy model for image Path modelsPath1 = Paths.get(errorpathAIPath1.toString(), "models"); @@ -437,8 +458,7 @@ public void testErrorPathDomainMismatchMountPath() { // push image to repo for multi node cluster if (!DOMAIN_IMAGES_REPO.isEmpty()) { logger.info("docker push image {0} to registry {1}", errorPathAuxiliaryImage1, DOMAIN_IMAGES_REPO); - assertTrue(dockerPush(errorPathAuxiliaryImage1), - String.format("docker push failed for image %s", errorPathAuxiliaryImage1)); + dockerLoginAndPushImageToRegistry(errorPathAuxiliaryImage1); } // create domain custom resource using auxiliary images @@ -454,16 +474,16 @@ public void testErrorPathDomainMismatchMountPath() { domainUid, errorPathAuxiliaryImage1, errorpathDomainNamespace); assertDoesNotThrow(() -> createDomainCustomResource(domainCR), "createDomainCustomResource throws Exception"); - // check the introspector pod log contains the expected error msg + // check the introspector pod log contains the expected error message String expectedErrorMsg = "Auxiliary Image: Dir '/errorpath' doesn't exist or is empty. Exiting."; String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace)); checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); - // check the domain event contains the expected error msg + // check the domain event contains the expected error message checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, "Warning", timestamp, expectedErrorMsg); - // check the operator pod log contains the expected error msg + // check the operator pod log contains the expected error message String operatorPodName = assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace)); checkPodLogContainsString(opNamespace, operatorPodName, expectedErrorMsg); @@ -482,7 +502,7 @@ public void testErrorPathDomainMismatchMountPath() { /** * Negative Test to create domain without WDT binary. - * Check the error msg is in introspector pod log, domain events and operator pod log. + * Check the error message is in introspector pod log, domain events and operator pod log. */ @Test @Order(4) @@ -490,25 +510,27 @@ public void testErrorPathDomainMismatchMountPath() { public void testErrorPathDomainMissingWDTBinary() { OffsetDateTime timestamp = now(); - String errorPathAuxiliaryImage2 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage2"; final String auxiliaryImageVolumeName = "auxiliaryImageVolume1"; final String auxiliaryImagePath = "/auxiliary"; createSecretsForDomain(adminSecretName, encryptionSecretName, errorpathDomainNamespace); - // create stage dir for common mount image + // create stage dir for auxiliary image Path errorpathAIPath2 = Paths.get(RESULTS_ROOT, "errorpathauxiimage2"); - assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath2.toFile())); - assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath2)); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath2.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath2), + "Create directory failed"); // create models dir and copy model for image Path modelsPath2 = Paths.get(errorpathAIPath2.toString(), "models"); - assertDoesNotThrow(() -> Files.createDirectories(modelsPath2)); + assertDoesNotThrow(() -> Files.createDirectories(modelsPath2), + "Create directory failed"); assertDoesNotThrow(() -> Files.copy( Paths.get(MODEL_DIR, MII_BASIC_WDT_MODEL_FILE), Paths.get(modelsPath2.toString(), MII_BASIC_WDT_MODEL_FILE), - StandardCopyOption.REPLACE_EXISTING)); + StandardCopyOption.REPLACE_EXISTING), "Copy files failed"); // create image with model and no wdt installation files createAuxiliaryImage(errorpathAIPath2.toString(), @@ -517,8 +539,7 @@ public void testErrorPathDomainMissingWDTBinary() { // push image to repo for multi node cluster if (!DOMAIN_IMAGES_REPO.isEmpty()) { logger.info("docker push image {0} to registry {1}", errorPathAuxiliaryImage2, DOMAIN_IMAGES_REPO); - assertTrue(dockerPush(errorPathAuxiliaryImage2), - String.format("docker push failed for image %s", errorPathAuxiliaryImage2)); + dockerLoginAndPushImageToRegistry(errorPathAuxiliaryImage2); } // create domain custom resource using auxiliary images @@ -530,24 +551,26 @@ public void testErrorPathDomainMissingWDTBinary() { auxiliaryImageVolumeName, errorPathAuxiliaryImage2); // create domain and verify it is failed - logger.info("Creating domain {0} with common mount image {1} in namespace {2}", + logger.info("Creating domain {0} with auxiliary image {1} in namespace {2}", domainUid, errorPathAuxiliaryImage2, errorpathDomainNamespace); assertDoesNotThrow(() -> createDomainCustomResource(domainCR), "createDomainCustomResource throws Exception"); - // check the introspector pod log contains the expected error msg + // check the introspector pod log contains the expected error message String expectedErrorMsg = "The domain resource 'spec.domainHomeSourceType' is 'FromModel' and " + "a WebLogic Deploy Tool (WDT) install is not located at 'spec.configuration.model.wdtInstallHome' " + "which is currently set to '/auxiliary/weblogic-deploy'"; - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace)); + String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace), + "Can't get introspector pod's name"); checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); - // check the domain event contains the expected error msg + // check the domain event contains the expected error message checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, "Warning", timestamp, expectedErrorMsg); - // check the operator pod log contains the expected error msg + // check the operator pod log contains the expected error message String operatorPodName = - assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace)); + assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace), + "Can't get operator pod's name"); checkPodLogContainsString(opNamespace, operatorPodName, expectedErrorMsg); // check there are no admin server and managed server pods and services created @@ -572,7 +595,6 @@ public void testErrorPathDomainMissingWDTBinary() { public void testErrorPathDomainMissingDomainConfig() { OffsetDateTime timestamp = now(); - String errorPathAuxiliaryImage3 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage3"; final String auxiliaryImageVolumeName = "auxiliaryImageVolume1"; final String auxiliaryImagePath = "/auxiliary"; @@ -581,16 +603,20 @@ public void testErrorPathDomainMissingDomainConfig() { // create stage dir for auxiliary image Path errorpathAIPath3 = Paths.get(RESULTS_ROOT, "errorpathauxiimage3"); - assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath3.toFile())); - assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath3)); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath3.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath3), + "Create directory failed"); // create models dir and copy model for image Path modelsPath3 = Paths.get(errorpathAIPath3.toString(), "models"); - assertDoesNotThrow(() -> Files.createDirectories(modelsPath3)); + assertDoesNotThrow(() -> Files.createDirectories(modelsPath3), + "Create directory failed"); assertDoesNotThrow(() -> Files.copy( Paths.get(MODEL_DIR, "model.jms2.yaml"), Paths.get(modelsPath3.toString(), "model.jms2.yaml"), - StandardCopyOption.REPLACE_EXISTING)); + StandardCopyOption.REPLACE_EXISTING), + "Copy files failed"); // unzip WDT installation file into work dir unzipWDTInstallationFile(errorpathAIPath3.toString()); @@ -602,8 +628,7 @@ public void testErrorPathDomainMissingDomainConfig() { // push image to repo for multi node cluster if (!DOMAIN_IMAGES_REPO.isEmpty()) { logger.info("docker push image {0} to registry {1}", errorPathAuxiliaryImage3, DOMAIN_IMAGES_REPO); - assertTrue(dockerPush(errorPathAuxiliaryImage3), - String.format("docker push failed for image %s", errorPathAuxiliaryImage3)); + dockerLoginAndPushImageToRegistry(errorPathAuxiliaryImage3); } // create domain custom resource using auxiliary images @@ -619,19 +644,21 @@ public void testErrorPathDomainMissingDomainConfig() { domainUid, errorPathAuxiliaryImage3, errorpathDomainNamespace); assertDoesNotThrow(() -> createDomainCustomResource(domainCR), "createDomainCustomResource throws Exception"); - // check the introspector pod log contains the expected error msg + // check the introspector pod log contains the expected error message String expectedErrorMsg = "createDomain did not find the required domainInfo section in the model file /auxiliary/models/model.jms2.yaml"; - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace)); + String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace), + "Get introspector's pod name failed"); checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); - // check the domain event contains the expected error msg + // check the domain event contains the expected error message checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, "Warning", timestamp, expectedErrorMsg); - // check the operator pod log contains the expected error msg + // check the operator pod log contains the expected error message String operatorPodName = - assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace)); + assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace), + "Get operator's pod name failed"); checkPodLogContainsString(opNamespace, operatorPodName, expectedErrorMsg); // check there are no admin server and managed server pods and services created @@ -650,7 +677,7 @@ public void testErrorPathDomainMissingDomainConfig() { * Negative Test to patch the existing domain using a custom mount command that's guaranteed to fail. * Specify domain.spec.serverPod.auxiliaryImages.command to a custom mount command instead of the default one, which * defaults to "cp -R $AUXILIARY_IMAGE_PATH/* $TARGET_MOUNT_PATH" - * Check the error msg in introspector pod log, domain events and operator pod log. + * Check the error message in introspector pod log, domain events and operator pod log. * Restore the domain by removing the custom mount command. */ @Test @@ -685,7 +712,7 @@ public void testErrorPathDomainWithFailCustomMountCommand() { .append(" \"path\": " + searchString + ",") .append(" \"value\": \"exit 1\"") .append(" }]"); - logger.info("Auxiliary Image patch string: " + patchStr); + logger.info("Auxiliary Image patch string: " + patchStr); V1Patch patch = new V1Patch((patchStr).toString()); @@ -694,18 +721,20 @@ public void testErrorPathDomainWithFailCustomMountCommand() { "patchDomainCustomResource(Auxiliary Image) failed "); assertTrue(aiPatched, "patchDomainCustomResource(auxiliary image) failed"); - // check the introspector pod log contains the expected error msg + // check the introspector pod log contains the expected error message String expectedErrorMsg = "Auxiliary Image: Command 'exit 1' execution failed in container"; - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, domainNamespace)); + String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, domainNamespace), + "Get introspector's pod name failed"); checkPodLogContainsString(domainNamespace, introspectorPodName, expectedErrorMsg); - // check the domain event contains the expected error msg + // check the domain event contains the expected error message checkDomainEventContainsExpectedMsg(opNamespace, domainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, "Warning", timestamp, expectedErrorMsg); - // check the operator pod log contains the expected error msg + // check the operator pod log contains the expected error message String operatorPodName = - assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace)); + assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace), + "Get operator's pod name failed"); checkPodLogContainsString(opNamespace, operatorPodName, expectedErrorMsg); // verify the domain is not rolled @@ -723,7 +752,7 @@ public void testErrorPathDomainWithFailCustomMountCommand() { patchStr.append("\"op\": \"remove\",") .append(" \"path\": " + searchString) .append(" }]"); - logger.info("Auxiliary Image patch string: " + patchStr); + logger.info("Auxiliary Image patch string: " + patchStr); V1Patch patch1 = new V1Patch((patchStr).toString()); @@ -740,7 +769,7 @@ public void testErrorPathDomainWithFailCustomMountCommand() { * Negative Test to create domain with file , created by user tester with permission read only * and not accessible by oracle user in auxiliary image * via provided Dockerfile. - * Check the error msg is in introspector pod log, domain events and operator pod log. + * Check the error message is in introspector pod log, domain events and operator pod log. */ @Test @Order(7) @@ -748,7 +777,6 @@ public void testErrorPathDomainWithFailCustomMountCommand() { public void testErrorPathFilePermission() { OffsetDateTime timestamp = now(); - String errorPathAuxiliaryImage1 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage4"; final String auxiliaryImageVolumeName = "auxiliaryImageVolume1"; final String auxiliaryImagePath = "/auxiliary"; @@ -757,8 +785,10 @@ public void testErrorPathFilePermission() { // create stage dir for auxiliary image Path errorpathAIPath1 = Paths.get(RESULTS_ROOT, "errorpathauxiimage4"); - assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath1.toFile())); - assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath1)); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath1.toFile()), + "Can't delete directory"); + assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath1), + "Can't create directory"); Path errorpathAIPathToFile = Paths.get(RESULTS_ROOT, "errorpathauxiimage4/test1.txt"); String content = "some text "; @@ -767,11 +797,13 @@ public void testErrorPathFilePermission() { // create models dir and copy model for image Path modelsPath1 = Paths.get(errorpathAIPath1.toString(), "models"); - assertDoesNotThrow(() -> Files.createDirectories(modelsPath1)); + assertDoesNotThrow(() -> Files.createDirectories(modelsPath1), + "Can't create directory"); assertDoesNotThrow(() -> Files.copy( Paths.get(MODEL_DIR, MII_BASIC_WDT_MODEL_FILE), Paths.get(modelsPath1.toString(), MII_BASIC_WDT_MODEL_FILE), - StandardCopyOption.REPLACE_EXISTING)); + StandardCopyOption.REPLACE_EXISTING), + "Can't copy files"); // build app assertTrue(buildAppArchive(defaultAppParams() @@ -781,49 +813,50 @@ public void testErrorPathFilePermission() { // copy app archive to models assertDoesNotThrow(() -> Files.copy( - Paths.get(ARCHIVE_DIR, MII_BASIC_APP_NAME + ".zip"), + Paths.get(ARCHIVE_DIR, MII_BASIC_APP_NAME + ".zip"), Paths.get(modelsPath1.toString(), MII_BASIC_APP_NAME + ".zip"), - StandardCopyOption.REPLACE_EXISTING)); + StandardCopyOption.REPLACE_EXISTING), "Can't copy files"); // unzip WDT installation file into work dir unzipWDTInstallationFile(errorpathAIPath1.toString()); // create image with model and wdt installation files createAuxiliaryImage(errorpathAIPath1.toString(), - Paths.get(RESOURCE_DIR, "auxiliaryimage", "/negative/Dockerfile").toString(), errorPathAuxiliaryImage1); + Paths.get(RESOURCE_DIR, "auxiliaryimage", "/negative/Dockerfile").toString(), errorPathAuxiliaryImage4); // push image to repo for multi node cluster if (!DOMAIN_IMAGES_REPO.isEmpty()) { - logger.info("docker push image {0} to registry {1}", errorPathAuxiliaryImage1, DOMAIN_IMAGES_REPO); - assertTrue(dockerPush(errorPathAuxiliaryImage1), - String.format("docker push failed for image %s", errorPathAuxiliaryImage1)); + logger.info("docker push image {0} to registry {1}", errorPathAuxiliaryImage4, DOMAIN_IMAGES_REPO); + dockerLoginAndPushImageToRegistry(errorPathAuxiliaryImage4); } // create domain custom resource using auxiliary images logger.info("Creating domain custom resource with domainUid {0} and auxiliary image {1}", - domainUid, errorPathAuxiliaryImage1); + domainUid, errorPathAuxiliaryImage4); Domain domainCR = createDomainResource(domainUid, errorpathDomainNamespace, WEBLOGIC_IMAGE_NAME + ":" + WEBLOGIC_IMAGE_TAG, adminSecretName, OCIR_SECRET_NAME, encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath, - auxiliaryImageVolumeName, errorPathAuxiliaryImage1); + auxiliaryImageVolumeName, errorPathAuxiliaryImage4); // create domain and verify it is failed logger.info("Creating domain {0} with auxiliary image {1} in namespace {2}", - domainUid, errorPathAuxiliaryImage1, errorpathDomainNamespace); + domainUid, errorPathAuxiliaryImage4, errorpathDomainNamespace); assertDoesNotThrow(() -> createDomainCustomResource(domainCR), "createDomainCustomResource throws Exception"); - // check the introspector pod log contains the expected error msg + // check the introspector pod log contains the expected error message String expectedErrorMsg = "cp: can't open '/auxiliary/test1.txt': Permission denied"; - String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace)); + String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace), + "Can't get introspector's pod name"); checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg); - // check the domain event contains the expected error msg + // check the domain event contains the expected error message checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED, "Warning", timestamp, expectedErrorMsg); - // check the operator pod log contains the expected error msg + // check the operator pod log contains the expected error message String operatorPodName = - assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace)); + assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace), + "Can't get operator's pod name"); checkPodLogContainsString(opNamespace, operatorPodName, expectedErrorMsg); // check there are no admin server and managed server pods and services not created @@ -838,6 +871,183 @@ public void testErrorPathFilePermission() { deleteDomainResource(errorpathDomainNamespace, domainUid); } + /** + * Create a domain using multiple auxiliary images. + * One auxiliary image (image1) contains the domain configuration and + * another auxiliary image (image2) with WDT only, + * update WDT version by patching with another auxiliary image (image3) + * and verify the domain is running. + */ + @Test + @Order(8) + @DisplayName("Test to update WDT version using auxiliary images") + public void testUpdateWDTVersionUsingMultipleAuxiliaryImages() { + + // admin/managed server name here should match with model yaml + final String auxiliaryImageVolumeName = "auxiliaryImageVolume1"; + final String auxiliaryImagePath = "/auxiliary"; + + // Create the repo secret to pull the image + // this secret is used only for non-kind cluster + createOcirRepoSecret(wdtDomainNamespace); + + // create secret for admin credentials + logger.info("Create secret for admin credentials"); + String adminSecretName = "weblogic-credentials"; + createSecretWithUsernamePassword(adminSecretName, wdtDomainNamespace, + ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT); + + // create encryption secret + logger.info("Create encryption secret"); + String encryptionSecretName = "encryptionsecret"; + createSecretWithUsernamePassword(encryptionSecretName, wdtDomainNamespace, + "weblogicenc", "weblogicenc"); + + // create stage dir for first auxiliary image containing domain configuration + Path multipleAIPath1 = Paths.get(RESULTS_ROOT, "multipleauxiliaryimage1"); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(multipleAIPath1.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(multipleAIPath1), + "Failed to create directory"); + + // create models dir and copy model, archive files if any for image1 + Path modelsPath1 = Paths.get(multipleAIPath1.toString(), "models"); + assertDoesNotThrow(() -> Files.createDirectories(modelsPath1)); + assertDoesNotThrow(() -> Files.copy( + Paths.get(MODEL_DIR, MII_BASIC_WDT_MODEL_FILE), + Paths.get(modelsPath1.toString(), MII_BASIC_WDT_MODEL_FILE), + StandardCopyOption.REPLACE_EXISTING), "Failed to copy file"); + assertDoesNotThrow(() -> Files.copy( + Paths.get(MODEL_DIR, "multi-model-one-ds.20.yaml"), + Paths.get(modelsPath1.toString(), "multi-model-one-ds.20.yaml"), + StandardCopyOption.REPLACE_EXISTING), "Failed to copy file"); + + // build app + assertTrue(buildAppArchive(defaultAppParams() + .srcDirList(Collections.singletonList(MII_BASIC_APP_NAME)) + .appName(MII_BASIC_APP_NAME)), + String.format("Failed to create app archive for %s", MII_BASIC_APP_NAME)); + + // copy app archive to models + assertDoesNotThrow(() -> Files.copy( + Paths.get(ARCHIVE_DIR, MII_BASIC_APP_NAME + ".zip"), + Paths.get(modelsPath1.toString(), MII_BASIC_APP_NAME + ".zip"), + StandardCopyOption.REPLACE_EXISTING), "Failed to copy file"); + + // create image1 with domain configuration only + createAuxiliaryImage(multipleAIPath1.toString(), + Paths.get(RESOURCE_DIR, "auxiliaryimage", "Dockerfile").toString(), miiAuxiliaryImage4); + + // push image1 to repo for multi node cluster + if (!DOMAIN_IMAGES_REPO.isEmpty()) { + logger.info("docker push image {0} to registry {1}", miiAuxiliaryImage4, DOMAIN_IMAGES_REPO); + dockerLoginAndPushImageToRegistry(miiAuxiliaryImage4); + } + + // create stage dir for second auxiliary image + Path multipleAIPath2 = Paths.get(RESULTS_ROOT, "multipleauxiliaryimage2"); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(multipleAIPath2.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(multipleAIPath2), "Create directory failed"); + + Path modelsPath2 = Paths.get(multipleAIPath2.toString(), "models"); + assertDoesNotThrow(() -> Files.createDirectories(modelsPath2), "Create directory failed"); + + // unzip older version WDT installation file into work dir + String wdtURL = "https://github.com/oracle/weblogic-deploy-tooling/releases/download/release-" + + WDT_TEST_VERSION + "/" + + WDT_DOWNLOAD_FILENAME_DEFAULT; + unzipWDTInstallationFile(multipleAIPath2.toString(), wdtURL, + DOWNLOAD_DIR + "/ver" + WDT_TEST_VERSION); + + // create image2 with wdt installation files only + createAuxiliaryImage(multipleAIPath2.toString(), + Paths.get(RESOURCE_DIR, "auxiliaryimage", "Dockerfile").toString(), miiAuxiliaryImage5); + + // push image2 to repo for multi node cluster + if (!DOMAIN_IMAGES_REPO.isEmpty()) { + logger.info("docker push image {0} to registry {1}", miiAuxiliaryImage5, DOMAIN_IMAGES_REPO); + dockerLoginAndPushImageToRegistry(miiAuxiliaryImage5); + } + + // create stage dir for third auxiliary image with latest wdt installation files only + Path multipleAIPath3 = Paths.get(RESULTS_ROOT, "multipleauxiliaryimage3"); + assertDoesNotThrow(() -> FileUtils.deleteDirectory(multipleAIPath3.toFile()), + "Delete directory failed"); + assertDoesNotThrow(() -> Files.createDirectories(multipleAIPath3), + "Create directory failed"); + + Path modelsPath3 = Paths.get(multipleAIPath3.toString(), "models"); + assertDoesNotThrow(() -> Files.createDirectories(modelsPath3), + "Create directory failed"); + + // unzip WDT installation file into work dir + unzipWDTInstallationFile(multipleAIPath3.toString()); + + // create image3 with newest version of wdt installation files + createAuxiliaryImage(multipleAIPath3.toString(), + Paths.get(RESOURCE_DIR, "auxiliaryimage", "Dockerfile").toString(), miiAuxiliaryImage6); + + // push image3 to repo for multi node cluster + if (!DOMAIN_IMAGES_REPO.isEmpty()) { + logger.info("docker push image {0} to registry {1}", miiAuxiliaryImage6, DOMAIN_IMAGES_REPO); + dockerLoginAndPushImageToRegistry(miiAuxiliaryImage6); + } + + // create domain custom resource using 2 auxiliary images ( image1, image2) + logger.info("Creating domain custom resource with domainUid {0} and auxiliary images {1} {2}", + domainUid, miiAuxiliaryImage4, miiAuxiliaryImage5); + Domain domainCR = createDomainResource(domainUid, wdtDomainNamespace, + WEBLOGIC_IMAGE_NAME + ":" + WEBLOGIC_IMAGE_TAG, adminSecretName, OCIR_SECRET_NAME, + encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath, + auxiliaryImageVolumeName, miiAuxiliaryImage4, miiAuxiliaryImage5); + + // create domain and verify its running + logger.info("Creating domain {0} with auxiliary images {1} {2} in namespace {3}", + domainUid, miiAuxiliaryImage4, miiAuxiliaryImage5, wdtDomainNamespace); + createDomainAndVerify(domainUid, domainCR, wdtDomainNamespace, + adminServerPodName, managedServerPrefix, replicaCount); + + // check configuration for DataSource in the running domain + int adminServiceNodePort + = getServiceNodePort(wdtDomainNamespace, getExternalServicePodName(adminServerPodName), "default"); + assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid"); + assertTrue(checkSystemResourceConfig(adminServiceNodePort, + "JDBCSystemResources/TestDataSource/JDBCResource/JDBCDriverParams", + "jdbc:oracle:thin:@\\/\\/xxx.xxx.x.xxx:1521\\/ORCLCDB"), + "Can't find expected URL configuration for DataSource"); + + logger.info("Found the DataResource configuration"); + //check WDT version in the image equals the provided WDT_TEST_VERSION + + assertDoesNotThrow(() -> { + String wdtVersion = checkWDTVersion(wdtDomainNamespace, auxiliaryImagePath); + assertEquals("WebLogic Deploy Tooling " + WDT_TEST_VERSION, wdtVersion, + " Used WDT in the auxiliary image does not match the expected"); + }, "Can't retrieve wdt version file or version does match the expected"); + + //updating wdt to latest version by patching the domain with image3 + patchDomainWithAuxiliaryImageAndVerify(miiAuxiliaryImage5, miiAuxiliaryImage6, domainUid, wdtDomainNamespace); + + //check that WDT version is changed + assertDoesNotThrow(() -> { + String wdtVersion = checkWDTVersion(wdtDomainNamespace, auxiliaryImagePath); + assertNotEquals("WebLogic Deploy Tooling " + WDT_TEST_VERSION,wdtVersion, + " Used WDT in the auxiliary image was not updated"); + }, "Can't retrieve wdt version file " + + "or wdt was not updated after patching with auxiliary image"); + + // check configuration for DataSource in the running domain + adminServiceNodePort + = getServiceNodePort(wdtDomainNamespace, getExternalServicePodName(adminServerPodName), "default"); + assertNotEquals(-1, adminServiceNodePort, "admin server default node port is not valid"); + assertTrue(checkSystemResourceConfig(adminServiceNodePort, + "JDBCSystemResources/TestDataSource/JDBCResource/JDBCDriverParams", + "jdbc:oracle:thin:@\\/\\/xxx.xxx.x.xxx:1521\\/ORCLCDB"), + "Can't find expected URL configuration for DataSource"); + + } + private static void patchDomainWithAuxiliaryImageAndVerify(String oldImageName, String newImageName, String domainUid, String domainNamespace) { String adminServerPodName = domainUid + "-admin-server"; @@ -867,7 +1077,7 @@ private static void patchDomainWithAuxiliaryImageAndVerify(String oldImageName, .append(" \"path\": " + searchString + ",") .append(" \"value\": \"" + newImageName + "\"") .append(" }]"); - logger.info("Auxiliary Image patch string: " + patchStr); + logger.info("Auxiliary Image patch string: " + patchStr); //get current timestamp before domain rolling restart to verify domain roll events podsWithTimeStamps = getPodsWithTimeStamps(domainNamespace, adminServerPodName, @@ -920,6 +1130,34 @@ public void tearDownAll() { if (miiAuxiliaryImage3 != null) { deleteImage(miiAuxiliaryImage3); } + + if (miiAuxiliaryImage4 != null) { + deleteImage(miiAuxiliaryImage4); + } + + if (miiAuxiliaryImage5 != null) { + deleteImage(miiAuxiliaryImage5); + } + + if (miiAuxiliaryImage6 != null) { + deleteImage(miiAuxiliaryImage6); + } + + if (errorPathAuxiliaryImage1 != null) { + deleteImage(errorPathAuxiliaryImage1); + } + + if (errorPathAuxiliaryImage2 != null) { + deleteImage(errorPathAuxiliaryImage2); + } + + if (errorPathAuxiliaryImage3 != null) { + deleteImage(errorPathAuxiliaryImage3); + } + + if (errorPathAuxiliaryImage4 != null) { + deleteImage(errorPathAuxiliaryImage4); + } } private void createAuxiliaryImage(String stageDirPath, String dockerFileLocation, String auxiliaryImage) { @@ -970,4 +1208,14 @@ private void checkConfiguredJDBCresouce(String domainNamespace, String adminServ logger.info("Found the DataResource configuration"); } + private String checkWDTVersion(String domainNamespace, String auxiliaryImagePath) throws Exception { + assertDoesNotThrow(() -> FileUtils.deleteQuietly(Paths.get(RESULTS_ROOT, "/WDTversion.txt").toFile())); + assertDoesNotThrow(() -> copyFileFromPod(domainNamespace, + adminServerPodName, "weblogic-server", + auxiliaryImagePath + "/weblogic-deploy/VERSION.txt", + Paths.get(RESULTS_ROOT, "/WDTversion.txt")), " Can't find file in the pod, or failed to copy"); + + + return Files.readAllLines(Paths.get(RESULTS_ROOT, "/WDTversion.txt")).get(0); + } } diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/TestConstants.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/TestConstants.java index 0bfbba08603..0b95074f1c1 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/TestConstants.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/TestConstants.java @@ -240,6 +240,9 @@ public interface TestConstants { public static final String WDT_IMAGE_DOMAINHOME_BASE_DIR = "/u01/oracle/user_projects/domains"; public static final String WDT_BASIC_IMAGE_DOMAINTYPE = "wdt"; public static final String WDT_BASIC_APP_NAME = "sample-app"; + public static final String WDT_TEST_VERSION = Optional.ofNullable(System.getenv( + "WDT_TEST_VERSION")) + .orElse("1.9.15"); //monitoring constants public static final String MONITORING_EXPORTER_WEBAPP_VERSION = Optional.ofNullable(System.getenv( diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java index 01c55fb6cbd..398daea7f35 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java @@ -56,8 +56,22 @@ public static InstallParams defaultInstallWdtParams() { .location(WDT_DOWNLOAD_URL) .verify(true) .unzip(false); - } - + } + + /** + * Create an InstallParams with the default values for WDT. + * @param locationURL wdt download url + * @return an InstallParams instance + */ + public static InstallParams installWdtParams(String locationURL) { + return new InstallParams() + .defaults() + .type(WDT) + .location(locationURL) + .verify(true) + .unzip(false); + } + /** * Create an InstallParams with the default values for WIT. * @return an InstallParams instance @@ -131,44 +145,53 @@ private Installer params(InstallParams params) { * @return true if the command succeeds */ public boolean download() { - + return download(DOWNLOAD_DIR); + } + + /** + * Download and install the tool using the params. + * @param downloadDir download directory + * @return true if the command succeeds + */ + public boolean download(String downloadDir) { + boolean downloadSucceeded = true; boolean unzipSucceeded = true; if (params.verify() - && new File(DOWNLOAD_DIR, getInstallerFileName(params.type())).exists()) { + && new File(downloadDir, getInstallerFileName(params.type())).exists()) { getLogger().fine("File {0} already exists.", getInstallerFileName(params.type())); } else { - // check and make sure DOWNLOAD_DIR exists; will create it if it is missing - checkDirectory(DOWNLOAD_DIR); - + // check and make sure downloadDir exists; will create it if it is missing + checkDirectory(downloadDir); + // we are about to download the installer. We need to get the real version that is requested try { - params.location(getActualLocationIfNeeded(params.location(), params.type())); + params.location(getActualLocationIfNeeded(params.location(), params.type(), downloadDir)); } catch (RuntimeException re) { // already logged return false; } - + downloadSucceeded = Command.withParams( - defaultCommandParams() - .command(buildDownloadCommand()) + defaultCommandParams() + .command(buildDownloadCommand(downloadDir)) .redirect(params.redirect())) .execute(); } if (params.unzip()) { // only unzip WIT once if (!(doesFileExist(IMAGE_TOOL)) || !(doesFileExist(REMOTECONSOLE_FILE))) { - unzipSucceeded = unzip(); + unzipSucceeded = unzip(downloadDir); } } return downloadSucceeded && unzipSucceeded; } - private boolean unzip() { + private boolean unzip(String downloadDir) { String command = String.format( "unzip -o -d %s %s/%s", WORK_DIR, - DOWNLOAD_DIR, + downloadDir, getInstallerFileName(params.type())); return Command.withParams( @@ -178,11 +201,11 @@ private boolean unzip() { .execute(); } - private String buildDownloadCommand() { + private String buildDownloadCommand(String downloadDir) { String command = String.format( "curl -fL %s -o %s/%s", params.location(), - DOWNLOAD_DIR, + downloadDir, getInstallerFileName(params.type())); return command; } @@ -197,7 +220,8 @@ private String buildDownloadCommand() { */ private String getActualLocationIfNeeded( String location, - String type + String type, + String downloadDir ) throws RuntimeException { String actualLocation = location; if (needToGetActualLocation(location, type)) { @@ -205,7 +229,7 @@ private String getActualLocationIfNeeded( String command = String.format( "curl -fL %s -o %s/%s-%s", location, - DOWNLOAD_DIR, + downloadDir, type, TMP_FILE_NAME); @@ -227,7 +251,7 @@ private String getActualLocationIfNeeded( command = String.format( "cat %s/%s-%s | grep 'releases/download' | awk '{ split($0,a,/href=\"/);%s | %s", - DOWNLOAD_DIR, + downloadDir, type, TMP_FILE_NAME, " print a[2] }'", diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java index 2fe334d9b45..40516e48e54 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java @@ -31,8 +31,9 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static oracle.weblogic.kubernetes.actions.ActionConstants.DOWNLOAD_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_FILENAME_DEFAULT; +import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_URL; import static oracle.weblogic.kubernetes.actions.TestActions.execCommand; -import static oracle.weblogic.kubernetes.actions.impl.primitive.Installer.defaultInstallWdtParams; +import static oracle.weblogic.kubernetes.actions.impl.primitive.Installer.installWdtParams; import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; import static org.apache.commons.io.FileUtils.cleanDirectory; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -322,11 +323,21 @@ public static boolean doesFileExistInPod(String namespace, String podName, Strin * @param unzipLocation location to unzip the files */ public static void unzipWDTInstallationFile(String unzipLocation) { - Path wlDeployZipFile = Paths.get(DOWNLOAD_DIR, WDT_DOWNLOAD_FILENAME_DEFAULT); + unzipWDTInstallationFile(unzipLocation, WDT_DOWNLOAD_URL, DOWNLOAD_DIR); + } + + /** + * Download and unzip the WDT installation files. + * @param unzipLocation location to unzip the files + * @param downloadDir location to download wdt zip file + */ + public static void unzipWDTInstallationFile(String unzipLocation, String locationURL, String downloadDir) { + Path wlDeployZipFile = Paths.get(downloadDir, WDT_DOWNLOAD_FILENAME_DEFAULT); + if (!Files.exists(wlDeployZipFile)) { assertTrue(Installer.withParams( - defaultInstallWdtParams()) - .download(), "WDT download failed"); + installWdtParams(locationURL)) + .download(downloadDir), "WDT download failed"); } String cmdToExecute = String.format("unzip %s -d %s", wlDeployZipFile, unzipLocation); assertTrue(new Command()