Skip to content

Commit dbb4ca0

Browse files
committed
add multiple WDT model file usecase
1 parent 444cf87 commit dbb4ca0

File tree

4 files changed

+140
-44
lines changed

4 files changed

+140
-44
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class BaseTest {
2525
protected static final String BASE_OS_IMG_TAG = "7-4imagetooltest";
2626
protected static final String ORACLE_DB_IMG = "container-registry.oracle.com/database/enterprise";
2727
protected static final String ORACLE_DB_IMG_TAG = "12.2.0.1-slim";
28+
private static final String DB_CONTAINER_NAME = "InfraDB";
2829
private static String projectRoot = "";
2930
protected static String wlsImgBldDir = "";
3031
protected static String wlsImgCacheDir = "";
@@ -82,6 +83,8 @@ protected static void cleanup() throws Exception {
8283
executeNoVerify(command);
8384

8485
// clean up the docker images
86+
command = "docker stop " + DB_CONTAINER_NAME;
87+
executeNoVerify(command);
8588
command = "docker rmi -f " + BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " " + ORACLE_DB_IMG + ":" +
8689
ORACLE_DB_IMG_TAG;
8790
executeNoVerify(command);
@@ -97,7 +100,8 @@ protected static void pullBaseOSDockerImage() throws Exception {
97100
String ocir_password = System.getenv("OCIR_PASSWORD");
98101

99102
if(ocir_username == null || ocir_password == null) {
100-
throw new Exception("You need to set OCIR_USERNAME and OCIR_PASSWORD environment variable to pull images");
103+
throw new Exception("You need to set OCIR_USERNAME and OCIR_PASSWORD environment variable to pull base" +
104+
" OS image " + BASE_OS_IMG + ":" + BASE_OS_IMG_TAG);
101105
}
102106

103107
pullDockerImage(OCIR_SERVER, OCIR_TENENT + "/" + ocir_username , ocir_password, BASE_OS_IMG,
@@ -110,7 +114,8 @@ protected static void pullOracleDBDockerImage() throws Exception {
110114
String ocr_password = System.getenv("OCR_PASSWORD");
111115

112116
if(ocr_username == null || ocr_password == null) {
113-
throw new Exception("You need to set OCR_USERNAME and OCR_PASSWORD environment variable to pull images");
117+
throw new Exception("You need to set OCR_USERNAME and OCR_PASSWORD environment variable to pull DB " +
118+
"image " + ORACLE_DB_IMG + ":" + ORACLE_DB_IMG_TAG);
114119
}
115120

116121
pullDockerImage(OCR_SERVER, ocr_username, ocr_password, ORACLE_DB_IMG, ORACLE_DB_IMG_TAG);
@@ -123,14 +128,21 @@ protected static void downloadInstallers(String... installers) throws Exception
123128
cacheDir.mkdir();
124129
}
125130

131+
boolean missingInstaller = false;
132+
StringBuffer errorMsg = new StringBuffer();
133+
errorMsg.append("The test installers are missing. Please download: \n");
126134
// check the required installer is downloaded
127135
for(String installer : installers) {
128136
File installFile = new File(getInstallerCacheDir() + FS + installer);
129137
if(!installFile.exists()) {
130-
throw new Exception("Please download " + installer + " from oracle support site and put it in " +
131-
getInstallerCacheDir());
138+
missingInstaller = true;
139+
errorMsg.append( " " + installer + "\n");
132140
}
133141
}
142+
errorMsg.append("and put them in " + getInstallerCacheDir());
143+
if(missingInstaller) {
144+
throw new Exception(errorMsg.toString());
145+
}
134146
}
135147

136148
protected static String getProjectRoot() {
@@ -175,7 +187,7 @@ protected void verifyDockerImages(String imageTag) throws Exception {
175187
// verify the docker image is created
176188
ExecResult result = ExecCommand.exec("docker images | grep imagetool | grep " + imageTag +
177189
"| wc -l");
178-
if(Integer.parseInt(result.stdout()) != 1) {
190+
if(Integer.parseInt(result.stdout().trim()) != 1) {
179191
throw new Exception("wls docker image is not created as expected");
180192
}
181193
}
@@ -225,15 +237,15 @@ protected ExecResult buildWDTArchive() throws Exception {
225237

226238
protected void createDBContainer() throws Exception {
227239
logger.info("Creating an Oracle db docker container ...");
228-
String command = "docker rm -f InfraDB";
240+
String command = "docker rm -f " + DB_CONTAINER_NAME;
229241
ExecCommand.exec(command);
230-
command = "docker run -d --name InfraDB -p 1521:1521 -p 5500:5500 --env=\"DB_PDB=InfraPDB1\"" +
242+
command = "docker run -d --name " + DB_CONTAINER_NAME + " -p 1521:1521 -p 5500:5500 --env=\"DB_PDB=InfraPDB1\"" +
231243
" --env=\"DB_DOMAIN=us.oracle.com\" --env=\"DB_BUNDLE=basic\" " + ORACLE_DB_IMG + ":" +
232244
ORACLE_DB_IMG_TAG;
233245
ExecCommand.exec(command);
234246

235247
// wait for the db is ready
236-
command = "docker ps | grep InfraDB";
248+
command = "docker ps | grep " + DB_CONTAINER_NAME;
237249
checkCmdInLoop(command, "healthy");
238250
}
239251

@@ -264,7 +276,7 @@ private static void pullDockerImage(String repoServer, String username, String p
264276
// verify the docker image is pulled
265277
ExecResult result = ExecCommand.exec("docker images | grep " + imagename + " | grep " +
266278
imagetag + "| wc -l");
267-
if(Integer.parseInt(result.stdout()) != 1) {
279+
if(Integer.parseInt(result.stdout().trim()) != 1) {
268280
throw new Exception("docker image " + imagename + ":" + imagetag + " is not pulled as expected");
269281
}
270282
}

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

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import org.junit.FixMethodOrder;
1313
import org.junit.runners.MethodSorters;
1414

15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
import java.nio.file.Paths;
18+
import java.nio.file.StandardCopyOption;
1519

1620
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
1721
public class ITImagetool extends BaseTest {
@@ -39,6 +43,11 @@ public class ITImagetool extends BaseTest {
3943
private static final String WDT_VARIABLES = "domain.properties";
4044
private static final String WDT_MODEL = "simple-topology.yaml";
4145
private static final String WDT_MODEL1 = "simple-topology1.yaml";
46+
private static final String WDT_MODEL2 = "simple-topology2.yaml";
47+
private static String oracleSupportUsername;
48+
private static String oracleSupportPassword;
49+
private static String httpProxy;
50+
private static String httpsProxy;
4251

4352
@BeforeClass
4453
public static void staticPrepare() throws Exception {
@@ -51,16 +60,33 @@ public static void staticPrepare() throws Exception {
5160
setup();
5261
// pull base OS docker image used for test
5362
pullBaseOSDockerImage();
63+
// pull oracle db image
64+
pullOracleDBDockerImage();
5465

5566
// download the installers for the test
5667
downloadInstallers(JDK_INSTALLER, WLS_INSTALLER, WDT_INSTALLER, P27342434_INSTALLER, P28186730_INSTALLER,
57-
FMW_INSTALLER);
68+
FMW_INSTALLER, JDK_INSTALLER_8u212, FMW_INSTALLER_1221, P22987840_INSTALLER);
69+
70+
// get Oracle support credentials
71+
oracleSupportUsername = System.getenv("ORACLE_SUPPORT_USERNAME");
72+
oracleSupportPassword = System.getenv("ORACLE_SUPPORT_PASSWORD");
73+
if(oracleSupportUsername == null || oracleSupportPassword == null) {
74+
throw new Exception("Please set environment variables ORACLE_SUPPORT_USERNAME and ORACLE_SUPPORT_PASSWORD" +
75+
" for Oracle Support credentials to download the patches.");
76+
}
77+
78+
// get http proxy
79+
httpProxy = System.getenv("HTTP_PROXY");
80+
httpsProxy = System.getenv("HTTPS_PROXY");
81+
if(httpProxy == null || httpsProxy == null) {
82+
throw new Exception("Please set environment variable HTTP_PROXY and HTTPS_PROXY");
83+
}
5884
}
5985

6086
@AfterClass
6187
public static void staticUnprepare() throws Exception {
6288
logger.info("cleaning up after the test ...");
63-
cleanup();
89+
//cleanup();
6490
}
6591

6692
/**
@@ -315,19 +341,6 @@ public void testBCreateFMWImgFullInternetAccess() throws Exception {
315341
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
316342
logTestBegin(testMethodName);
317343

318-
String user = System.getenv("ORACLE_SUPPORT_USERNAME");
319-
String password = System.getenv("ORACLE_SUPPORT_PASSWORD");
320-
if(user == null || password == null) {
321-
throw new Exception("Please set environment variables ORACLE_SUPPORT_USERNAME and ORACLE_SUPPORT_PASSWORD" +
322-
" for Oracle Support credentials to download the patches.");
323-
}
324-
325-
String httpProxy = System.getenv("HTTP_PROXY");
326-
String httpsProxy = System.getenv("HTTPS_PROXY");
327-
if(httpProxy == null || httpsProxy == null) {
328-
throw new Exception("Please set environment variable HTTP_PROXY and HTTPS_PROXY");
329-
}
330-
331344
// add fmw installer to the cache
332345
// delete the cache entry if any
333346
deleteEntryFromCache("fmw_" + WLS_VERSION);
@@ -341,7 +354,7 @@ public void testBCreateFMWImgFullInternetAccess() throws Exception {
341354
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
342355

343356
String command = imagetool + " create --version=" + WLS_VERSION + " --tag imagetool:" + testMethodName +
344-
" --latestPSU --user " + user + " --passwordEnv ORACLE_SUPPORT_PASSWORD --httpProxyUrl " +
357+
" --latestPSU --user " + oracleSupportUsername + " --passwordEnv ORACLE_SUPPORT_PASSWORD --httpProxyUrl " +
345358
httpProxy + " --httpsProxyUrl " + httpsProxy + " --type fmw";
346359
logger.info("Executing command: " + command);
347360
ExecCommand.exec(command, true);
@@ -361,9 +374,6 @@ public void testCCreateFMWImgNonDefault() throws Exception {
361374
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
362375
logTestBegin(testMethodName);
363376

364-
// download the installers with non default version
365-
downloadInstallers(JDK_INSTALLER_8u212, FMW_INSTALLER_1221, P22987840_INSTALLER);
366-
367377
// add fmw installer to the cache
368378
String fmwPath = getInstallerCacheDir() + FS + FMW_INSTALLER_1221;
369379
addInstallerToCache("fmw", WLS_VERSION_1221, fmwPath);
@@ -397,9 +407,6 @@ public void testDCreateJRFDomainImgUsingWDT() throws Exception {
397407
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
398408
logTestBegin(testMethodName);
399409

400-
// pull oracle db image
401-
pullOracleDBDockerImage();
402-
403410
// create a db container for RCU
404411
createDBContainer();
405412

@@ -426,19 +433,23 @@ public void testDCreateJRFDomainImgUsingWDT() throws Exception {
426433

427434
String wdtArchive = getWDTResourcePath() + FS + WDT_ARCHIVE;
428435
String wdtModel = getWDTResourcePath() + FS + WDT_MODEL1;
436+
String tmpWdtModel = System.getProperty("java.io.tmpdir") + FS + WDT_MODEL1;
429437

430438
// update wdt model file
439+
Path source = Paths.get(wdtModel);
440+
Path dest = Paths.get(tmpWdtModel);
441+
Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING);
431442
String host = System.getenv("HOST");
432443
if (host == null) {
433444
throw new Exception("There is no HOST environment variable defined");
434445
}
435-
replaceStringInFile(wdtModel, "%DB_HOST%", host);
446+
replaceStringInFile(tmpWdtModel, "%DB_HOST%", host);
436447

437448
String command = imagetool + " create --fromImage " +
438449
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
439450
" --version " + WLS_VERSION + " --wdtVersion " + WDT_VERSION +
440451
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
441-
wdtModel + " --wdtDomainType JRF --wdtRunRCU --type fmw";
452+
tmpWdtModel + " --wdtDomainType JRF --wdtRunRCU --type fmw";
442453

443454
logger.info("Executing command: " + command);
444455
ExecCommand.exec(command, true);
@@ -454,17 +465,10 @@ public void testDCreateJRFDomainImgUsingWDT() throws Exception {
454465
* @throws Exception - if any error occurs
455466
*/
456467
@Test
457-
public void testECreateJRFDomainImgUsingWDT() throws Exception {
468+
public void testECreateRestricedJRFDomainImgUsingWDT() throws Exception {
458469
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
459470
logTestBegin(testMethodName);
460471

461-
String user = System.getenv("ORACLE_SUPPORT_USERNAME");
462-
String password = System.getenv("ORACLE_SUPPORT_PASSWORD");
463-
if(user == null || password == null) {
464-
throw new Exception("Please set environment variables ORACLE_SUPPORT_USERNAME and ORACLE_SUPPORT_PASSWORD" +
465-
" for Oracle Support credentials to download the patches.");
466-
}
467-
468472
// add WDT installer to the cache
469473
// delete the cache entry if any
470474
deleteEntryFromCache("wdt_" + WDT_VERSION);
@@ -491,8 +495,8 @@ public void testECreateJRFDomainImgUsingWDT() throws Exception {
491495
String wdtVariables = getWDTResourcePath() + FS + WDT_VARIABLES;
492496
String command = imagetool + " create --fromImage " +
493497
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
494-
" --version " + WLS_VERSION + " --latestPSU --user " + user +
495-
" --passwordEnv ORACLE_SUPPORT_PASSWORD " + " --wdtVersion " + WDT_VERSION +
498+
" --version " + WLS_VERSION + " --latestPSU --user " + oracleSupportUsername +
499+
" --password " + oracleSupportPassword + " --wdtVersion " + WDT_VERSION +
496500
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
497501
wdtModel + " --wdtDomainType RestrictedJRF --type fmw --wdtVariables " + wdtVariables;
498502

@@ -504,4 +508,55 @@ public void testECreateJRFDomainImgUsingWDT() throws Exception {
504508

505509
logTestEnd(testMethodName);
506510
}
511+
512+
@Test
513+
public void testFCreateWLSImgUsingMultiModels() throws Exception {
514+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
515+
logTestBegin(testMethodName);
516+
517+
// add WDT installer to the cache
518+
// delete the cache entry first
519+
deleteEntryFromCache("wdt_" + WDT_VERSION);
520+
String wdtPath = getInstallerCacheDir() + FS + WDT_INSTALLER;
521+
addInstallerToCache("wdt", WDT_VERSION, wdtPath);
522+
523+
// add WLS installer to the cache
524+
// delete the cache entry first
525+
deleteEntryFromCache("wls_" + WLS_VERSION);
526+
String wlsPath = getInstallerCacheDir() + FS + WLS_INSTALLER;
527+
addInstallerToCache("wls", WLS_VERSION, wlsPath);
528+
529+
// add jdk installer to the cache
530+
// delete the cache entry first
531+
deleteEntryFromCache("jdk_" + JDK_VERSION);
532+
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER;
533+
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
534+
535+
// need to add the required patches 28186730 for Opatch before create wls images
536+
// delete the cache entry first
537+
deleteEntryFromCache(P28186730_ID + "_opatch");
538+
String patchPath = getInstallerCacheDir() + FS + P28186730_INSTALLER;
539+
addPatchToCache("wls", P28186730_ID, OPATCH_VERSION, patchPath);
540+
541+
// build the wdt archive
542+
buildWDTArchive();
543+
544+
String wdtArchive = getWDTResourcePath() + FS + WDT_ARCHIVE;
545+
String wdtModel = getWDTResourcePath() + FS + WDT_MODEL;
546+
String wdtModel2 = getWDTResourcePath() + FS + WDT_MODEL2;
547+
String wdtVariables = getWDTResourcePath() + FS + WDT_VARIABLES;
548+
String command = imagetool + " create --fromImage " +
549+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
550+
" --version " + WLS_VERSION + " --wdtVersion " + WDT_VERSION +
551+
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
552+
wdtModel + "," + wdtModel2 + " --wdtVariables " + wdtVariables;
553+
554+
logger.info("Executing command: " + command);
555+
ExecCommand.exec(command, true);
556+
557+
// verify the docker image is created
558+
verifyDockerImages(testMethodName);
559+
560+
logTestEnd(testMethodName);
561+
}
507562
}

imagetool/src/test/resources/wdt/simple-topology1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ domainInfo:
66
rcu_prefix: wdt1
77
rcu_schema_password: Oradoc_db1
88
rcu_admin_password: Oradoc_db1
9-
rcu_db_conn_string: 'slc16oeb:1521/InfraPDB1.us.oracle.com'
9+
rcu_db_conn_string: '%DB_HOST%:1521/InfraPDB1.us.oracle.com'
1010
topology:
1111
Name: domain1
1212
AdminServerName: 'admin-server'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
domainInfo:
2+
AdminUserName: weblogic
3+
AdminPassword: welcome1
4+
ServerStartMode: prod
5+
topology:
6+
Name: domain1
7+
AdminServerName: 'admin-server'
8+
ProductionModeEnabled: true
9+
Cluster:
10+
cluster1:
11+
ClientCertProxyEnabled: true
12+
DynamicServers:
13+
ServerTemplate: template1
14+
CalculatedListenPorts: false
15+
ServerNamePrefix: 'ms-'
16+
DynamicClusterSize: 2
17+
MaxDynamicClusterSize: 2
18+
Server:
19+
'admin-server':
20+
ListenPort: 7001
21+
NetworkAccessPoint:
22+
T3Channel:
23+
ListenAddress: None
24+
ListenPort: 30012
25+
PublicAddress: kubernetes
26+
PublicPort: 30012
27+
ServerTemplate:
28+
template1:
29+
ListenPort: 8001

0 commit comments

Comments
 (0)