Skip to content

Commit af4835d

Browse files
authored
Merge pull request #1071 from oracle/fix-int-test-external-jenkins
Fix integration tests to run on remote multi node k8s cluster(external jenkins)
2 parents fd8d40c + 8428c8a commit af4835d

File tree

15 files changed

+325
-103
lines changed

15 files changed

+325
-103
lines changed

integration-tests/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,20 @@ SHARED_CLUSTER=true:
228228
| IMAGE_NAME_OPERATOR | Docker image name for operator. Default is weblogic-kubernetes-operator |
229229
| IMAGE_PULL_POLICY_OPERATOR | Default 'Never'. |
230230
| IMAGE_PULL_SECRET_OPERATOR | Default ''. |
231-
| IMAGE_PULL_SECRET_WEBLOGIC | Default ''.
231+
| IMAGE_PULL_SECRET_WEBLOGIC | Default ''. |
232232

233+
The below env variables are required for SHARED_CLUSTER=true:
234+
235+
| Variable | Description |
236+
| --- | --- |
237+
| REPO_REGISTRY | OCIR Server to push/pull the Operator image |
238+
| REPO_USERNAME | OCIR Username |
239+
| REPO_PASSWORD | OCIR token |
240+
| REPO_EMAIL | OCIR email |
241+
| DOCKER_USERNAME | Docker username to pull the Weblogic image |
242+
| DOCKER_PASSWORD | Docker password |
243+
| DOCKER_EMAIL | Docker email |
244+
| K8S_NODEPORT_HOST | DNS name of a Kubernetes worker node. |
233245

234246
Successful run will have the output like below:
235247
```

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class BaseTest {
5252
public static boolean QUICKTEST;
5353
public static boolean SMOKETEST;
5454
public static boolean JENKINS;
55+
public static boolean SHARED_CLUSTER;
5556
public static boolean INGRESSPERDOMAIN = true;
5657

5758
private static String resultRoot = "";
@@ -83,6 +84,9 @@ public class BaseTest {
8384
if (System.getenv("JENKINS") != null) {
8485
JENKINS = new Boolean(System.getenv("JENKINS")).booleanValue();
8586
}
87+
if (System.getenv("SHARED_CLUSTER") != null) {
88+
SHARED_CLUSTER = new Boolean(System.getenv("SHARED_CLUSTER")).booleanValue();
89+
}
8690
if (System.getenv("INGRESSPERDOMAIN") != null) {
8791
INGRESSPERDOMAIN = new Boolean(System.getenv("INGRESSPERDOMAIN")).booleanValue();
8892
}
@@ -128,7 +132,7 @@ public static void initialize(String appPropsFile) throws Exception {
128132
}
129133

130134
// for manual/local run, do cleanup
131-
if (System.getenv("SHARED_CLUSTER") == null && System.getenv("JENKINS") == null) {
135+
if (!JENKINS) {
132136

133137
// delete k8s artifacts created if any, delete PV directories
134138
ExecResult clnResult = cleanup();
@@ -143,19 +147,25 @@ public static void initialize(String appPropsFile) throws Exception {
143147
+ clnResult.stderr());
144148
}
145149

146-
if (System.getenv("JENKINS") != null) {
147-
logger.info("Creating " + resultRoot + "/acceptance_test_tmp");
150+
if (JENKINS) {
151+
logger.info("Deleting and creating " + resultRoot + "/acceptance_test_tmp");
148152
TestUtils.exec(
149-
"/usr/local/packages/aime/ias/run_as_root \"mkdir -p "
153+
"/usr/local/packages/aime/ias/run_as_root \"rm -rf "
154+
+ resultRoot
155+
+ "/acceptance_test_tmp\" && "
156+
+ "/usr/local/packages/aime/ias/run_as_root \"mkdir -p "
150157
+ resultRoot
151158
+ "/acceptance_test_tmp\"");
152159
TestUtils.exec(
153160
"/usr/local/packages/aime/ias/run_as_root \"chmod 777 "
154161
+ resultRoot
155162
+ "/acceptance_test_tmp\"");
156-
logger.info("Creating " + pvRoot + "/acceptance_test_pv");
163+
logger.info("Deleting and Creating " + pvRoot + "/acceptance_test_pv");
157164
TestUtils.exec(
158-
"/usr/local/packages/aime/ias/run_as_root \"mkdir -p "
165+
"/usr/local/packages/aime/ias/run_as_root \"rm -rf "
166+
+ pvRoot
167+
+ "/acceptance_test_pv\" && "
168+
+ "/usr/local/packages/aime/ias/run_as_root \"mkdir -p "
159169
+ pvRoot
160170
+ "/acceptance_test_pv\"");
161171
TestUtils.exec(
@@ -177,7 +187,7 @@ public static void initialize(String appPropsFile) throws Exception {
177187
logger.info("Adding file handler, logging to file at " + resultDir + "/java_test_suite.out");
178188

179189
// for manual/local run, create file handler, create PVROOT
180-
if (System.getenv("SHARED_CLUSTER") == null && System.getenv("JENKINS") == null) {
190+
if (!JENKINS && !SHARED_CLUSTER) {
181191
logger.info("Creating PVROOT " + pvRoot);
182192
Files.createDirectories(Paths.get(pvRoot));
183193
ExecResult result = ExecCommand.exec("chmod 777 " + pvRoot);
@@ -211,6 +221,9 @@ public static void initialize(String appPropsFile) throws Exception {
211221
"Env var IMAGE_PULL_SECRET_OPERATOR " + System.getenv("IMAGE_PULL_SECRET_OPERATOR"));
212222
logger.info(
213223
"Env var IMAGE_PULL_SECRET_WEBLOGIC " + System.getenv("IMAGE_PULL_SECRET_WEBLOGIC"));
224+
logger.info("Env var IMAGE_NAME_WEBLOGIC " + System.getenv("IMAGE_NAME_WEBLOGIC"));
225+
logger.info("Env var IMAGE_TAG_WEBLOGIC " + System.getenv("IMAGE_TAG_WEBLOGIC"));
226+
214227
logger.info("Env var BRANCH_NAME " + System.getenv("BRANCH_NAME"));
215228
}
216229

@@ -531,7 +544,7 @@ public static ExecResult cleanup() throws Exception {
531544
+ getResultRoot()
532545
+ " export PV_ROOT="
533546
+ getPvRoot()
534-
+ " && "
547+
+ " export SHARED_CLUSTER=false && "
535548
+ getProjectRoot()
536549
+ "/src/integration-tests/bash/cleanup.sh";
537550
logger.info("Command to call cleanup script " + cmd);
@@ -672,11 +685,8 @@ public static void tearDown(String iTClassName) throws Exception {
672685
StringBuffer cmd =
673686
new StringBuffer(
674687
"export RESULT_ROOT=$RESULT_ROOT && export PV_ROOT=$PV_ROOT && export IT_CLASS=");
675-
cmd.append(iTClassName);
676-
if (JENKINS) {
677-
cmd.append(" && export JENKINS_RESULTS_DIR=${WORKSPACE}/logdir/${BUILD_TAG} ");
678-
}
679-
cmd.append(" && ")
688+
cmd.append(iTClassName)
689+
.append(" && export JENKINS_RESULTS_DIR=${WORKSPACE}/logdir/${BUILD_TAG} && ")
680690
.append(BaseTest.getProjectRoot())
681691
.append("/integration-tests/src/test/resources/statedump.sh");
682692
logger.info("Running " + cmd);
@@ -693,7 +703,7 @@ public static void tearDown(String iTClassName) throws Exception {
693703

694704
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
695705

696-
if (JENKINS) {
706+
if (JENKINS || SHARED_CLUSTER) {
697707
result = cleanup();
698708
if (result.exitValue() != 0) {
699709
logger.info("cleanup result =" + result.stdout() + "\n " + result.stderr());

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,38 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
200200
+ domain.getDomainUid()
201201
+ " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate");
202202

203-
TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate");
204-
domain.verifyDomainServerPodRestart(
205-
"\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\"");
203+
if (BaseTest.SHARED_CLUSTER) {
204+
String newImage =
205+
System.getenv("REPO_REGISTRY") + "/weblogick8s/store/oracle/weblogic:duplicate";
206+
207+
// tag image with repo name
208+
TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 " + newImage);
209+
210+
// login and push image to ocir
211+
TestUtils.loginAndPushImageToOCIR(newImage);
212+
213+
// create ocir registry secret in the same ns as domain which is used while pulling the
214+
// image
215+
TestUtils.createDockerRegistrySecret(
216+
"docker-store",
217+
System.getenv("REPO_REGISTRY"),
218+
System.getenv("REPO_USERNAME"),
219+
System.getenv("REPO_PASSWORD"),
220+
System.getenv("REPO_EMAIL"),
221+
domain.getDomainNS());
222+
223+
// apply new domain yaml and verify pod restart
224+
domain.verifyDomainServerPodRestart(
225+
"\"store/oracle/weblogic:12.2.1.3\"", "\"" + newImage + "\"");
226+
} else {
227+
TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate");
228+
domain.verifyDomainServerPodRestart(
229+
"\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\"");
230+
}
206231
} finally {
207-
TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate");
232+
if (!BaseTest.SHARED_CLUSTER) {
233+
TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate");
234+
}
208235
}
209236

210237
logger.info("SUCCESS - " + testMethodName);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ public void testOPReconnToDomain() throws Exception {
193193
}
194194

195195
private void scaleDownAndverify(int decrNum) throws Exception {
196-
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
197-
logTestBegin(testMethodName);
198196

199197
Map<String, Object> domainMap = domain.getDomainMap();
200198
String domainUid = domain.getDomainUid();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public static void staticPrepare() throws Exception {
6363
// create domain
6464
if (domain == null) {
6565
logger.info("Creating WLS Domain & waiting for the script to complete execution");
66-
domain = TestUtils.createDomain(DOMAINONPV_WLST_YAML);
66+
Map<String, Object> wlstDomainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
67+
wlstDomainMap.put("domainUID", "sessmigdomainonpvwlst");
68+
domain = TestUtils.createDomain(wlstDomainMap);
6769
domain.verifyDomainCreated();
6870
}
6971

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,10 @@ public void testAddRemoveDomainUpdateOperatorHC() throws Exception {
630630
logger.info("verify that old domain is not managed by operator");
631631
verifyOperatorDomainManagement(operator, domain, false);
632632
verifyOperatorDomainManagement(operator, domainnew, true);
633+
logger.info("Upgrade to add first domain namespace in target domains");
634+
targetDomainsNS.add("test" + (number));
635+
upgradeOperatorDomainNamespaces(operator, targetDomainsNS);
636+
verifyOperatorDomainManagement(operator, domain, true);
633637
testCompletedSuccessfully = true;
634638
} finally {
635639
if (domain != null) {
@@ -700,6 +704,7 @@ private void verifyOperatorDomainManagement(
700704
.contains(
701705
"Response {\"status\":404,\"detail\":\"/operator/latest/domains/test" + number)) {
702706
} else {
707+
logger.info("Got 404, Operator can not access the domain " + domain.getDomainUid());
703708
break;
704709
}
705710
}

0 commit comments

Comments
 (0)