14
14
import java .nio .file .StandardOpenOption ;
15
15
import java .util .Map ;
16
16
import java .util .logging .Level ;
17
-
18
17
import oracle .kubernetes .operator .utils .Domain ;
19
18
import oracle .kubernetes .operator .utils .ExecResult ;
20
19
import oracle .kubernetes .operator .utils .Operator ;
@@ -82,7 +81,14 @@ public static void staticPrepare() throws Exception {
82
81
fqdn = TestUtils .getHostName ();
83
82
JDBC_URL = "jdbc:mysql://" + fqdn + ":" + MYSQL_DB_PORT + "/" ;
84
83
// copy the configuration override files to replacing the JDBC_URL token
85
- copySitConfigFiles ();
84
+ String [] files = {
85
+ "config.xml" ,
86
+ "jdbc-JdbcTestDataSource-0.xml" ,
87
+ "diagnostics-WLDF-MODULE-0.xml" ,
88
+ "jms-ClusterJmsSystemResource.xml" ,
89
+ "version.txt"
90
+ };
91
+ copySitConfigFiles (files , "test-secrets" );
86
92
// create weblogic domain with configOverrides
87
93
domain = createSitConfigDomain ();
88
94
Assert .assertNotNull (domain );
@@ -132,7 +138,6 @@ public static void staticUnPrepare() throws Exception {
132
138
* @throws Exception - if it cannot create the domain
133
139
*/
134
140
private static Domain createSitConfigDomain () throws Exception {
135
- String createDomainScript = TEST_RES_DIR + "/domain-home-on-pv/create-domain.py" ;
136
141
// load input yaml to map and add configOverrides
137
142
Map <String , Object > domainMap = TestUtils .loadYaml (DOMAINONPV_WLST_YAML );
138
143
domainMap .put ("configOverrides" , "sitconfigcm" );
@@ -168,22 +173,17 @@ private static void destroySitConfigDomain() throws Exception {
168
173
*
169
174
* @throws IOException when copying files from source location to staging area fails
170
175
*/
171
- private static void copySitConfigFiles () throws IOException {
176
+ private static void copySitConfigFiles (String files [], String secretName ) throws IOException {
172
177
String srcDir = TEST_RES_DIR + "/sitconfig/configoverrides" ;
173
178
String dstDir = configOverrideDir ;
174
- String [] files = {
175
- "config.xml" ,
176
- "jdbc-JdbcTestDataSource-0.xml" ,
177
- "diagnostics-WLDF-MODULE-0.xml" ,
178
- "jms-ClusterJmsSystemResource.xml" ,
179
- "version.txt"
180
- };
179
+
180
+ Charset charset = StandardCharsets .UTF_8 ;
181
181
for (String file : files ) {
182
182
Path path = Paths .get (srcDir , file );
183
183
logger .log (Level .INFO , "Copying {0}" , path .toString ());
184
- Charset charset = StandardCharsets .UTF_8 ;
185
184
String content = new String (Files .readAllBytes (path ), charset );
186
185
content = content .replaceAll ("JDBC_URL" , JDBC_URL );
186
+ content = content .replaceAll ("test-secrets" , secretName );
187
187
if (getWeblogicImageTag ().contains (PS3_TAG )) {
188
188
content = content .replaceAll (JDBC_DRIVER_NEW , JDBC_DRIVER_OLD );
189
189
}
@@ -387,7 +387,7 @@ public void testConfigOverrideAfterDomainStartup() throws Exception {
387
387
Paths .get (srcDir , "config_1.xml" ),
388
388
Paths .get (dstDir , "config.xml" ),
389
389
StandardCopyOption .REPLACE_EXISTING );
390
- recreateCrdWithNewConfigMap ( );
390
+ recreateConfigMapandRestart ( "test-secrets" , "test-secrets" );
391
391
transferTests ();
392
392
ExecResult result =
393
393
TestUtils .exec (
@@ -423,7 +423,7 @@ public void testOverrideJdbcResourceAfterDomainStart() throws Exception {
423
423
Paths .get (srcDir , "jdbc-JdbcTestDataSource-1.xml" ),
424
424
Paths .get (dstDir , "jdbc-JdbcTestDataSource-1.xml" ),
425
425
StandardCopyOption .REPLACE_EXISTING );
426
- recreateCrdWithNewConfigMap ( );
426
+ recreateConfigMapandRestart ( "test-secrets" , "test-secrets" );
427
427
transferTests ();
428
428
ExecResult result =
429
429
TestUtils .exec (
@@ -452,45 +452,29 @@ public void testOverrideJdbcResourceWithNewSecret() throws Exception {
452
452
logTestBegin (testMethod );
453
453
// recreate the map with new situational config files
454
454
String [] files = {"config.xml" , "jdbc-JdbcTestDataSource-0.xml" };
455
- String secretName = "test-secrets-new" ;
456
- for (String file : files ) {
457
- Path path = Paths .get (sitconfigTmpDir , "configoverridefiles" , file );
458
- String content = new String (Files .readAllBytes (path ), StandardCharsets .UTF_8 );
459
- content = content .replaceAll ("test-secrets" , secretName );
460
- if (getWeblogicImageTag ().contains (PS3_TAG )) {
461
- content = content .replaceAll (JDBC_DRIVER_NEW , JDBC_DRIVER_OLD );
462
- }
463
- Files .write (
464
- Paths .get (sitconfigTmpDir , "configoverridefiles" , file ),
465
- content .getBytes (StandardCharsets .UTF_8 ),
466
- StandardOpenOption .TRUNCATE_EXISTING );
455
+ String newSecret = "test-secrets-new" ;
456
+ try {
457
+ copySitConfigFiles (files , newSecret );
458
+ recreateConfigMapandRestart ("test-secrets" , newSecret );
459
+ transferTests ();
460
+ ExecResult result =
461
+ TestUtils .exec (
462
+ KUBE_EXEC_CMD
463
+ + " 'sh runSitConfigTests.sh "
464
+ + fqdn
465
+ + " "
466
+ + T3CHANNELPORT
467
+ + " weblogic welcome1 "
468
+ + testMethod
469
+ + " "
470
+ + JDBC_URL
471
+ + "'" );
472
+ assertResult (result );
473
+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethod );
474
+ } finally {
475
+ copySitConfigFiles (files , "test-secrets" );
476
+ recreateConfigMapandRestart ("test-secrets-new" , "test-secrets" );
467
477
}
468
- String content = new String (Files .readAllBytes (Paths .get (domainYaml )), StandardCharsets .UTF_8 );
469
- content = content .replaceAll ("test-secrets" , secretName );
470
- Files .write (
471
- Paths .get (domainYaml ),
472
- content .getBytes (StandardCharsets .UTF_8 ),
473
- StandardOpenOption .TRUNCATE_EXISTING );
474
-
475
- TestUtils .exec ("kubectl delete secret " + domain .getDomainUid () + "-test-secrets" , true );
476
- createNewSecret (secretName );
477
- TestUtils .exec ("kubectl apply -f " + domainYaml , true );
478
- recreateCrdWithNewConfigMap ();
479
- transferTests ();
480
- ExecResult result =
481
- TestUtils .exec (
482
- KUBE_EXEC_CMD
483
- + " 'sh runSitConfigTests.sh "
484
- + fqdn
485
- + " "
486
- + T3CHANNELPORT
487
- + " weblogic welcome1 "
488
- + testMethod
489
- + " "
490
- + JDBC_URL
491
- + "'" );
492
- assertResult (result );
493
- logger .log (Level .INFO , "SUCCESS - {0}" , testMethod );
494
478
}
495
479
496
480
/**
@@ -522,7 +506,32 @@ private void createJdbcResource() throws Exception {
522
506
*
523
507
* @throws Exception when pods restart fail
524
508
*/
525
- private void recreateCrdWithNewConfigMap () throws Exception {
509
+ private void recreateConfigMapandRestart (String oldSecret , String newSecret ) throws Exception {
510
+ if (!oldSecret .equals (newSecret )) {
511
+ String content =
512
+ new String (Files .readAllBytes (Paths .get (domainYaml )), StandardCharsets .UTF_8 );
513
+ content = content .replaceAll (oldSecret , newSecret );
514
+ Files .write (
515
+ Paths .get (domainYaml ),
516
+ content .getBytes (StandardCharsets .UTF_8 ),
517
+ StandardOpenOption .TRUNCATE_EXISTING );
518
+
519
+ TestUtils .exec ("kubectl delete secret " + domain .getDomainUid () + "-" + oldSecret , true );
520
+ String cmd =
521
+ "kubectl -n "
522
+ + domain .getDomainNs ()
523
+ + " create secret generic "
524
+ + domain .getDomainUid ()
525
+ + "-"
526
+ + newSecret
527
+ + " --from-literal=hostname="
528
+ + TestUtils .getHostName ()
529
+ + " --from-literal=dbusername=root"
530
+ + " --from-literal=dbpassword=root123" ;
531
+ TestUtils .exec (cmd , true );
532
+ TestUtils .exec ("kubectl apply -f " + domainYaml , true );
533
+ }
534
+
526
535
int clusterReplicas =
527
536
TestUtils .getClusterReplicas (DOMAINUID , domain .getClusterName (), domain .getDomainNs ());
528
537
@@ -543,21 +552,6 @@ private void recreateCrdWithNewConfigMap() throws Exception {
543
552
domain .verifyDomainCreated ();
544
553
}
545
554
546
- private void createNewSecret (String secretName ) throws Exception {
547
- String cmd =
548
- "kubectl -n "
549
- + domain .getDomainNs ()
550
- + " create secret generic "
551
- + domain .getDomainUid ()
552
- + "-"
553
- + secretName
554
- + " --from-literal=hostname="
555
- + TestUtils .getHostName ()
556
- + " --from-literal=dbusername=root"
557
- + " --from-literal=dbpassword=root123" ;
558
- TestUtils .exec (cmd , true );
559
- }
560
-
561
555
/**
562
556
* Transfer the tests to run in WLS pods.
563
557
*
0 commit comments