Skip to content

Commit a5935c2

Browse files
authored
Fix regression with UPDATE where WDT install could not be overwritten (#294)
* Add WDT version and home to inspect output * Fix regression with UPDATE where WDT install could not be overwritten. Overwrite is insufficient due to the compiled python. * Add test to prevent regression
1 parent a8cd71a commit a5935c2

File tree

7 files changed

+165
-41
lines changed

7 files changed

+165
-41
lines changed

imagetool/src/main/resources/docker-files/Create_Image.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ ENV ORACLE_HOME={{{oracle_home}}} \
3333
{{/installJava}}
3434
{{#isWdtEnabled}}
3535
DOMAIN_HOME={{{domain_home}}} \
36+
WDT_HOME={{{wdt_home}}} \
3637
{{#modelOnly}}
3738
WDT_MODEL_HOME={{{wdt_model_home}}} \
3839
{{/modelOnly}}
3940
{{/isWdtEnabled}}
40-
PATH=${PATH}:{{{java_home}}}/bin:{{{oracle_home}}}/oracle_common/common/bin:{{{oracle_home}}}/wlserver/common/bin:{{{oracle_home}}}{{#isWdtEnabled}}:{{{domain_home}}}/bin{{/isWdtEnabled}}
41+
PATH=${PATH}:{{{java_home}}}/bin:{{{oracle_home}}}/oracle_common/common/bin:{{{oracle_home}}}/wlserver/common/bin:{{{oracle_home}}}{{#isWdtEnabled}}:{{{domain_home}}}/bin
42+
{{/isWdtEnabled}}
4143

4244
LABEL com.oracle.weblogic.imagetool.buildid="{{buildId}}"
4345

imagetool/src/main/resources/docker-files/Update_Image.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ USER root
1212
ENV OPATCH_NO_FUSER=true
1313

1414
{{#isWdtEnabled}}
15-
ENV DOMAIN_HOME={{{domain_home}}} \
15+
ENV DOMAIN_HOME={{{domain_home}}} \
16+
WDT_HOME={{{wdt_home}}} \
1617
{{#modelOnly}}
1718
WDT_MODEL_HOME={{{wdt_model_home}}} \
1819
{{/modelOnly}}

imagetool/src/main/resources/docker-files/run-wdt.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ RUN cd {{{wdt_home}}} \
3636
{{{.}}}
3737
{{/beforeWdtCommand}}
3838

39+
RUN test -d {{{wdt_home}}}/weblogic-deploy && rm -rf {{{wdt_home}}}/weblogic-deploy || echo Initial WDT install \
3940
{{#usingWdtTarGzInstaller}}
40-
RUN tar zxf {{{tempDir}}}/{{{wdtInstaller}}} -C {{{wdt_home}}}
41+
&& tar zxf {{{tempDir}}}/{{{wdtInstaller}}} -C {{{wdt_home}}}
4142
{{/usingWdtTarGzInstaller}}
4243
{{^usingWdtTarGzInstaller}}
43-
RUN unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}}
44+
&& unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}}
4445
{{/usingWdtTarGzInstaller}}
4546

4647
{{^modelOnly}}

imagetool/src/main/resources/probe-env/inspect-image-long.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ if [ -n "$WDT_MODEL_HOME" ]; then
3737
echo wdtModelHome="$WDT_MODEL_HOME"
3838
fi
3939

40+
if [ -n "$WDT_HOME" ]; then
41+
echo wdtHome="$WDT_HOME"
42+
echo wdtVersion="$(cat $WDT_HOME/weblogic-deploy/VERSION.txt | sed 's/.* //')"
43+
elif [ -f "/u01/wdt/weblogic-deploy/VERSION.txt" ]; then
44+
echo wdtHome="/u01/wdt"
45+
echo wdtVersion="$(cat /u01/wdt/weblogic-deploy/VERSION.txt | sed 's/.* //')"
46+
fi
4047

4148
if [ -n "$ORACLE_HOME" ]; then
4249
echo oracleHome="$ORACLE_HOME"

imagetool/src/main/resources/probe-env/inspect-image.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ if [ -n "$WDT_MODEL_HOME" ]; then
3737
echo wdtModelHome="$WDT_MODEL_HOME"
3838
fi
3939

40+
if [ -n "$WDT_HOME" ]; then
41+
echo wdtHome="$WDT_HOME"
42+
echo wdtVersion="$(cat $WDT_HOME/weblogic-deploy/VERSION.txt | sed 's/.* //')"
43+
elif [ -f "/u01/wdt/weblogic-deploy/VERSION.txt" ]; then
44+
echo wdtHome="/u01/wdt"
45+
echo wdtVersion="$(cat /u01/wdt/weblogic-deploy/VERSION.txt | sed 's/.* //')"
46+
fi
4047

4148
if [ -n "$ORACLE_HOME" ]; then
4249
echo oracleHome="$ORACLE_HOME"

tests/src/test/java/com/oracle/weblogic/imagetool/tests/ITImagetool.java

Lines changed: 101 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,28 @@ private static String getMethodName(TestInfo testInfo) {
264264

265265
}
266266

267+
private static CommandResult executeAndVerify(String command) throws Exception {
268+
logger.info("Executing command: " + command);
269+
CommandResult result = Runner.run(command);
270+
assertEquals(0, result.exitValue(), "for command: " + command);
271+
logger.info(result.stdout());
272+
return result;
273+
}
274+
275+
/**
276+
* Determine if a Docker image exists on the local system.
277+
*/
278+
private static boolean imageExists(String imageTag) throws IOException, InterruptedException {
279+
return !getImageId(imageTag).isEmpty();
280+
}
281+
282+
/**
283+
* Get the docker identifier for this image tag.
284+
*/
285+
private static String getImageId(String imageTag) throws IOException, InterruptedException {
286+
return Runner.run("docker images -q " + imageTag).stdout().trim();
287+
}
288+
267289
private void verifyFileInImage(String imagename, String filename, String expectedContent) throws Exception {
268290
logger.info("verifying the file content in image");
269291
String command = "docker run --rm " + imagename + " bash -c 'cat " + filename + "'";
@@ -289,14 +311,6 @@ private void createDBContainer() throws Exception {
289311
checkCmdInLoop(command);
290312
}
291313

292-
private static CommandResult executeAndVerify(String command) throws Exception {
293-
logger.info("Executing command: " + command);
294-
CommandResult result = Runner.run(command);
295-
assertEquals(0, result.exitValue(), "for command: " + command);
296-
logger.info(result.stdout());
297-
return result;
298-
}
299-
300314
/**
301315
* Test caching of an installer of type JDK.
302316
*
@@ -538,8 +552,8 @@ void createWlsImg(TestInfo testInfo) throws Exception {
538552
assertEquals(0, result.exitValue(), "for command: " + command);
539553

540554
// verify the docker image is created
541-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
542-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
555+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
556+
543557
wlsImgBuilt = true;
544558
}
545559
}
@@ -568,8 +582,8 @@ void updateWlsImg(TestInfo testInfo) throws Exception {
568582
assertEquals(0, result.exitValue(), "for command: " + command);
569583

570584
// verify the docker image is created
571-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
572-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
585+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
586+
573587
// TODO should check that patch and OPatch were applied
574588
}
575589
}
@@ -603,8 +617,8 @@ void createWlsImgUsingWdt(TestInfo testInfo) throws Exception {
603617
assertEquals(0, result.exitValue(), "for command: " + command);
604618

605619
// verify the docker image is created
606-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
607-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
620+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
621+
608622
domainImgBuilt = true;
609623
}
610624
}
@@ -633,8 +647,7 @@ void rebaseWlsImg(TestInfo testInfo) throws Exception {
633647
assertEquals(0, result.exitValue(), "for command: " + command);
634648

635649
// verify the docker image is created
636-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
637-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
650+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
638651
}
639652
}
640653

@@ -688,8 +701,7 @@ void createFmwImgFullInternetAccess(TestInfo testInfo) throws Exception {
688701
assertEquals(0, result.exitValue(), "for command: " + command);
689702

690703
// verify the docker image is created
691-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
692-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
704+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
693705
}
694706
}
695707

@@ -744,8 +756,7 @@ void createJrfDomainImgUsingWdt(TestInfo testInfo) throws Exception {
744756
assertEquals(0, result.exitValue(), "for command: " + command);
745757

746758
// verify the docker image is created
747-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
748-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
759+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
749760
}
750761
}
751762

@@ -784,8 +795,7 @@ void createRestrictedJrfDomainImgUsingWdt(TestInfo testInfo) throws Exception {
784795
assertEquals(0, result.exitValue(), "for command: " + command);
785796

786797
// verify the docker image is created
787-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
788-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
798+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
789799
}
790800
}
791801

@@ -821,8 +831,7 @@ void createWlsImgUsingMultiModels(TestInfo testInfo) throws Exception {
821831
assertEquals(0, result.exitValue(), "for command: " + command);
822832

823833
// verify the docker image is created
824-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
825-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
834+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
826835
}
827836
}
828837

@@ -851,8 +860,7 @@ void createWlsImgWithAdditionalBuildCommands(TestInfo testInfo) throws Exception
851860
assertEquals(0, result.exitValue(), "for command: " + command);
852861

853862
// verify the docker image is created
854-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
855-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
863+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
856864
}
857865

858866
// verify the file created in [before-jdk-install] section
@@ -891,8 +899,7 @@ void createImageWithServerJRE(TestInfo testInfo) throws Exception {
891899
assertEquals(0, result.exitValue(), "for command: " + command);
892900

893901
// verify the docker image is created
894-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
895-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
902+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
896903
}
897904
}
898905

@@ -919,8 +926,7 @@ void updateImageWithServerJRE(TestInfo testInfo) throws Exception {
919926
assertEquals(0, result.exitValue(), "for command: " + command);
920927

921928
// verify the docker image is created
922-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
923-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
929+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
924930
}
925931
}
926932

@@ -962,8 +968,7 @@ void createMiiOl8slim(TestInfo testInfo) throws Exception {
962968
assertEquals(0, result.exitValue(), "for command: " + command);
963969

964970
// verify the docker image is created
965-
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
966-
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
971+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
967972

968973
validateDirectoryPermissions("/u01/domains", "drwxrwxr-x", tagName, out);
969974
validateDirectoryPermissions("/u01/wdt", "drwxrwxr-x", tagName, out);
@@ -991,4 +996,68 @@ private void validateDirectoryPermissions(String directory, String expected, Str
991996
// When running on an SELinux host, the permissions shown by ls will end with a "."
992997
assertTrue(tokens[0].startsWith(expected), "Incorrect directory permissions for " + directory);
993998
}
999+
1000+
/**
1001+
* update a WLS image with a model.
1002+
*
1003+
* @throws Exception - if any error occurs
1004+
*/
1005+
@Test
1006+
@Order(28)
1007+
@Tag("nightly")
1008+
@DisplayName("Use Update to add a WDT model to createWlsImg")
1009+
void updateAddModel(TestInfo testInfo) throws Exception {
1010+
assumeTrue(wlsImgBuilt);
1011+
1012+
String tagName = build_tag + ":" + getMethodName(testInfo);
1013+
String command = new UpdateCommand()
1014+
.fromImage(build_tag + ":createWlsImg") //from step 10, createWlsImg()
1015+
.tag(tagName)
1016+
.wdtVersion(WDT_VERSION)
1017+
.wdtModel(WDT_MODEL)
1018+
.wdtVariables(WDT_VARIABLES)
1019+
.wdtArchive(WDT_ARCHIVE)
1020+
.wdtModelOnly(true)
1021+
.build();
1022+
1023+
try (PrintWriter out = getTestMethodWriter(testInfo)) {
1024+
CommandResult result = Runner.run(command, out, logger);
1025+
assertEquals(0, result.exitValue(), "for command: " + command);
1026+
1027+
// verify the docker image is created
1028+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
1029+
}
1030+
}
1031+
1032+
/**
1033+
* update a WLS image with another model.
1034+
*
1035+
* @throws Exception - if any error occurs
1036+
*/
1037+
@Test
1038+
@Order(29)
1039+
@Tag("nightly")
1040+
@DisplayName("Use Update to add a second WDT model to createWlsImg")
1041+
void updateAddSecondModel(TestInfo testInfo) throws Exception {
1042+
String testFromImage = build_tag + ":updateAddModel";
1043+
// skip this test if updateAddModel() failed to create an image
1044+
assumeTrue(imageExists(testFromImage));
1045+
1046+
String tagName = build_tag + ":" + getMethodName(testInfo);
1047+
String command = new UpdateCommand()
1048+
.fromImage(testFromImage)
1049+
.tag(tagName)
1050+
.wdtVersion(WDT_VERSION)
1051+
.wdtModel(WDT_MODEL2)
1052+
.wdtModelOnly(true)
1053+
.build();
1054+
1055+
try (PrintWriter out = getTestMethodWriter(testInfo)) {
1056+
CommandResult result = Runner.run(command, out, logger);
1057+
assertEquals(0, result.exitValue(), "for command: " + command);
1058+
1059+
// verify the docker image is created
1060+
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
1061+
}
1062+
}
9941063
}

tests/src/test/java/com/oracle/weblogic/imagetool/tests/utils/UpdateCommand.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33

44
package com.oracle.weblogic.imagetool.tests.utils;
55

6+
import java.nio.file.Path;
7+
import java.util.Arrays;
8+
import java.util.stream.Collectors;
9+
610
public class UpdateCommand extends ImageToolCommand {
711

812
private String fromImage;
913
private String tag;
1014
private String patches;
1115

16+
// WDT flags
17+
private String wdtVersion;
18+
private String wdtModel;
19+
private String wdtArchive;
20+
private String wdtVariables;
21+
private boolean wdtModelOnly;
22+
1223
public UpdateCommand() {
1324
super("update");
1425
}
@@ -23,15 +34,36 @@ public UpdateCommand tag(String value) {
2334
return this;
2435
}
2536

26-
public UpdateCommand tag(String name, String version) {
27-
return tag(name + ":" + version);
28-
}
29-
3037
public UpdateCommand patches(String... values) {
3138
patches = String.join(",", values);
3239
return this;
3340
}
3441

42+
public UpdateCommand wdtVersion(String value) {
43+
wdtVersion = value;
44+
return this;
45+
}
46+
47+
public UpdateCommand wdtModel(Path... values) {
48+
wdtModel = Arrays.stream(values).map(Path::toString).collect(Collectors.joining(","));
49+
return this;
50+
}
51+
52+
public UpdateCommand wdtArchive(Path value) {
53+
wdtArchive = value.toString();
54+
return this;
55+
}
56+
57+
public UpdateCommand wdtVariables(Path value) {
58+
wdtVariables = value.toString();
59+
return this;
60+
}
61+
62+
public UpdateCommand wdtModelOnly(boolean value) {
63+
wdtModelOnly = value;
64+
return this;
65+
}
66+
3567
/**
3668
* Generate the command using the provided command line options.
3769
* @return the imagetool command as a string suitable for running in ProcessBuilder
@@ -40,6 +72,11 @@ public String build() {
4072
return super.build()
4173
+ field("--fromImage", fromImage)
4274
+ field("--tag", tag)
43-
+ field("--patches", patches);
75+
+ field("--patches", patches)
76+
+ field("--wdtVersion", wdtVersion)
77+
+ field("--wdtModel", wdtModel)
78+
+ field("--wdtArchive", wdtArchive)
79+
+ field("--wdtVariables", wdtVariables)
80+
+ field("--wdtModelOnly", wdtModelOnly);
4481
}
4582
}

0 commit comments

Comments
 (0)