From 365dc37873b8e7593a92cf19f9b16e840fec0c2c Mon Sep 17 00:00:00 2001 From: xian_cao Date: Mon, 20 Nov 2023 23:32:05 +0000 Subject: [PATCH] fix intermittent test failures when multiple tests download WIT at the same time --- .../actions/impl/primitive/Installer.java | 7 +- .../impl/primitive/WebLogicImageTool.java | 86 +++++++++++-------- .../weblogic/kubernetes/utils/ImageUtils.java | 55 ++++++++---- 3 files changed, 92 insertions(+), 56 deletions(-) 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 6246de1572f..da9def10920 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 @@ -1,4 +1,4 @@ -// Copyright (c) 2020, 2021, Oracle and/or its affiliates. +// Copyright (c) 2020, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.weblogic.kubernetes.actions.impl.primitive; @@ -34,8 +34,6 @@ */ public class Installer { - private static final String TMP_FILE_NAME = "temp-download-file.out"; - private InstallParams params; @@ -189,7 +187,8 @@ && new File(downloadDir, getInstallerFileName(params.type())).exists()) { } if (params.unzip()) { // only unzip WIT once - if (!(doesFileExist(IMAGE_TOOL)) || !(doesFileExist(REMOTECONSOLE_FILE))) { + if ((params.type().equalsIgnoreCase(WIT) && !(doesFileExist(IMAGE_TOOL))) + || (params.type().equalsIgnoreCase(REMOTECONSOLE) && !(doesFileExist(REMOTECONSOLE_FILE)))) { unzipSucceeded = unzip(downloadDir); } } diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java index ba5d3cf5609..f55206814c5 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java @@ -1,4 +1,4 @@ -// Copyright (c) 2020, 2022, Oracle and/or its affiliates. +// Copyright (c) 2020, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.weblogic.kubernetes.actions.impl.primitive; @@ -22,6 +22,8 @@ import static oracle.weblogic.kubernetes.actions.impl.primitive.Installer.defaultInstallWdtParams; import static oracle.weblogic.kubernetes.actions.impl.primitive.Installer.defaultInstallWitParams; import static oracle.weblogic.kubernetes.actions.impl.primitive.Installer.installWdtParams; +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil; +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withStandardRetryPolicy; import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; @@ -96,34 +98,44 @@ public boolean updateImage() { public String inspectImage(String imageName, String imageTag) { String output = null; // download WIT if it is not in the expected location - if (!downloadWit()) { - return output; - } + testUntil( + withStandardRetryPolicy, + () -> downloadWit(), + getLogger(), + "downloading WIT succeeds"); // download WDT if it is not in the expected location - if (!downloadWdt()) { - return output; - } + testUntil( + withStandardRetryPolicy, + () -> downloadWdt(), + getLogger(), + "downloading WDT succeeds"); // delete the old cache entry for the WDT installer - if (!deleteEntry()) { - return output; - } + testUntil( + withStandardRetryPolicy, + () -> deleteEntry(), + getLogger(), + "deleting cache entry for WDT installer succeeds"); // add the WDT installer that we just downloaded into WIT cache entry - if (!addInstaller()) { - return output; - } + testUntil( + withStandardRetryPolicy, + () -> addInstaller(), + getLogger(), + "adding WDT installer to the cache succeeds"); + ExecResult result = Command.withParams( defaultCommandParams() .command(buildInspectWitCommand(imageName, imageTag)) .redirect(params.redirect())) .executeAndReturnResult(); - // check exitValue to determine if the command execution has failed. + // check exitValue to determine if the command execution has failed. if (result.exitValue() != 0) { getLogger().severe("The command execution failed because it returned non-zero exit value: {0}.", result); + output = result.stderr(); } else { getLogger().info("The command execution succeeded with result: {0}.", result); output = result.stdout(); @@ -339,35 +351,41 @@ public boolean createAuxImage() { */ public ExecResult createAuxImageAndReturnResult() { // download WIT if it is not in the expected location - if (!downloadWit()) { - return new ExecResult(1, "failed to download WIT", "failed to download WIT"); - } + testUntil( + withStandardRetryPolicy, + () -> downloadWit(), + getLogger(), + "downloading WIT succeeds"); // download WDT if it is not in the expected location if (params.wdtVersion() != null && !Objects.equals(params.wdtVersion(), "NONE")) { - if (!downloadWdt(params.wdtVersion())) { - return new ExecResult(1, "failed to download WDT with version " + params.wdtVersion(), - "failed to download WDT with version " + params.wdtVersion()); - - } + testUntil( + withStandardRetryPolicy, + () -> downloadWdt(params.wdtVersion()), + getLogger(), + "downloading WDT with version {0} succeeds", + params.wdtVersion()); } else { - if (!downloadWdt()) { - return new ExecResult(1, "failed to download latest WDT", - "failed to download latest WDT"); - } + testUntil( + withStandardRetryPolicy, + () -> downloadWdt(), + getLogger(), + "downloading latest WDT succeeds"); } // delete the old cache entry for the WDT installer - if (!deleteEntry()) { - return new ExecResult(1, "failed to delete cache entry for the WDT installer", - "failed to delete cache entry for the WDT installer"); - } + testUntil( + withStandardRetryPolicy, + () -> deleteEntry(), + getLogger(), + "deleting cache entry for WDT installer succeeds"); // add the WDT installer that we just downloaded into WIT cache entry - if (!addInstaller()) { - return new ExecResult(1, "failed to add WDT installer to the cache", - "failed to add WDT installer to the cache"); - } + testUntil( + withStandardRetryPolicy, + () -> addInstaller(), + getLogger(), + "adding WDT installer to the cache succeeds"); return Command.withParams( defaultCommandParams() diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ImageUtils.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ImageUtils.java index 2a1fbc39262..eb10dc0faa4 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ImageUtils.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ImageUtils.java @@ -62,6 +62,7 @@ import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getDateAndTimeStamp; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil; +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withStandardRetryPolicy; import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -421,24 +422,34 @@ public static String createImageAndVerify(String imageNameBase, // build an image using WebLogic Image Tool logger.info("Creating image {0} using model directory {1}", image, MODEL_DIR); boolean result = false; + if (!modelType) { //create a domain home in image image - result = createImage( - new WitParams() - .baseImageName(baseImageName) - .baseImageTag(baseImageTag) - .domainType(domainType) - .modelImageName(imageName) - .modelImageTag(imageTag) - .modelFiles(wdtModelList) - .modelVariableFiles(modelPropList) - .modelArchiveFiles(archiveList) - .domainHome(WDT_IMAGE_DOMAINHOME_BASE_DIR + "/" + domainHome) - .wdtModelOnly(modelType) - .wdtOperation("CREATE") - .wdtVersion(WDT_VERSION) - .target(witTarget) - .env(env) - .redirect(true)); + WitParams witParams = new WitParams() + .baseImageName(baseImageName) + .baseImageTag(baseImageTag) + .domainType(domainType) + .modelImageName(imageName) + .modelImageTag(imageTag) + .modelFiles(wdtModelList) + .modelVariableFiles(modelPropList) + .modelArchiveFiles(archiveList) + .domainHome(WDT_IMAGE_DOMAINHOME_BASE_DIR + "/" + domainHome) + .wdtModelOnly(modelType) + .wdtOperation("CREATE") + .wdtVersion(WDT_VERSION) + .target(witTarget) + .env(env) + .redirect(true); + + testUntil( + withStandardRetryPolicy, + () -> createImage(witParams), + getLogger(), + "creating image {0}:{1} succeeds", + imageName, + imageTag); + + result = true; } else { WitParams witParams = new WitParams() .baseImageName(baseImageName) @@ -470,7 +481,15 @@ public static String createImageAndVerify(String imageNameBase, witParams.target("OpenShift"); } - result = createImage(witParams); + testUntil( + withStandardRetryPolicy, + () -> createImage(witParams), + getLogger(), + "creating image {0}:{1} succeeds", + imageName, + imageTag); + + result = true; } assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image));