Skip to content

Commit 917934e

Browse files
committed
adding more negative tests
1 parent b1df14e commit 917934e

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void testDomainInitContainer() throws Exception {
128128

129129
// Modify the original domain yaml to include restartVersion in admin server node
130130
DomainCrd crd = new DomainCrd(originalYaml);
131-
crd.addInitContNode("spec", null, null, "busybox");
131+
crd.addInitContNode("spec", null, null, "busybox", "sleep");
132132
String modYaml = crd.getYamlTree();
133133
logger.info(modYaml);
134134
testInitContainer(modYaml);
@@ -155,7 +155,7 @@ public void testAdminServerInitContainer() throws Exception {
155155

156156
// Modify the original domain yaml to include restartVersion in admin server node
157157
DomainCrd crd = new DomainCrd(originalYaml);
158-
crd.addInitContNode("adminServer", null, null, "busybox");
158+
crd.addInitContNode("adminServer", null, null, "busybox", "sleep");
159159
String modYaml = crd.getYamlTree();
160160
logger.info(modYaml);
161161
testInitContainer(modYaml);
@@ -181,7 +181,7 @@ public void testClusterInitContainer() throws Exception {
181181

182182
// Modify the original domain yaml to include restartVersion in admin server node
183183
DomainCrd crd = new DomainCrd(originalYaml);
184-
crd.addInitContNode("clusters", "cluster-1", null, "busybox");
184+
crd.addInitContNode("clusters", "cluster-1", null, "busybox", "sleep");
185185
String modYaml = crd.getYamlTree();
186186
logger.info(modYaml);
187187
testInitContainer(modYaml);
@@ -208,7 +208,7 @@ public void testMSInitContainer() throws Exception {
208208

209209
// Modify the original domain yaml to include restartVersion in admin server node
210210
DomainCrd crd = new DomainCrd(originalYaml);
211-
crd.addInitContNode("managedServers", "cluster-1", "managed-server1", "busybox");
211+
crd.addInitContNode("managedServers", "cluster-1", "managed-server1", "busybox", "sleep");
212212
String modYaml = crd.getYamlTree();
213213
logger.info(modYaml);
214214
testInitContainer(modYaml);
@@ -230,23 +230,23 @@ public void testDomainInitContainerNegative() throws Exception {
230230
Assume.assumeFalse(QUICKTEST);
231231
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
232232
logTestBegin(testMethodName);
233-
String pods[] = {domainUid + "-" + domain.getAdminServerName(), domainUid + "-managed-server1"};
233+
String adminPodName = domainUid + "-" + domain.getAdminServerName();
234234

235235
// Modify the original domain yaml to include restartVersion in admin server node
236236
DomainCrd crd = new DomainCrd(originalYaml);
237-
crd.addInitContNode("spec", null, null, "busybox");
237+
crd.addInitContNode("spec", null, null, "busybox", "sleep");
238238
String modYaml = crd.getYamlTree();
239239
modYaml = modYaml.replaceAll("sleep", "foo");
240240
logger.info(modYaml);
241241
testInitContainer(modYaml);
242-
TestUtils.checkPodInitializing(pods[0], domain.getDomainNs());
243-
TestUtils.checkPodReady(pods[0], domain.getDomainNs());
242+
String cmd = "kubectl get pod " + adminPodName + " -n " + domain.getDomainNs();
243+
TestUtils.checkCmdInLoop(cmd, "Init:CrashLoopBackOff", adminPodName);
244244
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
245245
}
246246

247247
/**
248-
* Add initContainers at domain and adminserver level and verify init containers are run at both
249-
* level
248+
* Add initContainers at domain and admin server level and verify init container run only at
249+
* domain level
250250
*
251251
* @throws Exception when domain.yaml cannot be read or modified to include the initContainers or
252252
* weblogic server pod doesn't go through initialization and ready state
@@ -256,23 +256,24 @@ public void testInitContainerDiffLevel() throws Exception {
256256
Assume.assumeFalse(QUICKTEST);
257257
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
258258
logTestBegin(testMethodName);
259-
String pods[] = {domainUid + "-" + domain.getAdminServerName(), domainUid + "-managed-server1"};
259+
String pods[] = {domainUid + "-" + domain.getAdminServerName(), domainUid + "-managed-server2"};
260260

261261
// Modify the original domain yaml to include restartVersion in admin server node
262262
DomainCrd crd = new DomainCrd(originalYaml);
263-
crd.addInitContNode("spec", null, null, "busybox");
264-
crd.addInitContNode("adminServer", null, null, "busybox1");
263+
crd.addInitContNode("spec", null, null, "busybox", "sleep");
264+
crd.addInitContNode("adminServer", null, null, "busybox1", "foo");
265265
String modYaml = crd.getYamlTree();
266266
logger.info(modYaml);
267267
testInitContainer(modYaml);
268-
TestUtils.checkPodInitializing(pods[0], domain.getDomainNs());
269-
TestUtils.checkPodReady(pods[0], domain.getDomainNs());
268+
for (String pod : pods) {
269+
logger.info("Verifying if the pods are recreated with initialization");
270+
verifyPodInitialized(pod);
271+
}
270272
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
271273
}
272274

273275
/**
274-
* Add initContainers at domain and adminserver level and verify init containers are run at both
275-
* level
276+
* Add multiple initContainers at domain level and verify all of the init containers are run
276277
*
277278
* @throws Exception when domain.yaml cannot be read or modified to include the initContainers or
278279
* weblogic server pod doesn't go through initialization and ready state
@@ -286,13 +287,17 @@ public void testInitContainerMultiple() throws Exception {
286287

287288
// Modify the original domain yaml to include restartVersion in admin server node
288289
DomainCrd crd = new DomainCrd(originalYaml);
289-
crd.addInitContNode("spec", null, null, "busybox1");
290-
crd.addInitContNode("spec", null, null, "busybox2");
290+
crd.addInitContNode("spec", null, null, "busybox1", "sleep");
291+
crd.addInitContNode("spec", null, null, "busybox2", "sleep");
291292
String modYaml = crd.getYamlTree();
292293
logger.info(modYaml);
293294
testInitContainer(modYaml);
294-
TestUtils.checkPodInitializing(pods[0], domain.getDomainNs());
295-
TestUtils.checkPodReady(pods[0], domain.getDomainNs());
295+
String cmd = "kubectl get pod " + pods[0] + " -n " + domain.getDomainNs();
296+
for (String pod : pods) {
297+
TestUtils.checkCmdInLoop(cmd, "Init:0/2", pod);
298+
TestUtils.checkCmdInLoop(cmd, "Init:1/2", pod);
299+
TestUtils.checkPodReady(pod, domain.getDomainNs());
300+
}
296301
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
297302
}
298303

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ public void addObjectNodeToServerPod(String objectName, Map<String, String> attr
237237
}
238238

239239
public JsonNode addInitContNode(
240-
String parentNodeName, String clusterName, String msName, java.lang.String containerName) {
240+
String parentNodeName,
241+
String clusterName,
242+
String msName,
243+
java.lang.String containerName,
244+
String command) {
241245
ArrayNode initContNode = null;
242246
switch (parentNodeName) {
243247
case "spec":
@@ -260,7 +264,7 @@ public JsonNode addInitContNode(
260264
busybox.put("imagePullPolicy", "IfNotPresent");
261265
busybox.put("image", "busybox");
262266
ArrayNode commandArrayNode = objectMapper.createArrayNode();
263-
commandArrayNode.add("sleep");
267+
commandArrayNode.add(command);
264268
commandArrayNode.add("30");
265269
busybox.put("command", commandArrayNode);
266270
ArrayNode add = initContNode.add(busybox);

0 commit comments

Comments
 (0)