3
3
4
4
package oracle .weblogic .kubernetes ;
5
5
6
+ import java .io .IOException ;
7
+ import java .nio .charset .StandardCharsets ;
6
8
import java .nio .file .Files ;
7
9
import java .nio .file .Path ;
8
10
import java .nio .file .Paths ;
23
25
import oracle .weblogic .domain .Model ;
24
26
import oracle .weblogic .domain .OnlineUpdate ;
25
27
import oracle .weblogic .domain .ServerPod ;
28
+ import oracle .weblogic .kubernetes .actions .ActionConstants ;
26
29
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
27
30
import oracle .weblogic .kubernetes .annotations .Namespaces ;
28
31
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
32
+ import oracle .weblogic .kubernetes .utils .ExecCommand ;
29
33
import oracle .weblogic .kubernetes .utils .ExecResult ;
34
+ import org .junit .jupiter .api .AfterAll ;
30
35
import org .junit .jupiter .api .BeforeAll ;
31
36
import org .junit .jupiter .api .BeforeEach ;
32
37
import org .junit .jupiter .api .DisplayName ;
38
43
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
39
44
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
40
45
import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
46
+ import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
41
47
import static oracle .weblogic .kubernetes .TestConstants .MANAGED_SERVER_NAME_BASE ;
42
48
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_APP_DEPLOYMENT_NAME ;
43
49
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_NAME ;
44
50
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_TAG ;
45
51
import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
46
52
import static oracle .weblogic .kubernetes .TestConstants .SSL_PROPERTIES ;
47
53
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
48
- import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_SLIM ;
49
54
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
50
55
import static oracle .weblogic .kubernetes .actions .ActionConstants .WORK_DIR ;
51
56
import static oracle .weblogic .kubernetes .actions .TestActions .createDomainCustomResource ;
@@ -187,6 +192,25 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
187
192
domainNamespace );
188
193
}
189
194
195
+ @ AfterAll
196
+ public static void cleanup () {
197
+ Path dstFile = Paths .get (TestConstants .RESULTS_ROOT , "traefik/traefik-ingress-rules-tcp.yaml" );
198
+ assertDoesNotThrow (() -> {
199
+ String command = KUBERNETES_CLI + " delete -f " + dstFile ;
200
+ logger .info ("Running {0}" , command );
201
+ ExecResult result ;
202
+ try {
203
+ result = ExecCommand .exec (command , true );
204
+ String response = result .stdout ().trim ();
205
+ logger .info ("exitCode: {0}, \n stdout: {1}, \n stderr: {2}" ,
206
+ result .exitValue (), response , result .stderr ());
207
+ assertEquals (0 , result .exitValue (), "Command didn't succeed" );
208
+ } catch (IOException | InterruptedException ex ) {
209
+ logger .severe (ex .getMessage ());
210
+ }
211
+ });
212
+ }
213
+
190
214
/**
191
215
* Verify all server pods are running.
192
216
* Verify all k8s services for all servers are created.
@@ -251,49 +275,36 @@ void testVerifyProductionSecureMode() {
251
275
logger .info ("The hostAndPort is {0}" , hostAndPort );
252
276
253
277
String resourcePath = "/weblogic/ready" ;
254
- if (!WEBLOGIC_SLIM ) {
255
- if (OKE_CLUSTER ) {
256
- ExecResult result = exeAppInServerPod (domainNamespace , adminServerPodName ,7002 , resourcePath );
257
- logger .info ("result in OKE_CLUSTER is {0}" , result .toString ());
258
- assertEquals (0 , result .exitValue (), "Failed to access WebLogic readyapp" );
259
- } else {
260
- String curlCmd = "curl -g -sk --show-error --noproxy '*' "
261
- + " https://" + hostAndPort
262
- + "/weblogic/ready --write-out %{http_code} "
263
- + " -o /dev/null" ;
264
- logger .info ("Executing default-admin nodeport curl command {0}" , curlCmd );
265
- assertTrue (callWebAppAndWaitTillReady (curlCmd , 10 ));
266
- }
267
- logger .info ("WebLogic readyapp is accessible thru default-admin service" );
268
-
269
- String localhost = "localhost" ;
270
- String forwardPort = startPortForwardProcess (localhost , domainNamespace , domainUid , 9002 );
271
- assertNotNull (forwardPort , "port-forward fails to assign local port" );
272
- logger .info ("Forwarded admin-port is {0}" , forwardPort );
273
- String curlCmd = "curl -sk --show-error --noproxy '*' "
274
- + " https://" + localhost + ":" + forwardPort
275
- + "/weblogic/ready --write-out %{http_code} "
276
- + " -o /dev/null" ;
277
- logger .info ("Executing default-admin port-fwd curl command {0}" , curlCmd );
278
- assertTrue (callWebAppAndWaitTillReady (curlCmd , 10 ));
279
- logger .info ("WebLogic readyapp is accessible thru admin port forwarding" );
280
-
281
- // When port-forwarding is happening on admin-port, port-forwarding will
282
- // not work for SSL port i.e. 7002
283
- forwardPort = startPortForwardProcess (localhost , domainNamespace , domainUid , 7002 );
284
- assertNotNull (forwardPort , "port-forward fails to assign local port" );
285
- logger .info ("Forwarded ssl port is {0}" , forwardPort );
286
- curlCmd = "curl -g -sk --show-error --noproxy '*' "
287
- + " https://" + localhost + ":" + forwardPort
288
- + "/weblogic/ready --write-out %{http_code} "
289
- + " -o /dev/null" ;
290
- logger .info ("Executing default-admin port-fwd curl command {0}" , curlCmd );
291
- assertFalse (callWebAppAndWaitTillReady (curlCmd , 10 ));
292
- logger .info ("WebLogic readyapp should not be accessible thru ssl port forwarding" );
293
- stopPortForwardProcess (domainNamespace );
294
- } else {
295
- logger .info ("Skipping WebLogic reeadyapp check in WebLogic slim image" );
296
- }
278
+ ExecResult result = exeAppInServerPod (domainNamespace , adminServerPodName , 7002 , resourcePath );
279
+ logger .info ("result in OKE_CLUSTER is {0}" , result .toString ());
280
+ assertEquals (0 , result .exitValue (), "Failed to access WebLogic readyapp" );
281
+ logger .info ("WebLogic readyapp is accessible thru default-admin service" );
282
+
283
+ String localhost = "localhost" ;
284
+ String forwardPort = startPortForwardProcess (localhost , domainNamespace , domainUid , 9002 );
285
+ assertNotNull (forwardPort , "port-forward fails to assign local port" );
286
+ logger .info ("Forwarded admin-port is {0}" , forwardPort );
287
+ String curlCmd = "curl -sk --show-error --noproxy '*' "
288
+ + " https://" + localhost + ":" + forwardPort
289
+ + "/weblogic/ready --write-out %{http_code} "
290
+ + " -o /dev/null" ;
291
+ logger .info ("Executing default-admin port-fwd curl command {0}" , curlCmd );
292
+ assertTrue (callWebAppAndWaitTillReady (curlCmd , 10 ));
293
+ logger .info ("WebLogic readyapp is accessible thru admin port forwarding" );
294
+
295
+ // When port-forwarding is happening on admin-port, port-forwarding will
296
+ // not work for SSL port i.e. 7002
297
+ forwardPort = startPortForwardProcess (localhost , domainNamespace , domainUid , 7002 );
298
+ assertNotNull (forwardPort , "port-forward fails to assign local port" );
299
+ logger .info ("Forwarded ssl port is {0}" , forwardPort );
300
+ curlCmd = "curl -g -sk --show-error --noproxy '*' "
301
+ + " https://" + localhost + ":" + forwardPort
302
+ + "/weblogic/ready --write-out %{http_code} "
303
+ + " -o /dev/null" ;
304
+ logger .info ("Executing default-admin port-fwd curl command {0}" , curlCmd );
305
+ assertFalse (callWebAppAndWaitTillReady (curlCmd , 10 ));
306
+ logger .info ("WebLogic readyapp should not be accessible thru ssl port forwarding" );
307
+ stopPortForwardProcess (domainNamespace );
297
308
298
309
int nodePort = getServiceNodePort (
299
310
domainNamespace , getExternalServicePodName (adminServerPodName ), "default" );
@@ -337,6 +348,11 @@ void testMiiDynamicChangeWithSSLEnabled() {
337
348
String introspectVersion = patchDomainResourceWithNewIntrospectVersion (domainUid , domainNamespace );
338
349
339
350
verifyIntrospectorRuns (domainUid , domainNamespace );
351
+ String sslChannelName = "default-admin" ;
352
+ if (TestConstants .KIND_CLUSTER
353
+ && !TestConstants .WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
354
+ createTraefikIngressRoutingRules (domainNamespace );
355
+ }
340
356
341
357
String resourcePath = "/management/weblogic/latest/domainRuntime/serverRuntimes/"
342
358
+ MANAGED_SERVER_NAME_BASE + "1"
@@ -356,7 +372,7 @@ void testMiiDynamicChangeWithSSLEnabled() {
356
372
+ MANAGED_SERVER_NAME_BASE + "1"
357
373
+ "/applicationRuntimes/" + MII_BASIC_APP_DEPLOYMENT_NAME
358
374
+ "/workManagerRuntimes/newWM" ,
359
- "200" , true , "default-admin" ),
375
+ "200" , true , sslChannelName ),
360
376
logger , "work manager configuration to be updated." );
361
377
}
362
378
@@ -423,4 +439,28 @@ private static void createDomainResource(
423
439
assertTrue (domCreated , String .format ("Create domain custom resource failed with ApiException "
424
440
+ "for %s in namespace %s" , domainUid , domNamespace ));
425
441
}
442
+
443
+ private static void createTraefikIngressRoutingRules (String domainNamespace ) {
444
+ logger .info ("Creating ingress rules for domain traffic routing" );
445
+ Path srcFile = Paths .get (ActionConstants .RESOURCE_DIR , "traefik/traefik-ingress-rules-tcp.yaml" );
446
+ Path dstFile = Paths .get (TestConstants .RESULTS_ROOT , "traefik/traefik-ingress-rules-tcp.yaml" );
447
+ assertDoesNotThrow (() -> {
448
+ Files .deleteIfExists (dstFile );
449
+ Files .createDirectories (dstFile .getParent ());
450
+ Files .write (dstFile , Files .readString (srcFile ).replaceAll ("@NS@" , domainNamespace )
451
+ .getBytes (StandardCharsets .UTF_8 ));
452
+ });
453
+ String command = KUBERNETES_CLI + " create -f " + dstFile ;
454
+ logger .info ("Running {0}" , command );
455
+ ExecResult result ;
456
+ try {
457
+ result = ExecCommand .exec (command , true );
458
+ String response = result .stdout ().trim ();
459
+ logger .info ("exitCode: {0}, \n stdout: {1}, \n stderr: {2}" ,
460
+ result .exitValue (), response , result .stderr ());
461
+ assertEquals (0 , result .exitValue (), "Command didn't succeed" );
462
+ } catch (IOException | InterruptedException ex ) {
463
+ logger .severe (ex .getMessage ());
464
+ }
465
+ }
426
466
}
0 commit comments