Skip to content

Commit a354c0e

Browse files
committed
add create image using wdt testcase
1 parent 1bc74ab commit a354c0e

File tree

5 files changed

+179
-24
lines changed

5 files changed

+179
-24
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ protected static void initialize() throws Exception {
4747

4848
imagetoolZipfile = "imagetool-" + VERSION + "-SNAPSHOT.zip";
4949

50-
imagetool = "java -cp " + getImagetoolHome() + FS + "lib" + FS + "imagetool.jar" + PS +
51-
getImagetoolHome() + FS + "lib" + FS + "* -Djava.util.logging.config.file=" +
50+
// imagetool = "java -cp " + getImagetoolHome() + FS + "lib" + FS + "imagetool.jar" + PS +
51+
// getImagetoolHome() + FS + "lib" + FS + "* -Djava.util.logging.config.file=" +
52+
// getImagetoolHome() + FS + "bin" + FS + "logging.properties com.oracle.weblogic.imagetool.cli.CLIDriver";
53+
imagetool = "java -cp \"" + getImagetoolHome() + FS + "lib" + FS + "*\" -Djava.util.logging.config.file=" +
5254
getImagetoolHome() + FS + "bin" + FS + "logging.properties com.oracle.weblogic.imagetool.cli.CLIDriver";
5355

5456
logger.info("DEBUG: WLSIMG_BLDDIR=" + wlsImgBldDir);
@@ -74,6 +76,14 @@ protected static void setup() throws Exception {
7476
ExecResult result = ExecCommand.exec(command);
7577
}
7678

79+
protected static void cleanup() throws Exception {
80+
logger.info("cleaning up cache entries");
81+
logger.info("executing command: /bin/rm -rf " + wlsImgCacheDir);
82+
ExecCommand.exec("/bin/rm -rf " + wlsImgCacheDir);
83+
logger.info("executing command: /bin/mkdir " + wlsImgCacheDir);
84+
ExecCommand.exec("/bin/mkdir " + wlsImgCacheDir);
85+
}
86+
7787
protected static void pullDockerImage() throws Exception {
7888
logger.info("Pulling OS base images from OCIR ...");
7989
String ocir_username = System.getenv("OCIR_USERNAME");
@@ -113,6 +123,22 @@ protected void verifyResult(ExecResult result, String matchString) throws Except
113123
}
114124
}
115125

126+
protected void verifyExitValue(ExecResult result, String command) throws Exception {
127+
if(result.exitValue() != 0) {
128+
logger.info(result.stderr());
129+
throw new Exception("executing the following command failed: " + command);
130+
}
131+
}
132+
133+
protected void verifyDockerImages(String imageTag) throws Exception {
134+
// verify the docker image is created
135+
ExecResult result = ExecCommand.exec("docker images | grep imagetool | grep " + imageTag +
136+
"| wc -l");
137+
if(Integer.parseInt(result.stdout()) != 1) {
138+
throw new Exception("wls docker image is not created as expected");
139+
}
140+
}
141+
116142
protected void logTestBegin(String testMethodName) throws Exception {
117143
logger.info("=======================================");
118144
logger.info("BEGIN test " + testMethodName + " ...");
@@ -127,6 +153,7 @@ protected ExecResult listItemsInCache() throws Exception {
127153
String command = imagetool + " cache listItems";
128154
logger.info("executing command: " + command);
129155
ExecResult result = ExecCommand.exec(command);
156+
verifyExitValue(result, command);
130157
logger.info(result.stdout());
131158
return result;
132159
}
@@ -136,15 +163,17 @@ protected ExecResult addInstallerToCache(String type, String version, String pat
136163
" --path " + path;
137164
logger.info("executing command: " + command);
138165
ExecResult result = ExecCommand.exec(command);
166+
verifyExitValue(result, command);
139167
logger.info(result.stdout());
140168
return result;
141169
}
142170

143171
protected ExecResult addPatchToCache(String type, String patchId, String version, String path) throws Exception {
144-
String command = imagetool + " cache addPatch --type " + type + " --patchId " + patchId + " --version " +
172+
String command = imagetool + " cache addPatch --type " + type + " --patchId " + patchId + "_" +
145173
version + " --path " + path;
146174
logger.info("Executing command: " + command);
147175
ExecResult result = ExecCommand.exec(command);
176+
verifyExitValue(result, command);
148177
logger.info(result.stdout());
149178
return result;
150179
}
@@ -153,6 +182,7 @@ protected ExecResult addEntryToCache(String entryKey, String entryValue) throws
153182
String command = imagetool + " cache addEntry --key " + entryKey + " --value " + entryValue;
154183
logger.info("Executing command: " + command);
155184
ExecResult result = ExecCommand.exec(command);
185+
verifyExitValue(result, command);
156186
logger.info(result.stdout());
157187
return result;
158188
}
@@ -161,6 +191,7 @@ protected ExecResult deleteEntryFromCache(String entryKey) throws Exception {
161191
String command = imagetool + " cache deleteEntry --key " + entryKey;
162192
logger.info("Executing command: " + command);
163193
ExecResult result = ExecCommand.exec(command);
194+
verifyExitValue(result, command);
164195
logger.info(result.stdout());
165196
return result;
166197
}

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

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,30 @@
1616
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
1717
public class ITImagetool extends BaseTest {
1818

19-
private static final String JDK_INSTALLER = "jdk-8u212-linux-x64.tar.gz";
19+
private static final String JDK_INSTALLER = "jdk-8u202-linux-x64.tar.gz";
2020
private static final String WLS_INSTALLER = "fmw_12.2.1.3.0_wls_Disk1_1of1.zip";
2121
private static final String P27342434_INSTALLER = "p27342434_122130_Generic.zip";
2222
private static final String P28186730_INSTALLER = "p28186730_139400_Generic.zip";
23+
private static final String WDT_INSTALLER = "weblogic-deploy.zip";
2324
private static final String TEST_ENTRY_KEY = "mytestEntryKey";
2425
private static final String P27342434_ID = "27342434";
2526
private static final String P28186730_ID = "28186730";
2627
private static final String WLS_VERSION = "12.2.1.3.0";
27-
private static final String JDK_VERSION = "8u212";
28+
private static final String OPATCH_VERSION = "13.9.4.0.0";
29+
private static final String JDK_VERSION = "8u202";
30+
private static final String WDT_VERSION = "1.1.1";
31+
private static final String WDT_ARCHIVE = "archive.zip";
32+
private static final String WDT_VARIABLES = "domain.properties";
33+
private static final String WDT_MODEL = "simple-topology.yaml";
2834

2935
@BeforeClass
3036
public static void staticPrepare() throws Exception {
3137
logger.info("prepare for image tool test ...");
38+
3239
initialize();
40+
// clean up the env first
41+
cleanup();
42+
3343
setup();
3444
// pull base OS docker image used for test
3545
pullDockerImage();
@@ -38,6 +48,7 @@ public static void staticPrepare() throws Exception {
3848
@AfterClass
3949
public static void staticUnprepare() throws Exception {
4050
logger.info("cleaning up after the test ...");
51+
cleanup();
4152
}
4253

4354
@Test
@@ -94,11 +105,7 @@ public void test4CreateWLSImg() throws Exception {
94105
ExecCommand.exec(command, true);
95106

96107
// 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-
}
108+
verifyDockerImages(testMethodName);
102109

103110
logTestEnd(testMethodName);
104111
}
@@ -109,7 +116,8 @@ public void test5CacheAddPatch() throws Exception {
109116
logTestBegin(testMethodName);
110117

111118
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER;
112-
addPatchToCache("wls", "p" + P27342434_ID, WLS_VERSION, patchPath);
119+
deleteEntryFromCache(P27342434_ID + "_" + WLS_VERSION);
120+
addPatchToCache("wls", P27342434_ID, WLS_VERSION, patchPath);
113121

114122
// verify the result
115123
ExecResult result = listItemsInCache();
@@ -158,20 +166,16 @@ public void test8CreateWLSImgUseCache() throws Exception {
158166

159167
// need to add the required patches 28186730 for Opatch before create wls images
160168
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P28186730_INSTALLER;
161-
addPatchToCache("wls", "p" + P28186730_ID, WLS_VERSION, patchPath);
169+
addPatchToCache("wls", P28186730_ID, OPATCH_VERSION, patchPath);
162170

163171
String command = imagetool + " create --jdkVersion " + JDK_VERSION + " --fromImage " +
164172
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
165-
" --version " + WLS_VERSION + " --useCache always";
173+
" --version " + WLS_VERSION;
166174
logger.info("Executing command: " + command);
167175
ExecCommand.exec(command, true);
168176

169177
// 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-
}
178+
verifyDockerImages(testMethodName);
175179

176180
logTestEnd(testMethodName);
177181
}
@@ -182,16 +186,60 @@ public void test9UpdateWLSImg() throws Exception {
182186
logTestBegin(testMethodName);
183187

184188
String command = imagetool + " update --fromImage imagetool:test8CreateWLSImgUseCache --tag imagetool:" +
185-
testMethodName + " --patches " + P27342434_ID + " --useCache always";
189+
testMethodName + " --patches " + P27342434_ID;
186190
logger.info("Executing command: " + command);
187191
ExecCommand.exec(command, true);
188192

189193
// 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-
}
194+
verifyDockerImages(testMethodName);
195+
196+
logTestEnd(testMethodName);
197+
}
198+
199+
@Test
200+
public void testACreateWLSImgUsingWDT() throws Exception {
201+
202+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
203+
logTestBegin(testMethodName);
204+
205+
// add WDT installer to the cache
206+
String wdtPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + WDT_INSTALLER;
207+
addInstallerToCache("wdt", WDT_VERSION, wdtPath);
208+
209+
// add WLS installer to the cache
210+
String wlsPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + WLS_INSTALLER;
211+
addInstallerToCache("wls", WLS_VERSION, wlsPath);
212+
213+
// add jdk installer to the cache
214+
String jdkPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + JDK_INSTALLER;
215+
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
216+
217+
// need to add the required patches 28186730 for Opatch before create wls images
218+
// delete the cache entry first
219+
deleteEntryFromCache(P28186730_ID + "_opatch");
220+
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P28186730_INSTALLER;
221+
addPatchToCache("wls", P28186730_ID, OPATCH_VERSION, patchPath);
222+
223+
// add the patch to the cache
224+
deleteEntryFromCache(P27342434_ID + "_" + WLS_VERSION);
225+
patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER;
226+
addPatchToCache("wls", P27342434_ID, WLS_VERSION, patchPath);
227+
228+
String wdtResourcePath = getProjectRoot() + FS + "src" + FS + "test" + FS + "resources" + FS + "wdt" + FS;
229+
String wdtArchive = wdtResourcePath + WDT_ARCHIVE;
230+
String wdtModel = wdtResourcePath + WDT_MODEL;
231+
String wdtVariables = wdtResourcePath + WDT_VARIABLES;
232+
String command = imagetool + " create --fromImage " +
233+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
234+
" --version " + WLS_VERSION + " --patches " + P27342434_ID + " --wdtVersion " + WDT_VERSION +
235+
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
236+
wdtModel + " --wdtVariables " + wdtVariables;
237+
238+
logger.info("Executing command: " + command);
239+
ExecCommand.exec(command, true);
240+
241+
// verify the docker image is created
242+
verifyDockerImages(testMethodName);
195243

196244
logTestEnd(testMethodName);
197245
}
1.48 KB
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# These variables are used for substitution in the WDT model file.
2+
# Any port that will be exposed through Docker is put in this file.
3+
# The sample Dockerfile will get the ports from this file and not the WDT model.
4+
DOMAIN_NAME=domain1
5+
ADMIN_PORT=7001
6+
ADMIN_NAME=admin-server
7+
ADMIN_HOST=wlsadmin
8+
MANAGED_SERVER_PORT=8001
9+
MANAGED_SERVER_NAME_BASE=managed-server-
10+
CONFIGURED_MANAGED_SERVER_COUNT=2
11+
CLUSTER_NAME=cluster-1
12+
DEBUG_PORT=8453
13+
DEBUG_FLAG=true
14+
PRODUCTION_MODE_ENABLED=true
15+
CLUSTER_TYPE=DYNAMIC
16+
JAVA_OPTIONS=-Dweblogic.StdoutDebugEnabled=false
17+
T3_CHANNEL_PORT=30012
18+
T3_PUBLIC_ADDRESS=kubernetes
19+
SERVER_START_MODE=prod
20+
CLUSTER_ADMIN=cluster-1,admin-server
21+
# Derby Data Source parameters
22+
dsname=DockerDS
23+
dsdbname=DerbyDB;create=true
24+
dsjndiname=DockerDS
25+
dsdriver=org.apache.derby.jdbc.ClientXADataSource
26+
dsurl=jdbc:derby://localhost:1527/DerbyDB;create=true
27+
dbusername=dba
28+
dbpassword=dba1
29+
dstestquery=SQL SELECT 1 FROM SYS.SYSTABLES
30+
dsinitalcapacity=1
31+
dsmaxcapacity=15
32+
33+
34+
35+
36+
37+
#Derby Data Source parameters
38+
dsname=DockerDS
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
domainInfo:
2+
AdminUserName: weblogic
3+
AdminPassword: welcome1
4+
ServerStartMode: '@@PROP:SERVER_START_MODE@@'
5+
topology:
6+
Name: '@@PROP:DOMAIN_NAME@@'
7+
AdminServerName: '@@PROP:ADMIN_NAME@@'
8+
ProductionModeEnabled: '@@PROP:PRODUCTION_MODE_ENABLED@@'
9+
Cluster:
10+
'@@PROP:CLUSTER_NAME@@':
11+
ClientCertProxyEnabled: true
12+
DynamicServers:
13+
ServerTemplate: template1
14+
CalculatedListenPorts: false
15+
ServerNamePrefix: '@@PROP:MANAGED_SERVER_NAME_BASE@@'
16+
DynamicClusterSize: '@@PROP:CONFIGURED_MANAGED_SERVER_COUNT@@'
17+
MaxDynamicClusterSize: '@@PROP:CONFIGURED_MANAGED_SERVER_COUNT@@'
18+
Server:
19+
'@@PROP:ADMIN_NAME@@':
20+
ListenPort: '@@PROP:ADMIN_PORT@@'
21+
NetworkAccessPoint:
22+
T3Channel:
23+
ListenAddress: None
24+
ListenPort: '@@PROP:T3_CHANNEL_PORT@@'
25+
PublicAddress: '@@PROP:T3_PUBLIC_ADDRESS@@'
26+
PublicPort: '@@PROP:T3_CHANNEL_PORT@@'
27+
ServerTemplate:
28+
template1:
29+
ListenPort: '@@PROP:MANAGED_SERVER_PORT@@'
30+
appDeployments:
31+
Application:
32+
# Quote needed because of hyphen in string
33+
'simple-app':
34+
SourcePath: 'wlsdeploy/applications/simple-app.war'
35+
Target: '@@PROP:CLUSTER_NAME@@'
36+
ModuleType: war
37+
StagingMode: nostage
38+
PlanStagingMode: nostage

0 commit comments

Comments
 (0)