1
1
// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at
3
3
// http://oss.oracle.com/licenses/upl.
4
- package oracle .kubernetes .operator ;
5
4
6
- import static oracle .kubernetes .operator . BaseTest . logger ;
5
+ package oracle .kubernetes .operator ;
7
6
8
- import java .nio .charset .Charset ;
9
- import java .nio .charset .StandardCharsets ;
10
7
import java .nio .file .Files ;
11
- import java .nio .file .Path ;
12
8
import java .nio .file .Paths ;
13
9
import java .util .Map ;
14
10
import oracle .kubernetes .operator .utils .Domain ;
15
- import oracle .kubernetes .operator .utils .DomainCRD ;
16
- import oracle .kubernetes .operator .utils .ExecResult ;
17
11
import oracle .kubernetes .operator .utils .Operator ;
18
12
import oracle .kubernetes .operator .utils .TestUtils ;
19
13
import org .junit .AfterClass ;
@@ -34,8 +28,7 @@ public class ITPodsRestart extends BaseTest {
34
28
35
29
private static Domain domain = null ;
36
30
private static Operator operator1 ;
37
- private static String KUBE_EXEC_CMD ;
38
- private static String restartTmpDir = "" ;
31
+ private static String domainUid = "" ;
39
32
40
33
/**
41
34
* This method gets called only once before any of the test methods are executed. It does the
@@ -55,8 +48,6 @@ public static void staticPrepare() throws Exception {
55
48
if (operator1 == null ) {
56
49
operator1 = TestUtils .createOperator (OPERATOR1_YAML );
57
50
}
58
- restartTmpDir = BaseTest .getResultDir () + "/restarttemp" ;
59
- Files .createDirectories (Paths .get (restartTmpDir ));
60
51
61
52
domain = createPodsRestartdomain ();
62
53
Assert .assertNotNull (domain );
@@ -76,7 +67,7 @@ public static void staticUnPrepare() throws Exception {
76
67
logger .info ("Run once, release cluster lease" );
77
68
78
69
destroyPodsRestartdomain ();
79
- tearDown ();
70
+ tearDown (new Object () {}. getClass (). getEnclosingClass (). getSimpleName () );
80
71
81
72
logger .info ("SUCCESS" );
82
73
}
@@ -96,10 +87,10 @@ public void testServerPodsRestartByChangingEnvProperty() throws Exception {
96
87
logTestBegin (testMethodName );
97
88
98
89
logger .info (
99
- "About to testDomainServerPodRestart for Domain: "
90
+ "About to verifyDomainServerPodRestart for Domain: "
100
91
+ domain .getDomainUid ()
101
92
+ " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true" );
102
- domain .testDomainServerPodRestart (
93
+ domain .verifyDomainServerPodRestart (
103
94
"\" -Dweblogic.StdoutDebugEnabled=false\" " , "\" -Dweblogic.StdoutDebugEnabled=true\" " );
104
95
105
96
logger .info ("SUCCESS - " + testMethodName );
@@ -119,10 +110,10 @@ public void testServerPodsRestartByChangingLogHomeEnabled() throws Exception {
119
110
logTestBegin (testMethodName );
120
111
121
112
logger .info (
122
- "About to testDomainServerPodRestart for Domain: "
113
+ "About to verifyDomainServerPodRestart for Domain: "
123
114
+ domain .getDomainUid ()
124
115
+ " logHomeEnabled: true --> logHomeEnabled: false" );
125
- domain .testDomainServerPodRestart ("logHomeEnabled: true" , "logHomeEnabled: false" );
116
+ domain .verifyDomainServerPodRestart ("logHomeEnabled: true" , "logHomeEnabled: false" );
126
117
127
118
logger .info ("SUCCESS - " + testMethodName );
128
119
}
@@ -141,10 +132,10 @@ public void testServerPodsRestartByChangingImagePullPolicy() throws Exception {
141
132
logTestBegin (testMethodName );
142
133
143
134
logger .info (
144
- "About to testDomainServerPodRestart for Domain: "
135
+ "About to verifyDomainServerPodRestart for Domain: "
145
136
+ domain .getDomainUid ()
146
137
+ " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never " );
147
- domain .testDomainServerPodRestart (
138
+ domain .verifyDomainServerPodRestart (
148
139
"imagePullPolicy: \" IfNotPresent\" " , "imagePullPolicy: \" Never\" " );
149
140
150
141
logger .info ("SUCCESS - " + testMethodName );
@@ -164,10 +155,10 @@ public void testServerPodsRestartByChangingIncludeServerOutInPodLog() throws Exc
164
155
logTestBegin (testMethodName );
165
156
166
157
logger .info (
167
- "About to testDomainServerPodRestart for Domain: "
158
+ "About to verifyDomainServerPodRestart for Domain: "
168
159
+ domain .getDomainUid ()
169
160
+ " includeServerOutInPodLog: true --> includeServerOutInPodLog: false" );
170
- domain .testDomainServerPodRestart (
161
+ domain .verifyDomainServerPodRestart (
171
162
"includeServerOutInPodLog: true" , "includeServerOutInPodLog: false" );
172
163
173
164
logger .info ("SUCCESS - " + testMethodName );
@@ -188,12 +179,12 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
188
179
189
180
try {
190
181
logger .info (
191
- "About to testDomainServerPodRestart for Domain: "
182
+ "About to verifyDomainServerPodRestart for Domain: "
192
183
+ domain .getDomainUid ()
193
184
+ " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate" );
194
185
195
186
TestUtils .exec ("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate" );
196
- domain .testDomainServerPodRestart (
187
+ domain .verifyDomainServerPodRestart (
197
188
"\" store/oracle/weblogic:12.2.1.3\" " , "\" store/oracle/weblogic:duplicate\" " );
198
189
} finally {
199
190
TestUtils .exec ("docker rmi -f store/oracle/weblogic:duplicate" );
@@ -202,135 +193,115 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
202
193
logger .info ("SUCCESS - " + testMethodName );
203
194
}
204
195
196
+ /**
197
+ * Modify/Add the containerSecurityContext section at ServerPod Level using kubectl apply -f
198
+ * cont.security.context.domain.yaml. Verify all the pods re-started. The property tested is:
199
+ * serverPod: containerSecurityContext: runAsUser: 1000 fsGroup: 1000.
200
+ *
201
+ * @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers
202
+ * are not restarted or after restart the server yaml file doesn't include the new added
203
+ * property
204
+ */
205
205
@ Test
206
- public void testAdminServerRestartVersions () throws Exception {
206
+ public void testServerPodsRestartByChangingContSecurityContext () throws Exception {
207
207
Assume .assumeFalse (QUICKTEST );
208
208
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
209
209
logTestBegin (testMethodName );
210
- String originalYaml =
211
- BaseTest .getUserProjectsDir ()
212
- + "/weblogic-domains/"
213
- + domain .getDomainUid ()
214
- + "/domain.yaml" ;
215
- try {
216
- DomainCRD crd = new DomainCRD ();
217
- String yaml =
218
- crd .addRestartVersionToAdminServer (
219
- TestUtils .exec (
220
- "kubectl get Domain "
221
- + domain .getDomainUid ()
222
- + " -n "
223
- + domain .getDomainNS ()
224
- + " --output json" )
225
- .stdout (),
226
- "v1.1" );
227
- Path path = Paths .get (restartTmpDir , "restart.admin.yaml" );
228
- Charset charset = StandardCharsets .UTF_8 ;
229
- Files .write (path , yaml .getBytes (charset ));
230
- logger .info (TestUtils .exec ("kubectl apply -f " + path .toString ()).stdout ());
231
- domain .verifyAdminServerRestarted ();
232
- } finally {
233
- TestUtils .exec ("kubectl apply -f " + originalYaml );
234
- domain .verifyAdminServerRestarted ();
235
- }
236
- logger .info ("SUCCESS - " + testMethodName );
237
- }
238
210
239
- // @Test
240
- public void testClusterRestartVersions () throws Exception {
241
- Assume .assumeFalse (QUICKTEST );
242
- String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
243
- logTestBegin (testMethodName );
244
- ExecResult result ;
245
- String originalYaml =
246
- BaseTest .getUserProjectsDir ()
247
- + "/weblogic-domains/"
211
+ // firstly ensure that original domain.yaml doesn't include the property-to-be-added
212
+ String domainFileName =
213
+ BaseTest .getUserProjectsDir () + "/weblogic-domains/" + domainUid + "/domain.yaml" ;
214
+ boolean result =
215
+ (new String (Files .readAllBytes (Paths .get (domainFileName )))).contains ("fsGroup: 1000" );
216
+ Assert .assertFalse (result );
217
+
218
+ // domainYaml: the yaml file name with changed property under resources dir
219
+ String domainYaml = "cont.security.context.domain.yaml" ;
220
+ logger .info (
221
+ "About to verifyDomainServerPodRestart for Domain: "
248
222
+ domain .getDomainUid ()
249
- + "/domain.yaml" ;
250
- try {
251
- result =
252
- TestUtils .exec (
253
- "kubectl get Domain "
254
- + domain .getDomainUid ()
255
- + " -n "
256
- + domain .getDomainNS ()
257
- + " --output json" );
258
- DomainCRD parser = new DomainCRD ();
259
- String yaml =
260
- parser .addRestartVersionToCluster (
261
- result .stdout (), domain .getDomainMap ().get ("clusterName" ).toString (), "v1.1" );
262
- Path path = Paths .get (restartTmpDir , "restart.cluster.yaml" );
263
- Charset charset = StandardCharsets .UTF_8 ;
264
- Files .write (path , yaml .getBytes (charset ));
265
- result = TestUtils .exec ("kubectl apply -f " + path .toString ());
266
- // TODO - verify that the pod is restarting
267
- } finally {
268
- result = TestUtils .exec ("kubectl apply -f " + originalYaml );
269
- }
223
+ + " change container securityContext:\n "
224
+ + " runAsUser: 1000\n "
225
+ + " fsGroup: 1000 " );
226
+ domain .verifyDomainServerPodRestart (domainYaml );
227
+ domain .findServerPropertyChange ("securityContext" , "admin-server" );
228
+ domain .findServerPropertyChange ("securityContext" , "managed-server1" );
229
+
270
230
logger .info ("SUCCESS - " + testMethodName );
271
231
}
272
232
273
- // @Test
274
- public void testMSRestartVersions () throws Exception {
233
+ /**
234
+ * Modify/Add the podSecurityContext section at ServerPod level using kubectl apply -f
235
+ * pod.security.context.domain.yaml. Verify all the pods re-started. The property tested is:
236
+ * podSecurityContext: runAsUser: 1000 fsGroup: 2000.
237
+ *
238
+ * @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers
239
+ * are not restarted or after restart the server yaml file doesn't include the new added
240
+ * property
241
+ */
242
+ @ Test
243
+ public void testServerPodsRestartByChangingPodSecurityContext () throws Exception {
275
244
Assume .assumeFalse (QUICKTEST );
276
245
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
277
246
logTestBegin (testMethodName );
278
- ExecResult result ;
279
- String originalYaml =
280
- BaseTest .getUserProjectsDir ()
281
- + "/weblogic-domains/"
247
+
248
+ // firstly ensure that original domain.yaml doesn't include the property-to-be-added
249
+ String domainFileName =
250
+ BaseTest .getUserProjectsDir () + "/weblogic-domains/" + domainUid + "/domain.yaml" ;
251
+ boolean result =
252
+ (new String (Files .readAllBytes (Paths .get (domainFileName )))).contains ("fsGroup: 2000" );
253
+ Assert .assertFalse (result );
254
+
255
+ // domainYaml: the yaml file name with changed property under resources dir
256
+ String domainYaml = "pod.security.context.domain.yaml" ;
257
+
258
+ logger .info (
259
+ "About to verifyDomainServerPodRestart for Domain: "
282
260
+ domain .getDomainUid ()
283
- + "/domain.yaml" ;
284
- try {
285
- result =
286
- TestUtils .exec (
287
- "kubectl get Domain "
288
- + domain .getDomainUid ()
289
- + " -n "
290
- + domain .getDomainNS ()
291
- + " --output json" );
292
- DomainCRD parser = new DomainCRD ();
293
- String yaml = parser .addRestartVersionToMS (result .stdout (), "managed-server1" , "v1.1" );
294
- Path path = Paths .get (restartTmpDir , "restart.ms.yaml" );
295
- Charset charset = StandardCharsets .UTF_8 ;
296
- Files .write (path , yaml .getBytes (charset ));
297
- result = TestUtils .exec ("kubectl apply -f " + path .toString ());
298
- // TODO - verify that the pod is restarting
299
- } finally {
300
- result = TestUtils .exec ("kubectl apply -f " + originalYaml );
301
- }
261
+ + " change securityContext:\n "
262
+ + " runAsUser: 1000\n "
263
+ + " fsGroup: 2000 " );
264
+ domain .verifyDomainServerPodRestart (domainYaml );
265
+ domain .findServerPropertyChange ("fsGroup: 2000" , "admin-server" );
266
+ domain .findServerPropertyChange ("fsGroup: 2000" , "managed-server1" );
267
+
302
268
logger .info ("SUCCESS - " + testMethodName );
303
269
}
304
270
305
- // @Test
306
- public void testDomainRestartVersions () throws Exception {
271
+ /**
272
+ * Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml. Verify all pods
273
+ * re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: -
274
+ * -cpus - "2".
275
+ *
276
+ * @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers
277
+ * are not restarted or after restart the server yaml file doesn't include the new added
278
+ * property
279
+ */
280
+ @ Test
281
+ public void testServerPodsRestartByChangingResource () throws Exception {
307
282
Assume .assumeFalse (QUICKTEST );
308
283
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
309
284
logTestBegin (testMethodName );
310
- ExecResult result ;
311
- String originalYaml =
312
- BaseTest .getUserProjectsDir ()
313
- + "/weblogic-domains/"
285
+
286
+ // firstly ensure that original domain.yaml doesn't include the property-to-be-addeded
287
+ String domainFileName =
288
+ BaseTest .getUserProjectsDir () + "/weblogic-domains/" + domainUid + "/domain.yaml" ;
289
+ boolean result =
290
+ (new String (Files .readAllBytes (Paths .get (domainFileName )))).contains ("cpu: 500m" );
291
+ Assert .assertFalse (result );
292
+
293
+ // domainYaml: the yaml file name with changed property under resources dir
294
+ String domainYaml = "resource.domain.yaml" ;
295
+
296
+ logger .info (
297
+ "About to verifyDomainServerPodRestart for Domain: "
314
298
+ domain .getDomainUid ()
315
- + "/domain.yaml" ;
316
- try {
317
- result =
318
- TestUtils .exec (
319
- "kubectl get Domain "
320
- + domain .getDomainUid ()
321
- + " -n "
322
- + domain .getDomainNS ()
323
- + " --output json" );
324
- DomainCRD parser = new DomainCRD ();
325
- String yaml = parser .addRestartVersionToDomain (result .stdout (), "v1.1" );
326
- Path path = Paths .get (restartTmpDir , "restart.ms.yaml" );
327
- Charset charset = StandardCharsets .UTF_8 ;
328
- Files .write (path , yaml .getBytes (charset ));
329
- result = TestUtils .exec ("kubectl apply -f " + path .toString ());
330
- // TODO - verify that the pod is restarting
331
- } finally {
332
- result = TestUtils .exec ("kubectl apply -f " + originalYaml );
333
- }
299
+ + " change resource:\n "
300
+ + " cpu: 500m" );
301
+ domain .verifyDomainServerPodRestart (domainYaml );
302
+ domain .findServerPropertyChange ("cpu: 500m" , "admin-server" );
303
+ domain .findServerPropertyChange ("cpu: 500m" , "managed-server1" );
304
+
334
305
logger .info ("SUCCESS - " + testMethodName );
335
306
}
336
307
@@ -340,7 +311,9 @@ private static Domain createPodsRestartdomain() throws Exception {
340
311
domainMap .put ("domainUID" , "domainpodsrestart" );
341
312
domainMap .put ("initialManagedServerReplicas" , new Integer ("1" ));
342
313
343
- logger .info ("Creating Domain domain& verifing the domain creation" );
314
+ domainUid = (String ) domainMap .get ("domainUID" );
315
+ logger .info ("Creating and verifying the domain creation with domainUid: " + domainUid );
316
+
344
317
domain = TestUtils .createDomain (domainMap );
345
318
domain .verifyDomainCreated ();
346
319
0 commit comments