1414import java .nio .file .StandardOpenOption ;
1515import java .util .Map ;
1616import java .util .logging .Level ;
17-
1817import oracle .kubernetes .operator .utils .Domain ;
1918import oracle .kubernetes .operator .utils .ExecResult ;
2019import oracle .kubernetes .operator .utils .Operator ;
@@ -82,7 +81,14 @@ public static void staticPrepare() throws Exception {
8281 fqdn = TestUtils .getHostName ();
8382 JDBC_URL = "jdbc:mysql://" + fqdn + ":" + MYSQL_DB_PORT + "/" ;
8483 // 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" );
8692 // create weblogic domain with configOverrides
8793 domain = createSitConfigDomain ();
8894 Assert .assertNotNull (domain );
@@ -132,7 +138,6 @@ public static void staticUnPrepare() throws Exception {
132138 * @throws Exception - if it cannot create the domain
133139 */
134140 private static Domain createSitConfigDomain () throws Exception {
135- String createDomainScript = TEST_RES_DIR + "/domain-home-on-pv/create-domain.py" ;
136141 // load input yaml to map and add configOverrides
137142 Map <String , Object > domainMap = TestUtils .loadYaml (DOMAINONPV_WLST_YAML );
138143 domainMap .put ("configOverrides" , "sitconfigcm" );
@@ -168,22 +173,17 @@ private static void destroySitConfigDomain() throws Exception {
168173 *
169174 * @throws IOException when copying files from source location to staging area fails
170175 */
171- private static void copySitConfigFiles () throws IOException {
176+ private static void copySitConfigFiles (String files [], String secretName ) throws IOException {
172177 String srcDir = TEST_RES_DIR + "/sitconfig/configoverrides" ;
173178 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 ;
181181 for (String file : files ) {
182182 Path path = Paths .get (srcDir , file );
183183 logger .log (Level .INFO , "Copying {0}" , path .toString ());
184- Charset charset = StandardCharsets .UTF_8 ;
185184 String content = new String (Files .readAllBytes (path ), charset );
186185 content = content .replaceAll ("JDBC_URL" , JDBC_URL );
186+ content = content .replaceAll ("test-secrets" , secretName );
187187 if (getWeblogicImageTag ().contains (PS3_TAG )) {
188188 content = content .replaceAll (JDBC_DRIVER_NEW , JDBC_DRIVER_OLD );
189189 }
@@ -387,7 +387,7 @@ public void testConfigOverrideAfterDomainStartup() throws Exception {
387387 Paths .get (srcDir , "config_1.xml" ),
388388 Paths .get (dstDir , "config.xml" ),
389389 StandardCopyOption .REPLACE_EXISTING );
390- recreateCrdWithNewConfigMap ( );
390+ recreateConfigMapandRestart ( "test-secrets" , "test-secrets" );
391391 transferTests ();
392392 ExecResult result =
393393 TestUtils .exec (
@@ -423,7 +423,7 @@ public void testOverrideJdbcResourceAfterDomainStart() throws Exception {
423423 Paths .get (srcDir , "jdbc-JdbcTestDataSource-1.xml" ),
424424 Paths .get (dstDir , "jdbc-JdbcTestDataSource-1.xml" ),
425425 StandardCopyOption .REPLACE_EXISTING );
426- recreateCrdWithNewConfigMap ( );
426+ recreateConfigMapandRestart ( "test-secrets" , "test-secrets" );
427427 transferTests ();
428428 ExecResult result =
429429 TestUtils .exec (
@@ -452,45 +452,29 @@ public void testOverrideJdbcResourceWithNewSecret() throws Exception {
452452 logTestBegin (testMethod );
453453 // recreate the map with new situational config files
454454 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" );
467477 }
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 );
494478 }
495479
496480 /**
@@ -522,7 +506,32 @@ private void createJdbcResource() throws Exception {
522506 *
523507 * @throws Exception when pods restart fail
524508 */
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+
526535 int clusterReplicas =
527536 TestUtils .getClusterReplicas (DOMAINUID , domain .getClusterName (), domain .getDomainNs ());
528537
@@ -543,21 +552,6 @@ private void recreateCrdWithNewConfigMap() throws Exception {
543552 domain .verifyDomainCreated ();
544553 }
545554
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-
561555 /**
562556 * Transfer the tests to run in WLS pods.
563557 *
0 commit comments