13
13
import oracle .kubernetes .operator .utils .Domain ;
14
14
import oracle .kubernetes .operator .utils .DomainCrd ;
15
15
import oracle .kubernetes .operator .utils .ExecResult ;
16
- import oracle .kubernetes .operator .utils .K8sTestUtils ;
17
16
import oracle .kubernetes .operator .utils .Operator ;
18
17
import oracle .kubernetes .operator .utils .TestUtils ;
19
18
import org .junit .AfterClass ;
24
23
import org .junit .Test ;
25
24
import org .junit .runners .MethodSorters ;
26
25
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 */
32
27
@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
33
28
public class ItInitContainers extends BaseTest {
34
29
@@ -90,6 +85,12 @@ public static void staticUnPrepare() throws Exception {
90
85
}
91
86
}
92
87
88
+ /**
89
+ * creates the init container domain on PV
90
+ *
91
+ * @return created domain Domain
92
+ * @throws Exception when domain creation fails
93
+ */
93
94
private static Domain createInitContdomain () throws Exception {
94
95
Map <String , Object > domainMap = TestUtils .loadYaml (DOMAINONPV_WLST_YAML );
95
96
domainMap .put ("domainUID" , domainUid );
@@ -100,21 +101,26 @@ private static Domain createInitContdomain() throws Exception {
100
101
return domain ;
101
102
}
102
103
104
+ /**
105
+ * destroys the running domain
106
+ *
107
+ * @throws Exception when domain destruction fails
108
+ */
103
109
private static void destroyInitContdomain () throws Exception {
104
110
if (domain != null ) {
105
111
domain .destroy ();
106
112
}
107
113
}
108
114
109
115
/**
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
112
118
*
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
115
121
*/
116
122
@ Test
117
- public void testAdminServerInitContainer () throws Exception {
123
+ public void testDomainInitContainer () throws Exception {
118
124
Assume .assumeFalse (QUICKTEST );
119
125
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
120
126
logTestBegin (testMethodName );
@@ -123,12 +129,89 @@ public void testAdminServerInitContainer() throws Exception {
123
129
// Modify the original domain yaml to include restartVersion in admin server node
124
130
DomainCrd crd = new DomainCrd (originalYaml );
125
131
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 );
126
154
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 );
127
177
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 );
128
200
crd .addInitContNode ("managedServers" , "cluster-1" , "managed-server1" );
129
201
String modYaml = crd .getYamlTree ();
130
202
logger .info (modYaml );
203
+ testInitContainer (modYaml , podName );
204
+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
205
+ }
131
206
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 {
132
215
// Write the modified yaml to a new file
133
216
Path path = Paths .get (initContainerTmpDir , "domain.yaml" );
134
217
logger .log (Level .INFO , "Path of the modified domain.yaml :{0}" , path .toString ());
@@ -142,44 +225,23 @@ public void testAdminServerInitContainer() throws Exception {
142
225
ExecResult exec = TestUtils .exec ("kubectl apply -f " + path .toString ());
143
226
logger .info (exec .stdout ());
144
227
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 );
153
230
}
154
231
155
232
/**
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 .
157
234
*
158
235
* @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
161
237
*/
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 );
182
242
}
183
- Assert .assertTrue ("Didn't get the expected pod status" , gotExpected );
243
+
244
+ // TestUtils.checkPodInitializing(podName, domain.getDomainNs());
245
+ // TestUtils.checkPodReady(podName, domain.getDomainNs());
184
246
}
185
247
}
0 commit comments