Skip to content

Commit 8229fc0

Browse files
committed
add JRF domain image test case
1 parent fbb13f4 commit 8229fc0

File tree

3 files changed

+195
-11
lines changed

3 files changed

+195
-11
lines changed

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

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import com.oracle.weblogic.imagetool.integration.utils.ExecCommand;
88
import com.oracle.weblogic.imagetool.integration.utils.ExecResult;
99
import java.io.File;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
1013
import java.util.logging.Logger;
1114

1215
public class BaseTest {
@@ -17,13 +20,18 @@ public class BaseTest {
1720
protected static final String FS = File.separator;
1821
private static final String OCIR_SERVER = "phx.ocir.io";
1922
private static final String OCIR_TENENT = "weblogick8s";
23+
private static final String OCR_SERVER = "container-registry.oracle.com";
2024
protected static final String BASE_OS_IMG = "phx.ocir.io/weblogick8s/oraclelinux";
2125
protected static final String BASE_OS_IMG_TAG = "7-4imagetooltest";
26+
protected static final String ORACLE_DB_IMG = "container-registry.oracle.com/database/enterprise";
27+
protected static final String ORACLE_DB_IMG_TAG = "12.2.0.1-slim";
2228
private static String projectRoot = "";
2329
protected static String wlsImgBldDir = "";
2430
protected static String wlsImgCacheDir = "";
2531
protected static String imagetool = "";
2632
private static String imagetoolZipfile = "";
33+
private static int maxIterations = 50;
34+
private static int waitTime = 5;
2735

2836
protected static void initialize() throws Exception {
2937
logger.info("Initializing the tests ...");
@@ -82,7 +90,7 @@ protected static void cleanup() throws Exception {
8290
executeNoVerify(command);
8391
}
8492

85-
protected static void pullDockerImage() throws Exception {
93+
protected static void pullBaseOSDockerImage() throws Exception {
8694
logger.info("Pulling OS base images from OCIR ...");
8795
String ocir_username = System.getenv("OCIR_USERNAME");
8896
String ocir_password = System.getenv("OCIR_PASSWORD");
@@ -91,16 +99,20 @@ protected static void pullDockerImage() throws Exception {
9199
throw new Exception("You need to set OCIR_USERNAME and OCIR_PASSWORD environment variable to pull images");
92100
}
93101

94-
ExecCommand.exec("docker login " + OCIR_SERVER + " -u " + OCIR_TENENT + "/" + ocir_username +
95-
" -p " + ocir_password);
96-
ExecCommand.exec("docker pull " + BASE_OS_IMG + ":" + BASE_OS_IMG_TAG);
102+
pullDockerImage(OCIR_SERVER, OCIR_TENENT + "/" + ocir_username , ocir_password, BASE_OS_IMG,
103+
BASE_OS_IMG_TAG);
104+
}
97105

98-
// verify the docker image is pulled
99-
ExecResult result = ExecCommand.exec("docker images | grep " + BASE_OS_IMG + " | grep " +
100-
BASE_OS_IMG_TAG + "| wc -l");
101-
if(Integer.parseInt(result.stdout()) != 1) {
102-
throw new Exception("Base OS docker image is not pulled as expected");
106+
protected static void pullOracleDBDockerImage() throws Exception {
107+
logger.info("Pulling Oracle DB image from OCR ...");
108+
String ocr_username = System.getenv("OCR_USERNAME");
109+
String ocr_password = System.getenv("OCR_PASSWORD");
110+
111+
if(ocr_username == null || ocr_password == null) {
112+
throw new Exception("You need to set OCR_USERNAME and OCR_PASSWORD environment variable to pull images");
103113
}
114+
115+
pullDockerImage(OCR_SERVER, ocr_username, ocr_password, ORACLE_DB_IMG, ORACLE_DB_IMG_TAG);
104116
}
105117

106118
protected static void downloadInstallers(String... installers) throws Exception {
@@ -210,11 +222,83 @@ protected ExecResult buildWDTArchive() throws Exception {
210222
return executeAndVerify(command, true);
211223
}
212224

225+
protected void createDBContainer() throws Exception {
226+
logger.info("Creating an Oracle db docker container ...");
227+
String command = "docker rm -f InfraDB";
228+
ExecCommand.exec(command);
229+
command = "docker run -d --name InfraDB -p 1521:1521 -p 5500:5500 --env=\"DB_PDB=InfraPDB1\"" +
230+
" --env=\"DB_DOMAIN=us.oracle.com\" --env=\"DB_BUNDLE=basic\" " + ORACLE_DB_IMG + ":" +
231+
ORACLE_DB_IMG_TAG;
232+
ExecCommand.exec(command);
233+
234+
// wait for the db is ready
235+
command = "docker ps | grep InfraDB";
236+
checkCmdInLoop(command, "healthy");
237+
}
238+
239+
protected static void replaceStringInFile(String filename, String originalString, String newString)
240+
throws Exception {
241+
Path path = Paths.get(filename);
242+
243+
String content = new String(Files.readAllBytes(path));
244+
content = content.replaceAll(originalString, newString);
245+
Files.write(path, content.getBytes());
246+
}
247+
213248
private ExecResult executeAndVerify(String command, boolean isRedirectToOut) throws Exception {
214249
logger.info("Executing command: " + command);
215250
ExecResult result = ExecCommand.exec(command, isRedirectToOut);
216251
verifyExitValue(result, command);
217252
logger.info(result.stdout());
218253
return result;
219254
}
255+
256+
private static void pullDockerImage(String repoServer, String username, String password,
257+
String imagename, String imagetag) throws Exception {
258+
259+
ExecCommand.exec("docker login " + repoServer + " -u " + username +
260+
" -p " + password);
261+
ExecCommand.exec("docker pull " + imagename + ":" + imagetag);
262+
263+
// verify the docker image is pulled
264+
ExecResult result = ExecCommand.exec("docker images | grep " + imagename + " | grep " +
265+
imagetag + "| wc -l");
266+
if(Integer.parseInt(result.stdout()) != 1) {
267+
throw new Exception("docker image " + imagename + ":" + imagetag + " is not pulled as expected");
268+
}
269+
}
270+
271+
private static void checkCmdInLoop(String cmd, String matchStr)
272+
throws Exception {
273+
int i = 0;
274+
while (i < maxIterations) {
275+
ExecResult result = ExecCommand.exec(cmd);
276+
277+
// pod might not have been created or if created loop till condition
278+
if (result.exitValue() != 0
279+
|| (result.exitValue() == 0 && !result.stdout().contains(matchStr))) {
280+
logger.info("Output for " + cmd + "\n" + result.stdout() + "\n " + result.stderr());
281+
// check for last iteration
282+
if (i == (maxIterations - 1)) {
283+
throw new RuntimeException(
284+
"FAILURE: " + cmd + " does not return the expected string " + matchStr + ", exiting!");
285+
}
286+
logger.info(
287+
"Waiting for the expected String " + matchStr
288+
+ ": Ite ["
289+
+ i
290+
+ "/"
291+
+ maxIterations
292+
+ "], sleeping "
293+
+ waitTime
294+
+ " seconds more");
295+
296+
Thread.sleep(waitTime * 1000);
297+
i++;
298+
} else {
299+
logger.info("get the expected String " + matchStr);
300+
break;
301+
}
302+
}
303+
}
220304
}

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

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public class ITImagetool extends BaseTest {
3434
private static final String OPATCH_VERSION = "13.9.4.0.0";
3535
private static final String JDK_VERSION = "8u202";
3636
private static final String JDK_VERSION_8u212 = "8u212";
37-
private static final String WDT_VERSION = "1.1.1";
37+
private static final String WDT_VERSION = "1.1.2";
3838
private static final String WDT_ARCHIVE = "archive.zip";
3939
private static final String WDT_VARIABLES = "domain.properties";
4040
private static final String WDT_MODEL = "simple-topology.yaml";
41+
private static final String WDT_MODEL1 = "simple-topology1.yaml";
4142

4243
@BeforeClass
4344
public static void staticPrepare() throws Exception {
@@ -49,7 +50,7 @@ public static void staticPrepare() throws Exception {
4950

5051
setup();
5152
// pull base OS docker image used for test
52-
pullDockerImage();
53+
pullBaseOSDockerImage();
5354

5455
// download the installers for the test
5556
downloadInstallers(JDK_INSTALLER, WLS_INSTALLER, WDT_INSTALLER, P27342434_INSTALLER, P28186730_INSTALLER,
@@ -375,4 +376,60 @@ public void testCCreateFMWImgNonDefault() throws Exception {
375376

376377
logTestEnd(testMethodName);
377378
}
379+
380+
/**
381+
* create a JRF domain image using WDT
382+
* You need to have OCR credentials to pull container-registry.oracle.com/database/enterprise:12.2.0.1-slim
383+
* @throws Exception
384+
*/
385+
@Test
386+
public void testDCreateJRFDomainImgUsingWDT() throws Exception {
387+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
388+
logTestBegin(testMethodName);
389+
390+
// pull oracle db image
391+
pullOracleDBDockerImage();
392+
393+
// create a db container for RCU
394+
createDBContainer();
395+
396+
// add WDT installer to the cache
397+
String wdtPath = getInstallerCacheDir() + FS + WDT_INSTALLER;
398+
addInstallerToCache("wdt", WDT_VERSION, wdtPath);
399+
400+
// add FMW installer to the cache
401+
String fmwPath = getInstallerCacheDir() + FS + FMW_INSTALLER;
402+
addInstallerToCache("fmw", WLS_VERSION, fmwPath);
403+
404+
// add jdk installer to the cache
405+
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER;
406+
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
407+
408+
// build the wdt archive
409+
buildWDTArchive();
410+
411+
String wdtArchive = getWDTResourcePath() + FS + WDT_ARCHIVE;
412+
String wdtModel = getWDTResourcePath() + FS + WDT_MODEL1;
413+
414+
// update wdt model file
415+
String host = System.getenv("HOST");
416+
if (host == null) {
417+
throw new Exception("There is no HOST environment variable defined");
418+
}
419+
replaceStringInFile(wdtModel, "%DB_HOST%", host);
420+
421+
String command = imagetool + " create --fromImage " +
422+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
423+
" --version " + WLS_VERSION + " --wdtVersion " + WDT_VERSION +
424+
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
425+
wdtModel + " --wdtDomainType JRF --wdtRunRCU --type fmw";
426+
427+
logger.info("Executing command: " + command);
428+
ExecCommand.exec(command, true);
429+
430+
// verify the docker image is created
431+
verifyDockerImages(testMethodName);
432+
433+
logTestEnd(testMethodName);
434+
}
378435
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
domainInfo:
2+
AdminUserName: weblogic
3+
AdminPassword: welcome1
4+
ServerStartMode: prod
5+
RCUDbInfo:
6+
rcu_prefix: wdt1
7+
rcu_schema_password: Oradoc_db1
8+
rcu_admin_password: Oradoc_db1
9+
rcu_db_conn_string: 'slc16oeb:1521/InfraPDB1.us.oracle.com'
10+
topology:
11+
Name: domain1
12+
AdminServerName: 'admin-server'
13+
ProductionModeEnabled: true
14+
Cluster:
15+
cluster1:
16+
ClientCertProxyEnabled: true
17+
DynamicServers:
18+
ServerTemplate: template1
19+
CalculatedListenPorts: false
20+
ServerNamePrefix: 'ms-'
21+
DynamicClusterSize: 2
22+
MaxDynamicClusterSize: 2
23+
Server:
24+
'admin-server':
25+
ListenPort: 7001
26+
NetworkAccessPoint:
27+
T3Channel:
28+
ListenAddress: None
29+
ListenPort: 30012
30+
PublicAddress: kubernetes
31+
PublicPort: 30012
32+
ServerTemplate:
33+
template1:
34+
ListenPort: 8001
35+
appDeployments:
36+
Application:
37+
# Quote needed because of hyphen in string
38+
'simple-app':
39+
SourcePath: 'wlsdeploy/applications/simple-app.war'
40+
Target: cluster1
41+
ModuleType: war
42+
StagingMode: nostage
43+
PlanStagingMode: nostage

0 commit comments

Comments
 (0)