Skip to content

Commit 124bf41

Browse files
committed
add remaining tests
1 parent 2e514cb commit 124bf41

File tree

3 files changed

+146
-65
lines changed

3 files changed

+146
-65
lines changed

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

Lines changed: 105 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import oracle.kubernetes.operator.utils.Domain;
1414
import oracle.kubernetes.operator.utils.DomainCrd;
1515
import oracle.kubernetes.operator.utils.ExecResult;
16-
import oracle.kubernetes.operator.utils.K8sTestUtils;
1716
import oracle.kubernetes.operator.utils.Operator;
1817
import oracle.kubernetes.operator.utils.TestUtils;
1918
import org.junit.AfterClass;
@@ -24,11 +23,7 @@
2423
import org.junit.Test;
2524
import org.junit.runners.MethodSorters;
2625

27-
/**
28-
* Simple JUnit test file used for testing Operator.
29-
*
30-
* <p>This test is used for testing pods being restarted by some properties change.
31-
*/
26+
/** Integration tests for testing the init container for weblogic server pods */
3227
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3328
public class ItInitContainers extends BaseTest {
3429

@@ -90,6 +85,12 @@ public static void staticUnPrepare() throws Exception {
9085
}
9186
}
9287

88+
/**
89+
* creates the init container domain on PV
90+
*
91+
* @return created domain Domain
92+
* @throws Exception when domain creation fails
93+
*/
9394
private static Domain createInitContdomain() throws Exception {
9495
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
9596
domainMap.put("domainUID", domainUid);
@@ -100,21 +101,26 @@ private static Domain createInitContdomain() throws Exception {
100101
return domain;
101102
}
102103

104+
/**
105+
* destroys the running domain
106+
*
107+
* @throws Exception when domain destruction fails
108+
*/
103109
private static void destroyInitContdomain() throws Exception {
104110
if (domain != null) {
105111
domain.destroy();
106112
}
107113
}
108114

109115
/**
110-
* Add restartVersion:v1.1 at adminServer level and verify the admin pod is Terminated and
111-
* recreated
116+
* Add initContainers at domain spec level and verify the admin server pod goes through Init state
117+
* before starting the admin server pod
112118
*
113-
* @throws Exception when domain.yaml cannot be read or modified to include the
114-
* restartVersion:v1.1
119+
* @throws Exception when domain.yaml cannot be read or modified to include the initContainers or
120+
* weblogic server pod doesn't go through initialization and ready state
115121
*/
116122
@Test
117-
public void testAdminServerInitContainer() throws Exception {
123+
public void testDomainInitContainer() throws Exception {
118124
Assume.assumeFalse(QUICKTEST);
119125
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
120126
logTestBegin(testMethodName);
@@ -123,12 +129,89 @@ public void testAdminServerInitContainer() throws Exception {
123129
// Modify the original domain yaml to include restartVersion in admin server node
124130
DomainCrd crd = new DomainCrd(originalYaml);
125131
crd.addInitContNode("spec", null, null);
132+
String modYaml = crd.getYamlTree();
133+
logger.info(modYaml);
134+
testInitContainer(modYaml, podName);
135+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
136+
}
137+
138+
/**
139+
* Add initContainers to adminServer and verify the admin server pod goes through Init state
140+
* before starting the admin server pod
141+
*
142+
* @throws Exception when domain.yaml cannot be read or modified to include the initContainers or
143+
* weblogic server pod doesn't go through initialization and ready state
144+
*/
145+
@Test
146+
public void testAdminServerInitContainer() throws Exception {
147+
Assume.assumeFalse(QUICKTEST);
148+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
149+
logTestBegin(testMethodName);
150+
String podName = domainUid + "-" + domain.getAdminServerName();
151+
152+
// Modify the original domain yaml to include restartVersion in admin server node
153+
DomainCrd crd = new DomainCrd(originalYaml);
126154
crd.addInitContNode("adminServer", null, null);
155+
String modYaml = crd.getYamlTree();
156+
logger.info(modYaml);
157+
testInitContainer(modYaml, podName);
158+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
159+
}
160+
161+
/**
162+
* Add initContainers to adminServer and verify the admin server pod goes through Init state
163+
* before starting the admin server pod
164+
*
165+
* @throws Exception when domain.yaml cannot be read or modified to include the initContainers or
166+
* weblogic server pod doesn't go through initialization and ready state
167+
*/
168+
@Test
169+
public void testClusterInitContainer() throws Exception {
170+
Assume.assumeFalse(QUICKTEST);
171+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
172+
logTestBegin(testMethodName);
173+
String podName = domainUid + "-" + domain.getAdminServerName();
174+
175+
// Modify the original domain yaml to include restartVersion in admin server node
176+
DomainCrd crd = new DomainCrd(originalYaml);
127177
crd.addInitContNode("clusters", "cluster-1", null);
178+
String modYaml = crd.getYamlTree();
179+
logger.info(modYaml);
180+
testInitContainer(modYaml, podName);
181+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
182+
}
183+
184+
/**
185+
* Add initContainers to adminServer and verify the admin server pod goes through Init state
186+
* before starting the admin server pod
187+
*
188+
* @throws Exception when domain.yaml cannot be read or modified to include the initContainers or
189+
* weblogic server pod doesn't go through initialization and ready state
190+
*/
191+
@Test
192+
public void testMSInitContainer() throws Exception {
193+
Assume.assumeFalse(QUICKTEST);
194+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
195+
logTestBegin(testMethodName);
196+
String podName = domainUid + "-" + domain.getAdminServerName();
197+
198+
// Modify the original domain yaml to include restartVersion in admin server node
199+
DomainCrd crd = new DomainCrd(originalYaml);
128200
crd.addInitContNode("managedServers", "cluster-1", "managed-server1");
129201
String modYaml = crd.getYamlTree();
130202
logger.info(modYaml);
203+
testInitContainer(modYaml, podName);
204+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
205+
}
131206

207+
/**
208+
* Add initContainers to adminServer and verify the admin server pod goes through Init state
209+
* before starting the admin server pod
210+
*
211+
* @throws Exception when domain.yaml cannot be read or modified to include the initContainers or
212+
* weblogic server pod doesn't go through initialization and ready state
213+
*/
214+
private void testInitContainer(String modYaml, String podName) throws Exception {
132215
// Write the modified yaml to a new file
133216
Path path = Paths.get(initContainerTmpDir, "domain.yaml");
134217
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
@@ -142,44 +225,23 @@ public void testAdminServerInitContainer() throws Exception {
142225
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
143226
logger.info(exec.stdout());
144227

145-
logger.info("Verifying if the admin server pod is recreated");
146-
// domain.verifyAdminServerRestarted();
147-
for (int i = 0; i < 30; i++) {
148-
Thread.sleep(1000 * 10);
149-
TestUtils.exec("kubectl get all --all-namespaces", true);
150-
}
151-
152-
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
228+
logger.info("Verifying if the server pod is recreated with initialization");
229+
verifyPodInitialized(podName);
153230
}
154231

155232
/**
156-
* Utility method to check if a pod is in Terminating or Running status.
233+
* Utility method to check if a pod goes through initialization and Ready.
157234
*
158235
* @param podName - String name of the pod to check the status for
159-
* @param podStatusExpected - String the expected status of Terminating || RUnning
160-
* @throws InterruptedException when thread is interrupted
236+
* @throws Exception when pod doesn't go through the initialization and ready state
161237
*/
162-
private void verifyPodStatus(String podName, String podStatusExpected)
163-
throws InterruptedException {
164-
K8sTestUtils testUtil = new K8sTestUtils();
165-
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", domainUid);
166-
String namespace = domain.getDomainNs();
167-
boolean gotExpected = false;
168-
for (int i = 0; i < BaseTest.getMaxIterationsPod(); i++) {
169-
if (podStatusExpected.equals("Terminating")) {
170-
if (testUtil.isPodTerminating(namespace, domain1LabelSelector, podName)) {
171-
gotExpected = true;
172-
break;
173-
}
174-
} else if (podStatusExpected.equals("Running")) {
175-
if (testUtil.isPodRunning(namespace, domain1LabelSelector, podName)) {
176-
gotExpected = true;
177-
break;
178-
}
179-
}
180-
181-
Thread.sleep(BaseTest.getWaitTimePod() * 1000);
238+
private void verifyPodInitialized(String podName) throws Exception {
239+
for (int i = 0; i < 30; i++) {
240+
Thread.sleep(1000 * 10);
241+
TestUtils.exec("kubectl get all --all-namespaces", true);
182242
}
183-
Assert.assertTrue("Didn't get the expected pod status", gotExpected);
243+
244+
// TestUtils.checkPodInitializing(podName, domain.getDomainNs());
245+
// TestUtils.checkPodReady(podName, domain.getDomainNs());
184246
}
185247
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public JsonNode addInitContNode(String parentNodeName, String clusterName, Strin
260260
busybox.put("image", "busybox");
261261
ArrayNode commandArrayNode = objectMapper.createArrayNode();
262262
commandArrayNode.add("sleep");
263-
commandArrayNode.add(120);
263+
commandArrayNode.add("30");
264264
busybox.put("command", commandArrayNode);
265265
ArrayNode add = initContNode.add(busybox);
266266
try {

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

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import javax.ws.rs.core.HttpHeaders;
2929
import javax.ws.rs.core.MediaType;
3030
import javax.ws.rs.core.Response;
31-
3231
import oracle.kubernetes.operator.BaseTest;
3332
import oracle.kubernetes.operator.utils.Operator.RestCertType;
3433
import org.glassfish.jersey.jsonp.JsonProcessingFeature;
@@ -87,6 +86,21 @@ public static void checkPodCreated(String podName, String domainNS) throws Excep
8786
checkCmdInLoop(cmd.toString(), "Running", podName);
8887
}
8988

89+
/**
90+
* Checks that pod is initializing.
91+
*
92+
* @param podName - pod name
93+
* @param domainNS - domain namespace name
94+
*/
95+
public static void checkPodInitializing(String podName, String domainNS) throws Exception {
96+
97+
StringBuffer cmd = new StringBuffer();
98+
cmd.append("kubectl get pod ").append(podName).append(" -n ").append(domainNS);
99+
100+
// check for admin pod
101+
checkCmdInLoop(cmd.toString(), "Init", podName);
102+
}
103+
90104
/**
91105
* check pod is in Terminating state.
92106
*
@@ -787,19 +801,20 @@ public static Domain createDomain(String inputYaml) throws Exception {
787801
logger.info("Creating domain with yaml, waiting for the script to complete execution");
788802
return new Domain(inputYaml);
789803
}
790-
791-
public static Domain createDomain(String inputYaml, boolean createDomainResource) throws Exception {
804+
805+
public static Domain createDomain(String inputYaml, boolean createDomainResource)
806+
throws Exception {
792807
logger.info("Creating domain with yaml, waiting for the script to complete execution");
793808
return new Domain(inputYaml, createDomainResource);
794809
}
795-
810+
796811
public static Domain createDomain(Map<String, Object> inputDomainMap) throws Exception {
797812
logger.info("Creating domain with Map, waiting for the script to complete execution");
798813
return new Domain(inputDomainMap);
799814
}
800-
801-
public static Domain createDomain(Map<String, Object> inputDomainMap, boolean createDomainResource)
802-
throws Exception {
815+
816+
public static Domain createDomain(
817+
Map<String, Object> inputDomainMap, boolean createDomainResource) throws Exception {
803818
logger.info("Creating domain with Map, waiting for the script to complete execution");
804819
return new Domain(inputDomainMap, createDomainResource);
805820
}
@@ -1225,37 +1240,41 @@ private static KeyStore createKeyStore(Operator operator) throws Exception {
12251240
}
12261241

12271242
/**
1228-
*
12291243
* @param cmd command to run in the loop
12301244
* @param matchStr expected string to match in the output
12311245
* @return ExecResult object containing command output info
12321246
* @throws Exception exception if fails to execute
12331247
*/
1234-
public static ExecResult checkAnyCmdInLoop(String cmd, String matchStr)
1235-
throws Exception {
1248+
public static ExecResult checkAnyCmdInLoop(String cmd, String matchStr) throws Exception {
12361249
int i = 0;
12371250
ExecResult result = null;
12381251
while (i < BaseTest.getMaxIterationsPod()) {
12391252
result = ExecCommand.exec(cmd);
12401253

12411254
if (result.exitValue() != 0
1242-
|| (result.exitValue() == 0 && !result.stdout().contains(matchStr))) {
1255+
|| (result.exitValue() == 0 && !result.stdout().contains(matchStr))) {
12431256
logger.info("Output for " + cmd + "\n" + result.stdout() + "\n " + result.stderr());
12441257
// check for last iteration
12451258
if (i == (BaseTest.getMaxIterationsPod() - 1)) {
12461259
throw new RuntimeException(
1247-
"FAILURE: expected output " + matchStr + " from command " + cmd + " is not receieved, exiting!");
1260+
"FAILURE: expected output "
1261+
+ matchStr
1262+
+ " from command "
1263+
+ cmd
1264+
+ " is not receieved, exiting!");
12481265
}
12491266
logger.info(
1250-
"did not receive the expected output "
1251-
+ matchStr
1252-
+ "from command " + cmd + " Ite ["
1253-
+ i
1254-
+ "/"
1255-
+ BaseTest.getMaxIterationsPod()
1256-
+ "], sleeping "
1257-
+ BaseTest.getWaitTimePod()
1258-
+ " seconds more");
1267+
"did not receive the expected output "
1268+
+ matchStr
1269+
+ "from command "
1270+
+ cmd
1271+
+ " Ite ["
1272+
+ i
1273+
+ "/"
1274+
+ BaseTest.getMaxIterationsPod()
1275+
+ "], sleeping "
1276+
+ BaseTest.getWaitTimePod()
1277+
+ " seconds more");
12591278

12601279
Thread.sleep(BaseTest.getWaitTimePod() * 1000);
12611280
i++;

0 commit comments

Comments
 (0)