Skip to content

Commit 2e02f7b

Browse files
committed
Fixing the secrets change
1 parent 6c3e03c commit 2e02f7b

File tree

1 file changed

+59
-68
lines changed

1 file changed

+59
-68
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ItSitConfig.java

Lines changed: 59 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.nio.file.StandardOpenOption;
1515
import java.util.Map;
1616
import java.util.logging.Level;
17-
1817
import oracle.kubernetes.operator.utils.Domain;
1918
import oracle.kubernetes.operator.utils.ExecResult;
2019
import 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");
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");
427427
transferTests();
428428
ExecResult result =
429429
TestUtils.exec(
@@ -453,44 +453,28 @@ public void testOverrideJdbcResourceWithNewSecret() throws Exception {
453453
// recreate the map with new situational config files
454454
String[] files = {"config.xml", "jdbc-JdbcTestDataSource-0.xml"};
455455
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);
456+
try {
457+
copySitConfigFiles(files, secretName);
458+
recreateConfigMapandRestart(secretName);
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(secretName);
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,15 +506,37 @@ 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 secretName) throws Exception {
510+
String content = new String(Files.readAllBytes(Paths.get(domainYaml)), StandardCharsets.UTF_8);
511+
content = content.replaceAll("test-secrets", secretName);
512+
Files.write(
513+
Paths.get(domainYaml),
514+
content.getBytes(StandardCharsets.UTF_8),
515+
StandardOpenOption.TRUNCATE_EXISTING);
516+
517+
TestUtils.exec("kubectl delete secret " + domain.getDomainUid() + "-test-secrets", true);
518+
String cmd =
519+
"kubectl -n "
520+
+ domain.getDomainNs()
521+
+ " create secret generic "
522+
+ domain.getDomainUid()
523+
+ "-"
524+
+ secretName
525+
+ " --from-literal=hostname="
526+
+ TestUtils.getHostName()
527+
+ " --from-literal=dbusername=root"
528+
+ " --from-literal=dbpassword=root123";
529+
TestUtils.exec(cmd, true);
530+
TestUtils.exec("kubectl apply -f " + domainYaml, true);
531+
526532
int clusterReplicas =
527533
TestUtils.getClusterReplicas(DOMAINUID, domain.getClusterName(), domain.getDomainNs());
528534

529535
String patchStr = "'{\"spec\":{\"serverStartPolicy\":\"NEVER\"}}'";
530536
TestUtils.kubectlpatch(DOMAINUID, domain.getDomainNs(), patchStr);
531537
domain.verifyServerPodsDeleted(clusterReplicas);
532538

533-
String cmd =
539+
cmd =
534540
"kubectl create configmap "
535541
+ DOMAINUID
536542
+ "-sitconfigcm --from-file="
@@ -543,21 +549,6 @@ private void recreateCrdWithNewConfigMap() throws Exception {
543549
domain.verifyDomainCreated();
544550
}
545551

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-
561552
/**
562553
* Transfer the tests to run in WLS pods.
563554
*

0 commit comments

Comments
 (0)