Skip to content

Commit abc3765

Browse files
committed
get Mark's changes and update the jrf tests to use Mark's new script
1 parent 971acf8 commit abc3765

File tree

25 files changed

+1495
-331
lines changed

25 files changed

+1495
-331
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/JrfInOperatorTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,15 @@ public void testJRFDomainOnPVUsingWLST() throws Exception {
100100
boolean testCompletedSuccessfully = false;
101101

102102
try {
103+
// run RCU first
104+
DBUtils.deleteNamespace(DBUtils.RCU_NAMESPACE);
105+
DBUtils.createNamespace(DBUtils.RCU_NAMESPACE);
106+
DBUtils.runRCU(JRF_DOMAIN_ON_PV_WLST_FILE);
107+
108+
// create JRF domain
103109
jrfdomain = new JRFDomain(JRF_DOMAIN_ON_PV_WLST_FILE);
110+
111+
// verify JRF domain created, servers up and running
104112
jrfdomain.verifyDomainCreated();
105113

106114
if (!SMOKETEST) {

integration-tests/src/test/java/oracle/kubernetes/operator/utils/DBUtils.java

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44

55
package oracle.kubernetes.operator.utils;
66

7+
import java.util.Map;
78
import java.util.logging.Logger;
89

910
public class DBUtils {
11+
public static final String DEFAULT_FMWINFRA_DOCKER_IMAGENAME =
12+
"phx.ocir.io/weblogick8s/oracle/fmw-infrastructure";
13+
public static final String DEFAULT_FMWINFRA_DOCKER_IMAGETAG = "12.2.1.3";
14+
public static final String DEFAULT_RCU_SCHEMA_USERNAME = "myrcuuser";
15+
public static final String DEFAULT_RCU_SCHEMA_PASSWORD = "Oradoc_db1";
16+
public static final String DEFAULT_RCU_SYS_USERNAME = "sys";
17+
public static final String DEFAULT_RCU_SYS_PASSWORD = "Oradoc_db1";
18+
public static final String RCU_NAMESPACE = "rcu";
1019
private static final Logger logger = Logger.getLogger("OperatorIT", "OperatorIT");
1120

1221
/**
@@ -21,9 +30,9 @@ public static OracleDB createOracleDB(String dbPropsFile) throws Exception {
2130

2231
// check the db is ready
2332
String dbnamespace = oracledb.getNamespace();
24-
2533
String cmd = "kubectl get pod -n " + dbnamespace + " -o jsonpath=\"{.items[0].metadata.name}\"";
26-
ExecResult result = ExecCommand.exec(cmd);
34+
logger.info("running command " + cmd);
35+
ExecResult result = TestUtils.exec(cmd);
2736
String podName = result.stdout();
2837

2938
logger.info("DEBUG: db namespace=" + dbnamespace);
@@ -36,4 +45,112 @@ public static OracleDB createOracleDB(String dbPropsFile) throws Exception {
3645

3746
return oracledb;
3847
}
48+
49+
/**
50+
* run RCU script to load database schema
51+
*
52+
* @param inputYaml - create domain input file
53+
* @throws Exception - if any error occurs
54+
*/
55+
public static void runRCU(String inputYaml) throws Exception {
56+
Map<String, Object> inputMap = TestUtils.loadYaml(inputYaml);
57+
String dbConnectString = (String) inputMap.get("rcuDatabaseURL");
58+
String rcuPrefix = (String) inputMap.get("rcuSchemaPrefix");
59+
runRCU(RCU_NAMESPACE, dbConnectString, rcuPrefix);
60+
}
61+
62+
/**
63+
* run RCU script to load database schema
64+
*
65+
* @param rcuNamespace - namespace for rcu pod
66+
* @param dbConnectString - db connect string to load the database schema
67+
* @param rcuPrefix - rcu prefix for the db schema name
68+
* @throws Exception - if any error occurs
69+
*/
70+
public static void runRCU(String rcuNamespace, String dbConnectString, String rcuPrefix)
71+
throws Exception {
72+
String rcuPodName = createRCUPod(rcuNamespace);
73+
logger.info("DEBUG: rcuPodName=" + rcuPodName);
74+
75+
// create password file used for rcu script
76+
String rcuPwdCmd = "echo " + DEFAULT_RCU_SYS_PASSWORD + "> /u01/oracle/pwd.txt";
77+
TestUtils.kubectlexec(rcuPodName, rcuNamespace, " -- bash -c '" + rcuPwdCmd + "'");
78+
rcuPwdCmd = "echo " + DEFAULT_RCU_SYS_PASSWORD + ">> /u01/oracle/pwd.txt";
79+
TestUtils.kubectlexec(rcuPodName, rcuNamespace, " -- bash -c '" + rcuPwdCmd + "'");
80+
81+
// create rcu script to run
82+
String rcuScript =
83+
"/u01/oracle/oracle_common/bin/rcu -silent -createRepository -databaseType ORACLE"
84+
+ " -connectString "
85+
+ dbConnectString
86+
+ " -dbUser sys -dbRole sysdba"
87+
+ " -useSamePasswordForAllSchemaUsers true -selectDependentsForComponents true -schemaPrefix "
88+
+ rcuPrefix
89+
+ " -component MDS -component IAU -component IAU_APPEND -component IAU_VIEWER -component OPSS"
90+
+ " -component WLS -component STB < /u01/oracle/pwd.txt";
91+
92+
TestUtils.kubectlexec(rcuPodName, rcuNamespace, " -- bash -c '" + rcuScript + "'");
93+
}
94+
95+
/**
96+
* create a rcu pod to run rcu script
97+
*
98+
* @param rcuNamespace - namespace for rcu pod
99+
* @return - rcu pod name
100+
* @throws Exception - if any error occurs
101+
*/
102+
private static String createRCUPod(String rcuNamespace) throws Exception {
103+
// create a rcu deployment
104+
String cmd =
105+
"kubectl run rcu -n "
106+
+ rcuNamespace
107+
+ " --image "
108+
+ DEFAULT_FMWINFRA_DOCKER_IMAGENAME
109+
+ ":"
110+
+ DEFAULT_FMWINFRA_DOCKER_IMAGETAG
111+
+ " -- sleep 300";
112+
TestUtils.exec(cmd);
113+
114+
// get rcu pod name
115+
cmd = "kubectl get pod -n " + rcuNamespace + " -o jsonpath=\"{.items[0].metadata.name}\"";
116+
logger.info("running command " + cmd);
117+
ExecResult result = TestUtils.exec(cmd);
118+
String podName = result.stdout();
119+
120+
// check the pod is ready
121+
TestUtils.checkPodReady(podName, rcuNamespace);
122+
123+
return podName;
124+
}
125+
126+
/**
127+
* delete a namespace
128+
*
129+
* @param namespace - namespace to delete
130+
* @throws Exception - if any error occurs
131+
*/
132+
public static void deleteNamespace(String namespace) throws Exception {
133+
if (!namespace.equalsIgnoreCase("default")) {
134+
String command = "kubectl delete ns " + namespace;
135+
logger.info("Running " + command);
136+
ExecCommand.exec(command);
137+
138+
// verify the namespace is deleted
139+
TestUtils.checkNamespaceDeleted(namespace);
140+
}
141+
}
142+
143+
/**
144+
* create a namespace
145+
*
146+
* @param namespace - namespace to create
147+
* @throws Exception - if any error occurs
148+
*/
149+
public static void createNamespace(String namespace) throws Exception {
150+
if (!namespace.equalsIgnoreCase("default")) {
151+
String command = "kubectl create ns " + namespace;
152+
logger.info("Running " + command);
153+
TestUtils.exec(command);
154+
}
155+
}
39156
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Domain {
4444
protected String domainUid = "";
4545
// default values as in create-weblogic-domain-inputs.yaml, generated yaml file will have the
4646
// customized property values
47-
private String domainNS;
47+
protected String domainNS;
4848
private String adminServerName;
4949
private String managedServerNameBase;
5050
private int initialManagedServerReplicas;
@@ -62,7 +62,7 @@ public class Domain {
6262
private String projectRoot = "";
6363
private boolean ingressPerDomain = true;
6464

65-
private String generatedInputYamlFile;
65+
protected String generatedInputYamlFile;
6666

6767
private static int maxIterations = BaseTest.getMaxIterationsPod(); // 50 * 5 = 250 seconds
6868
private static int waitTime = BaseTest.getWaitTimePod();
@@ -1555,6 +1555,9 @@ private String prepareCmdToCallCreateDomainScript(String outputDir) {
15551555
.append(" -p ")
15561556
.append(BaseTest.getPassword())
15571557
.append(" -k -i ");
1558+
} else if (domainMap.containsKey("rcuCredentialsSecret")) {
1559+
createDomainScriptCmd.append(
1560+
"/samples/scripts/create-fmw-infrastructure-domain/create-domain.sh -v -i ");
15581561
} else {
15591562
createDomainScriptCmd.append(
15601563
"/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh -v -i ");

integration-tests/src/test/java/oracle/kubernetes/operator/utils/JRFDomain.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
/** JRF Domain class with all the utility methods */
1111
public class JRFDomain extends Domain {
1212

13-
private static final String DEFAULT_FMWINFRA_DOCKER_IMAGENAME =
14-
"phx.ocir.io/weblogick8s/oracle/fmw-infrastructure";
15-
private static final String DEFAULT_FMWINFRA_DOCKER_IMAGETAG = "12.2.1.3";
16-
1713
/**
1814
* JRFDomain constructor
1915
*
@@ -38,6 +34,7 @@ public JRFDomain(Map<String, Object> inputDomainMap) throws Exception {
3834
updateDomainMapForJRF();
3935
createPV();
4036
createSecret();
37+
createRcuSecret();
4138
generateInputYaml();
4239
callCreateDomainScript(userProjectsDir);
4340
// TODO: add load balancer later
@@ -52,7 +49,8 @@ public JRFDomain(Map<String, Object> inputDomainMap) throws Exception {
5249
private void updateDomainMapForJRF() throws Exception {
5350
// jrf specific input parameter
5451
domainMap.put(
55-
"image", DEFAULT_FMWINFRA_DOCKER_IMAGENAME + ":" + DEFAULT_FMWINFRA_DOCKER_IMAGETAG);
52+
"image",
53+
DBUtils.DEFAULT_FMWINFRA_DOCKER_IMAGENAME + ":" + DBUtils.DEFAULT_FMWINFRA_DOCKER_IMAGETAG);
5654

5755
if (!domainMap.containsKey("domainHomeImageBase")) {
5856
domainMap.put("createDomainFilesDir", BaseTest.getResultDir() + "/jrf");
@@ -64,4 +62,27 @@ private void updateDomainMapForJRF() throws Exception {
6462
domainMap.put("imagePullSecretName", "ocir-store");
6563
}
6664
}
65+
66+
/**
67+
* create rcu secret
68+
*
69+
* @throws Exception - if any error occurs
70+
*/
71+
private void createRcuSecret() throws Exception {
72+
RcuSecret rucSecret =
73+
new RcuSecret(
74+
domainNS,
75+
domainMap.getOrDefault("secretName", domainUid + "-rcu-credentials").toString(),
76+
DBUtils.DEFAULT_RCU_SCHEMA_USERNAME,
77+
DBUtils.DEFAULT_RCU_SCHEMA_PASSWORD,
78+
DBUtils.DEFAULT_RCU_SYS_USERNAME,
79+
DBUtils.DEFAULT_RCU_SYS_PASSWORD);
80+
domainMap.put("rcuCredentialsSecret", rucSecret.getSecretName());
81+
final String labelCmd =
82+
String.format(
83+
"kubectl label secret %s -n %s weblogic.domainUID=%s weblogic.domainName=%s",
84+
rucSecret.getSecretName(), domainNS, domainUid, domainUid);
85+
logger.info("running command " + labelCmd);
86+
TestUtils.exec(labelCmd);
87+
}
6788
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/OracleDB.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class OracleDB {
1313
public static final String DEFAULT_DB_NAME = "infradb";
1414
public static final String DEFAULT_DB_NAMESPACE = "db";
1515
public static final String DEFAULT_DB_IMAGE = "store/oracle/database-enterprise:12.2.0.1";
16-
// "container-registry.oracle.com/database/enterprise:12.2.0.1";
1716
public static final String DEFAULT_DB_PORT = "1521";
1817
public static final String DEFAULT_DB_SID = "InfraDB";
1918
public static final String DEFAULT_DB_PDB = "InfraPDB1";
@@ -48,11 +47,7 @@ public OracleDB(String dbPropFile) throws Exception {
4847

4948
String command;
5049
// create the namespace
51-
if (!namespace.equalsIgnoreCase("default")) {
52-
command = "kubectl create ns " + namespace;
53-
logger.info("Running " + command);
54-
TestUtils.exec(command);
55-
}
50+
DBUtils.createNamespace(namespace);
5651

5752
// create db
5853
command =
@@ -113,12 +108,7 @@ private void cleanDB() throws Exception {
113108
// delete the namespace if the db namespace is not default
114109
String command;
115110
if (!namespace.equalsIgnoreCase("default")) {
116-
command = "kubectl delete ns " + namespace;
117-
logger.info("Running " + command);
118-
ExecCommand.exec(command);
119-
120-
// verify the namespace is deleted
121-
TestUtils.checkNamespaceDeleted(namespace);
111+
DBUtils.deleteNamespace(namespace);
122112
} else {
123113
// delete the deployment and service
124114
command = "kubectl delete deployment " + name + " -n " + namespace;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2018, 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+
5+
package oracle.kubernetes.operator.utils;
6+
7+
public class RcuSecret extends Secret {
8+
9+
private String sysUsername;
10+
private String sysPassword;
11+
12+
public RcuSecret(
13+
String namespace,
14+
String secretName,
15+
String username,
16+
String password,
17+
String sysUsername,
18+
String sysPassword)
19+
throws Exception {
20+
this.namespace = namespace;
21+
this.secretName = secretName;
22+
this.username = username;
23+
this.password = password;
24+
this.sysUsername = sysUsername;
25+
this.sysPassword = sysPassword;
26+
27+
// delete the secret first if exists
28+
deleteSecret();
29+
30+
// create the secret
31+
String command =
32+
"kubectl -n "
33+
+ this.namespace
34+
+ " create secret generic "
35+
+ this.secretName
36+
+ " --from-literal=username="
37+
+ this.username
38+
+ " --from-literal=password="
39+
+ this.password
40+
+ " --from-literal=sys_username="
41+
+ this.sysUsername
42+
+ " --from-literal=sys_password="
43+
+ this.sysPassword;
44+
logger.info("Running " + command);
45+
ExecResult result = TestUtils.exec(command);
46+
logger.info("command result " + result.stdout().trim());
47+
}
48+
49+
public String getSysUsername() {
50+
return sysUsername;
51+
}
52+
53+
public String getSysPassword() {
54+
return sysPassword;
55+
}
56+
57+
private void deleteSecret() throws Exception {
58+
String command = "kubectl -n " + namespace + " delete secret " + secretName;
59+
logger.info("Running " + command);
60+
ExecCommand.exec(command);
61+
}
62+
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Secret.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
import java.util.logging.Logger;
88

99
public class Secret {
10-
private String secretName;
11-
private String namespace;
12-
private String username;
13-
private String password;
14-
private static final Logger logger = Logger.getLogger("OperatorIT", "OperatorIT");
10+
protected String secretName;
11+
protected String namespace;
12+
protected String username;
13+
protected String password;
14+
protected static final Logger logger = Logger.getLogger("OperatorIT", "OperatorIT");
15+
16+
public Secret() throws Exception {
17+
secretName = "";
18+
}
1519

1620
public Secret(String namespace, String secretName, String username, String password)
1721
throws Exception {

0 commit comments

Comments
 (0)