Skip to content

Commit

Permalink
Merge branch 'xc-113809' into 'main'
Browse files Browse the repository at this point in the history
fix intermittent test failures when multiple tests download WIT at the same time

See merge request weblogic-cloud/weblogic-kubernetes-operator!4503
  • Loading branch information
rjeberhard committed Nov 20, 2023
2 parents c89c40f + 365dc37 commit 9e11b1d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,8 +34,6 @@
*/

public class Installer {
private static final String TMP_FILE_NAME = "temp-download-file.out";


private InstallParams params;

Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;


Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9e11b1d

Please sign in to comment.