Skip to content

Commit 78a49bf

Browse files
committed
add more imagetool tests
2 parents c3cc268 + 704dc9c commit 78a49bf

File tree

4 files changed

+223
-16
lines changed

4 files changed

+223
-16
lines changed

imagetool/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
<artifactId>guava</artifactId>
4545
<scope>test</scope>
4646
</dependency>
47+
<dependency>
48+
<groupId>com.github.spullara.mustache.java</groupId>
49+
<artifactId>compiler</artifactId>
50+
</dependency>
4751
</dependencies>
4852

4953
<build>

imagetool/src/test/java/com/oracle/weblogic/imagetool/integration/BaseTest.java

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
15
package com.oracle.weblogic.imagetool.integration;
26

37
import com.oracle.weblogic.imagetool.integration.utils.ExecCommand;
@@ -13,6 +17,10 @@ public class BaseTest {
1317
protected static final String VERSION = "1.0.1";
1418
protected static final String PS = File.pathSeparator;
1519
protected static final String FS = File.separator;
20+
private static final String OCIR_SERVER = "phx.ocir.io";
21+
private static final String OCIR_TENENT = "weblogick8s";
22+
protected static final String BASE_OS_IMG = "phx.ocir.io/weblogick8s/oraclelinux";
23+
protected static final String BASE_OS_IMG_TAG = "7-4imagetooltest";
1624

1725
private static String projectRoot = "";
1826
protected static String wlsImgBldDir = "";
@@ -22,6 +30,8 @@ public class BaseTest {
2230

2331

2432
protected static void initialize() throws Exception {
33+
logger.info("Initializing the tests ...");
34+
2535
projectRoot = System.getProperty("user.dir");
2636

2737
if(System.getenv("WLSIMG_BLDDIR") != null) {
@@ -48,17 +58,41 @@ protected static void initialize() throws Exception {
4858

4959
protected static void setup() throws Exception {
5060

61+
logger.info("Setting up the test ..." +
62+
"");
5163
// unzip the weblogic-image-tool/imagetool/target/imagetool-${VERSION}-SNAPSHOT.zip
52-
ExecCommand.exec("/bin/rm -rf " + getImagetoolHome());
53-
ExecCommand.exec("/bin/unzip " + getTargetDir() + FS + imagetoolZipfile);
54-
logger.info("running script " + getImagetoolHome() + FS + "bin" + FS + "setup.sh" );
55-
ExecResult result = ExecCommand.exec("source " + getImagetoolHome() + FS + "bin" + FS + "setup.sh");
56-
logger.info("DEBUG: running setup.sh ..." );
57-
logger.info(result.stderr());
58-
59-
//result = ExecCommand.exec(imagetool);
60-
//logger.info("DEBUG: running imagetool");
61-
//logger.info(result.stdout());
64+
String command = "/bin/rm -rf " + getImagetoolHome();
65+
logger.info("Executing command: " + command);
66+
ExecCommand.exec(command);
67+
68+
command = "/bin/unzip " + getTargetDir() + FS + imagetoolZipfile;
69+
logger.info("Executing command: " + command);
70+
ExecCommand.exec(command);
71+
72+
command = "source " + getImagetoolHome() + FS + "bin" + FS + "setup.sh";
73+
logger.info("Executing command: " + command );
74+
ExecResult result = ExecCommand.exec(command);
75+
}
76+
77+
protected static void pullDockerImage() throws Exception {
78+
logger.info("Pulling OS base images from OCIR ...");
79+
String ocir_username = System.getenv("OCIR_USERNAME");
80+
String ocir_password = System.getenv("OCIR_PASSWORD");
81+
82+
if(ocir_username == null || ocir_password == null) {
83+
throw new Exception("You need to set OCIR_USERNAME and OCIR_PASSWORD environment variable to pull images");
84+
}
85+
86+
ExecCommand.exec("docker login " + OCIR_SERVER + " -u " + OCIR_TENENT + "/" + ocir_username +
87+
" -p " + ocir_password);
88+
ExecCommand.exec("docker pull " + BASE_OS_IMG + ":" + BASE_OS_IMG_TAG);
89+
90+
// verify the docker image is pulled
91+
ExecResult result = ExecCommand.exec("docker images | grep " + BASE_OS_IMG + " | grep " +
92+
BASE_OS_IMG_TAG + "| wc -l");
93+
if(Integer.parseInt(result.stdout()) != 1) {
94+
throw new Exception("Base OS docker image is not pulled as expected");
95+
}
6296
}
6397

6498
protected static String getProjectRoot() {
@@ -106,4 +140,28 @@ protected ExecResult addInstallerToCache(String type, String version, String pat
106140
return result;
107141
}
108142

143+
protected ExecResult addPatchToCache(String type, String patchId, String version, String path) throws Exception {
144+
String command = imagetool + " cache addPatch --type " + type + " --patchId " + patchId + " --version " +
145+
version + " --path " + path;
146+
logger.info("Executing command: " + command);
147+
ExecResult result = ExecCommand.exec(command);
148+
logger.info(result.stdout());
149+
return result;
150+
}
151+
152+
protected ExecResult addEntryToCache(String entryKey, String entryValue) throws Exception {
153+
String command = imagetool + " cache addEntry --key " + entryKey + " --value " + entryValue;
154+
logger.info("Executing command: " + command);
155+
ExecResult result = ExecCommand.exec(command);
156+
logger.info(result.stdout());
157+
return result;
158+
}
159+
160+
protected ExecResult deleteEntryFromCache(String entryKey) throws Exception {
161+
String command = imagetool + " cache deleteEntry --key " + entryKey;
162+
logger.info("Executing command: " + command);
163+
ExecResult result = ExecCommand.exec(command);
164+
logger.info(result.stdout());
165+
return result;
166+
}
109167
}

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

Lines changed: 146 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
15
package com.oracle.weblogic.imagetool.integration;
26

37
import com.oracle.weblogic.imagetool.integration.utils.ExecCommand;
@@ -12,13 +16,23 @@
1216
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
1317
public class ITImagetool extends BaseTest {
1418

15-
19+
private static final String JDK_INSTALLER = "jdk-8u212-linux-x64.tar.gz";
20+
private static final String WLS_INSTALLER = "fmw_12.2.1.3.0_wls_Disk1_1of1.zip";
21+
private static final String P27342434_INSTALLER = "p27342434_122130_Generic.zip";
22+
private static final String P28186730_INSTALLER = "p28186730_139400_Generic.zip";
23+
private static final String TEST_ENTRY_KEY = "mytestEntryKey";
24+
private static final String P27342434_ID = "27342434";
25+
private static final String P28186730_ID = "28186730";
26+
private static final String WLS_VERSION = "12.2.1.3.0";
27+
private static final String JDK_VERSION = "8u212";
1628

1729
@BeforeClass
1830
public static void staticPrepare() throws Exception {
1931
logger.info("prepare for image tool test ...");
2032
initialize();
2133
setup();
34+
// pull base OS docker image used for test
35+
pullDockerImage();
2236
}
2337

2438
@AfterClass
@@ -45,14 +59,140 @@ public void test2CacheAddInstallerJDK() throws Exception {
4559
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
4660
logTestBegin(testMethodName);
4761

48-
String jdkPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + "jdk-8u212-linux-x64.tar.gz";
49-
ExecResult result = addInstallerToCache("jdk", "8u212", jdkPath);
50-
logger.info(result.stderr());
62+
String jdkPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + JDK_INSTALLER;
63+
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
64+
65+
ExecResult result = listItemsInCache();
66+
String expectedString = "jdk_" + JDK_VERSION + "=" + jdkPath;
67+
verifyResult(result, expectedString);
68+
69+
logTestEnd(testMethodName);
70+
}
71+
72+
@Test
73+
public void test3CacheAddInstallerWLS() throws Exception {
74+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
75+
logTestBegin(testMethodName);
76+
77+
String wlsPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + WLS_INSTALLER;
78+
addInstallerToCache("wls", WLS_VERSION, wlsPath);
79+
80+
ExecResult result = listItemsInCache();
81+
String expectedString = "wls_" + WLS_VERSION + "=" + wlsPath;
82+
verifyResult(result, expectedString);
83+
84+
logTestEnd(testMethodName);
85+
}
86+
87+
@Test
88+
public void test4CreateWLSImg() throws Exception {
89+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
90+
logTestBegin(testMethodName);
91+
92+
String command = imagetool + " create --jdkVersion=" + JDK_VERSION + " --tag imagetool:" + testMethodName;
93+
logger.info("Executing command: " + command);
94+
ExecCommand.exec(command, true);
95+
96+
// verify the docker image is created
97+
ExecResult result = ExecCommand.exec("docker images | grep imagetool | grep " + testMethodName +
98+
"| wc -l");
99+
if(Integer.parseInt(result.stdout()) != 1) {
100+
throw new Exception("wls docker image is not created as expected");
101+
}
102+
103+
logTestEnd(testMethodName);
104+
}
105+
106+
@Test
107+
public void test5CacheAddPatch() throws Exception {
108+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
109+
logTestBegin(testMethodName);
110+
111+
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER;
112+
addPatchToCache("wls", "p" + P27342434_ID, WLS_VERSION, patchPath);
113+
114+
// verify the result
115+
ExecResult result = listItemsInCache();
116+
String expectedString = P27342434_ID + "_" + WLS_VERSION + "=" + patchPath;
117+
verifyResult(result, expectedString);
118+
119+
logTestEnd(testMethodName);
120+
}
121+
122+
@Test
123+
public void test6CacheAddEntry() throws Exception {
124+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
125+
logTestBegin(testMethodName);
126+
127+
String mytestEntryValue = getProjectRoot() + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER;
128+
addEntryToCache(TEST_ENTRY_KEY, mytestEntryValue);
51129

52-
result = listItemsInCache();
53-
String expectedString = "jdk_8u212=" + jdkPath;
130+
// verify the result
131+
ExecResult result = listItemsInCache();
132+
String expectedString = TEST_ENTRY_KEY.toLowerCase() + "=" + mytestEntryValue;
54133
verifyResult(result, expectedString);
55134

56135
logTestEnd(testMethodName);
57136
}
137+
138+
@Test
139+
public void test7CacheDeleteEntry() throws Exception {
140+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
141+
logTestBegin(testMethodName);
142+
143+
deleteEntryFromCache(TEST_ENTRY_KEY);
144+
145+
// verify the result
146+
ExecResult result = listItemsInCache();
147+
if(result.exitValue() != 0 || result.stdout().contains(TEST_ENTRY_KEY)) {
148+
throw new Exception("The entry key is not deleted from the cache");
149+
}
150+
151+
logTestEnd(testMethodName);
152+
}
153+
154+
@Test
155+
public void test8CreateWLSImgUseCache() throws Exception {
156+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
157+
logTestBegin(testMethodName);
158+
159+
// need to add the required patches 28186730 for Opatch before create wls images
160+
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P28186730_INSTALLER;
161+
addPatchToCache("wls", "p" + P28186730_ID, WLS_VERSION, patchPath);
162+
163+
String command = imagetool + " create --jdkVersion " + JDK_VERSION + " --fromImage " +
164+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
165+
" --version " + WLS_VERSION + " --useCache always";
166+
logger.info("Executing command: " + command);
167+
ExecCommand.exec(command, true);
168+
169+
// verify the docker image is created
170+
ExecResult result = ExecCommand.exec("docker images | grep imagetool | grep " + testMethodName +
171+
"| wc -l");
172+
if(Integer.parseInt(result.stdout()) != 1) {
173+
throw new Exception("wls docker image is not created as expected");
174+
}
175+
176+
logTestEnd(testMethodName);
177+
}
178+
179+
@Test
180+
public void test9UpdateWLSImg() throws Exception {
181+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
182+
logTestBegin(testMethodName);
183+
184+
String command = imagetool + " update --fromImage imagetool:test8CreateWLSImgUseCache --tag imagetool:" +
185+
testMethodName + " --patches " + P27342434_ID + " --useCache always";
186+
logger.info("Executing command: " + command);
187+
ExecCommand.exec(command, true);
188+
189+
// verify the docker image is created
190+
ExecResult result = ExecCommand.exec("docker images | grep imagetool | grep " + testMethodName +
191+
"| wc -l");
192+
if(Integer.parseInt(result.stdout()) != 1) {
193+
throw new Exception("wls docker image is not created as expected");
194+
}
195+
196+
logTestEnd(testMethodName);
197+
}
58198
}

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
<artifactId>guava</artifactId>
7777
<version>19.0</version>
7878
</dependency>
79+
<dependency>
80+
<groupId>com.github.spullara.mustache.java</groupId>
81+
<artifactId>compiler</artifactId>
82+
<version>0.9.6</version>
83+
</dependency>
7984
</dependencies>
8085
</dependencyManagement>
8186

0 commit comments

Comments
 (0)