Skip to content

Commit 2dbcfc9

Browse files
authored
Merge pull request #623 from oracle/feature/java-integration-tests
Automatic situational config overrides test
2 parents 8a029d0 + a8cfeca commit 2dbcfc9

File tree

10 files changed

+359
-63
lines changed

10 files changed

+359
-63
lines changed

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

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
package oracle.kubernetes.operator;
66

7+
import java.io.File;
8+
import java.nio.file.Files;
9+
import java.nio.file.StandardCopyOption;
710
import oracle.kubernetes.operator.utils.Domain;
811
import oracle.kubernetes.operator.utils.ExecCommand;
912
import oracle.kubernetes.operator.utils.ExecResult;
@@ -46,6 +49,7 @@ public class ITOperator extends BaseTest {
4649
private static String domain9YamlFile = "domain9.yaml";
4750
private static String domain10YamlFile = "domain10.yaml";
4851
private static String domain11YamlFile = "domain11.yaml";
52+
private static String domain12YamlFile = "domain12.yaml";
4953

5054
// property file used to configure constants for integration tests
5155
private static String appPropsFile = "OperatorIT.properties";
@@ -250,7 +254,7 @@ public void test5CreateConfiguredDomainInTest2NS() throws Exception {
250254
logger.info("Verify no impact on domain5");
251255
domain5.verifyDomainCreated();
252256
testCompletedSuccessfully = true;
253-
logger.info("SUCCESS - test5CreateConfiguredDomainInTest2NS");
257+
254258
} finally {
255259
if (domain4 != null && (JENKINS || testCompletedSuccessfully)) {
256260
domain4.destroy();
@@ -259,6 +263,7 @@ public void test5CreateConfiguredDomainInTest2NS() throws Exception {
259263
domain5.destroy();
260264
}
261265
}
266+
logger.info("SUCCESS - test5CreateConfiguredDomainInTest2NS");
262267
}
263268

264269
@Test
@@ -458,7 +463,7 @@ public void testDeleteTwoDomains() throws Exception {
458463
logger.info("SUCCESS - testDeleteTwoDomains");
459464
}
460465

461-
// @Test
466+
@Test
462467
public void testAutoSitConfigOverrides() throws Exception {
463468
Assume.assumeFalse(QUICKTEST);
464469
logTestBegin("testAutoSitConfigOverrides");
@@ -468,32 +473,78 @@ public void testAutoSitConfigOverrides() throws Exception {
468473
}
469474
Domain domain11 = null;
470475
boolean testCompletedSuccessfully = false;
476+
String createDomainScriptDir =
477+
BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/domain-home-on-pv";
471478
try {
479+
472480
// cp py
473-
copyCreateDomainScript();
481+
Files.copy(
482+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
483+
new File(createDomainScriptDir + "/create-domain.py.bak").toPath(),
484+
StandardCopyOption.REPLACE_EXISTING);
485+
Files.copy(
486+
new File(createDomainScriptDir + "/create-domain-auto-sit-config.py").toPath(),
487+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
488+
StandardCopyOption.REPLACE_EXISTING);
489+
474490
domain11 = testDomainCreation(domain11YamlFile);
475491
domain11.verifyDomainCreated();
476492
testBasicUseCases(domain11);
493+
// testAdvancedUseCasesForADomain(operator1, domain11);
477494
testCompletedSuccessfully = true;
478495
logger.info("SUCCESS - testAutoSitConfigOverrides");
479496
} finally {
480-
481-
StringBuffer cmd = new StringBuffer("cd ");
482-
cmd.append(BaseTest.getProjectRoot())
483-
.append(
484-
"/integration-tests/src/test/resources/domain-home-on-pv && cp create-domain.py.bak create-domain.py");
485-
logger.info("Running " + cmd);
486-
ExecResult result = ExecCommand.exec(cmd.toString());
487-
if (result.exitValue() != 0) {
488-
throw new RuntimeException(cmd + " failed");
489-
}
490-
497+
Files.copy(
498+
new File(createDomainScriptDir + "/create-domain.py.bak").toPath(),
499+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
500+
StandardCopyOption.REPLACE_EXISTING);
491501
if (domain11 != null && (JENKINS || testCompletedSuccessfully)) {
492502
domain11.destroy();
493503
}
494504
}
495505
}
496506

507+
// @Test
508+
public void testCustomSitConfigOverrides() throws Exception {
509+
Assume.assumeFalse(QUICKTEST);
510+
logTestBegin("testCustomSitConfigOverrides");
511+
512+
if (operator1 == null) {
513+
operator1 = TestUtils.createOperator(op1YamlFile);
514+
}
515+
Domain domain12 = null;
516+
boolean testCompletedSuccessfully = false;
517+
String createDomainScriptDir =
518+
BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/domain-home-on-pv";
519+
try {
520+
521+
// cp py
522+
Files.copy(
523+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
524+
new File(createDomainScriptDir + "/create-domain.py.bak").toPath(),
525+
StandardCopyOption.REPLACE_EXISTING);
526+
Files.copy(
527+
new File(createDomainScriptDir + "/create-domain-custom-sit-config.py").toPath(),
528+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
529+
StandardCopyOption.REPLACE_EXISTING);
530+
531+
domain12 = testDomainCreation(domain12YamlFile);
532+
domain12.verifyDomainCreated();
533+
testBasicUseCases(domain12);
534+
// testAdvancedUseCasesForADomain(operator1, domain11);
535+
testCompletedSuccessfully = true;
536+
logger.info("SUCCESS - testCustomSitConfigOverrides");
537+
} finally {
538+
Files.copy(
539+
new File(createDomainScriptDir + "/create-domain.py.bak").toPath(),
540+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
541+
StandardCopyOption.REPLACE_EXISTING);
542+
if (domain12 != null && (JENKINS || testCompletedSuccessfully)) {
543+
domain12.destroy();
544+
}
545+
}
546+
}
547+
497548
private Domain testAdvancedUseCasesForADomain(Operator operator, Domain domain) throws Exception {
498549
if (!SMOKETEST) {
499550
testClusterScaling(operator, domain);
@@ -511,27 +562,4 @@ private void testBasicUseCases(Domain domain) throws Exception {
511562
testAdminT3Channel(domain);
512563
testAdminServerExternalService(domain);
513564
}
514-
515-
private void copyCreateDomainScript() throws Exception {
516-
String createDomainScriptPath =
517-
BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/domain-home-on-pv";
518-
519-
StringBuffer cmd = new StringBuffer("cd ");
520-
cmd.append(createDomainScriptPath).append(" && cp create-domain.py create-domain.py.bak");
521-
logger.info("Running " + cmd);
522-
523-
ExecResult result = ExecCommand.exec(cmd.toString());
524-
if (result.exitValue() != 0) {
525-
throw new RuntimeException(cmd + " failed");
526-
}
527-
528-
cmd = new StringBuffer("cd ");
529-
cmd.append(createDomainScriptPath)
530-
.append(" && cp create-domain-auto-sit-config.py create-domain.py");
531-
logger.info("Running " + cmd);
532-
result = ExecCommand.exec(cmd.toString());
533-
if (result.exitValue() != 0) {
534-
throw new RuntimeException(cmd + " failed");
535-
}
536-
}
537565
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.file.Files;
1111
import java.nio.file.Path;
1212
import java.nio.file.Paths;
13+
import java.nio.file.StandardOpenOption;
1314
import java.util.HashMap;
1415
import java.util.Map;
1516
import java.util.Objects;
@@ -668,11 +669,14 @@ private void generateInputYaml() throws Exception {
668669

669670
private void callCreateDomainScript(String outputDir) throws Exception {
670671
StringBuffer cmd = new StringBuffer(BaseTest.getProjectRoot());
672+
671673
cmd.append(
672674
"/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh -i ")
673-
.append(generatedInputYamlFile)
674-
.append(" -e -v -o ")
675-
.append(outputDir);
675+
.append(generatedInputYamlFile);
676+
if (!domainMap.containsKey("configOverrides")) {
677+
cmd.append(" -e ");
678+
}
679+
cmd.append(" -v -o ").append(outputDir);
676680
logger.info("Running " + cmd);
677681
ExecResult result = ExecCommand.exec(cmd.toString(), true);
678682
if (result.exitValue() != 0) {
@@ -686,6 +690,37 @@ private void callCreateDomainScript(String outputDir) throws Exception {
686690
}
687691
String outputStr = result.stdout().trim();
688692
logger.info("Command returned " + outputStr);
693+
694+
// write configOverride and configOverrideSecrets to domain.yaml
695+
if (domainMap.containsKey("configOverrides")) {
696+
String contentToAppend =
697+
" configOverrides: "
698+
+ domainUid
699+
+ "-"
700+
+ domainMap.get("configOverrides")
701+
+ "\n"
702+
+ " configOverrideSecrets: [ \""
703+
+ domainUid
704+
+ "-t3publicaddress\" ]"
705+
+ "\n";
706+
707+
String domainYaml =
708+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
709+
Files.write(Paths.get(domainYaml), contentToAppend.getBytes(), StandardOpenOption.APPEND);
710+
711+
String command = "kubectl create -f " + domainYaml;
712+
result = ExecCommand.exec(command);
713+
if (result.exitValue() != 0) {
714+
throw new RuntimeException(
715+
"FAILURE: command "
716+
+ cmd
717+
+ " failed, returned "
718+
+ result.stdout()
719+
+ "\n"
720+
+ result.stderr());
721+
}
722+
logger.info("Command returned " + result.stdout().trim());
723+
}
689724
}
690725

691726
private void createLoadBalancer() throws Exception {
@@ -790,7 +825,12 @@ private void callWebAppAndCheckForServerNameInResponse(
790825
ExecResult result = ExecCommand.exec(curlCmd.toString());
791826
if (result.exitValue() != 0) {
792827
throw new RuntimeException(
793-
"FAILURE: command " + curlCmd + " failed, returned " + result.stderr());
828+
"FAILURE: command "
829+
+ curlCmd
830+
+ " failed, returned "
831+
+ result.stderr()
832+
+ " \n "
833+
+ result.stdout());
794834
} else {
795835
logger.info("webapp invoked successfully");
796836
}
@@ -863,9 +903,9 @@ private void initialize(String inputYaml) throws Exception {
863903
}
864904

865905
domainMap.put("domainHome", "/shared/domains/" + domainUid);
866-
/* domainMap.put(
867-
"createDomainFilesDir",
868-
BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/domain-home-on-pv"); */
906+
domainMap.put(
907+
"createDomainFilesDir",
908+
BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/domain-home-on-pv");
869909
String imageName = "store/oracle/weblogic";
870910
if (System.getenv("IMAGE_NAME_WEBLOGIC") != null) {
871911
imageName = System.getenv("IMAGE_NAME_WEBLOGIC");
@@ -889,6 +929,56 @@ private void initialize(String inputYaml) throws Exception {
889929
}
890930
// remove null values if any attributes
891931
domainMap.values().removeIf(Objects::isNull);
932+
933+
// create config map and secret for custom sit config
934+
if (domainMap.get("configOverrides") != null) {
935+
// write hostname in config file for public address
936+
937+
String cmd =
938+
"kubectl -n "
939+
+ domainNS
940+
+ " create cm "
941+
+ domainUid
942+
+ "-"
943+
+ domainMap.get("configOverrides")
944+
+ " --from-file "
945+
+ BaseTest.getProjectRoot()
946+
+ "/integration-tests/src/test/resources/domain-home-on-pv/customsitconfig";
947+
ExecResult result = ExecCommand.exec(cmd);
948+
if (result.exitValue() != 0) {
949+
throw new RuntimeException(
950+
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
951+
}
952+
cmd =
953+
"kubectl -n "
954+
+ domainNS
955+
+ " label cm "
956+
+ domainUid
957+
+ "-"
958+
+ domainMap.get("configOverrides")
959+
+ " weblogic.domainUID="
960+
+ domainUid;
961+
result = ExecCommand.exec(cmd);
962+
if (result.exitValue() != 0) {
963+
throw new RuntimeException(
964+
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
965+
}
966+
// create secret for custom sit config t3 public address
967+
cmd =
968+
"kubectl -n "
969+
+ domainNS
970+
+ " create secret generic "
971+
+ domainUid
972+
+ "-"
973+
+ "t3publicaddress "
974+
+ " --from-literal=hostname="
975+
+ TestUtils.getHostName();
976+
result = ExecCommand.exec(cmd);
977+
if (result.exitValue() != 0) {
978+
throw new RuntimeException(
979+
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
980+
}
981+
}
892982
}
893983

894984
private String getNodeHost() throws Exception {

integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ public static void deletePVC(String pvcName, String namespace) throws Exception
177177
StringBuffer cmd = new StringBuffer("kubectl delete pvc ");
178178
cmd.append(pvcName).append(" -n ").append(namespace);
179179
logger.info("Deleting PVC " + cmd);
180-
ExecCommand.exec(cmd.toString());
180+
ExecResult result = ExecCommand.exec(cmd.toString());
181+
if (result.exitValue() != 0) {
182+
throw new RuntimeException(
183+
"FAILURE: delete PVC failed with " + result.stderr() + " \n " + result.stdout());
184+
}
181185
}
182186

183187
public static boolean checkPVReleased(String pvBaseName, String namespace) throws Exception {
@@ -186,7 +190,7 @@ public static boolean checkPVReleased(String pvBaseName, String namespace) throw
186190

187191
int i = 0;
188192
while (i < BaseTest.getMaxIterationsPod()) {
189-
logger.info("Checking if PV is Released " + cmd);
193+
logger.info("Iteration " + i + " Checking if PV is Released " + cmd);
190194
ExecResult result = ExecCommand.exec(cmd.toString());
191195
if (result.exitValue() != 0
192196
|| result.exitValue() == 0 && !result.stdout().contains("Released")) {
@@ -344,7 +348,7 @@ private static int makeOperatorRestCall(
344348

345349
Response response = null;
346350
int i = 0;
347-
while (i < BaseTest.getMaxIterationsPod() / 2) {
351+
while (i < BaseTest.getMaxIterationsPod()) {
348352
try {
349353
// Post scaling request to Operator
350354
if (jsonObjStr != null) {
@@ -353,9 +357,12 @@ private static int makeOperatorRestCall(
353357
response = request.get();
354358
}
355359
} catch (Exception ex) {
356-
logger.info("Got exception " + ex.getMessage());
360+
logger.info("Got exception, iteration " + i + " " + ex.getMessage());
357361
i++;
358362
if (ex.getMessage().contains("java.net.ConnectException: Connection refused")) {
363+
if (i == (BaseTest.getMaxIterationsPod() - 1)) {
364+
throw ex;
365+
}
359366
logger.info("Sleeping 5 more seconds and try again");
360367
Thread.sleep(5 * 1000);
361368
continue;

integration-tests/src/test/resources/domain-home-on-pv/create-domain-auto-sit-config.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,25 @@ def getEnvVar(var):
4949
# ===================================
5050
cd('/Servers/AdminServer')
5151
# Give incorrect listenaddress, introspector overrides with sit-config
52-
set('ListenAddress', 'junk')
52+
#set('ListenAddress', '')
5353
set('ListenPort', admin_port)
5454
set('Name', admin_server_name)
55-
create('AdminServer','Log')
56-
cd('/Servers/AdminServer/Log/AdminServer')
57-
# Give incorrect filelog, introspector overrides with sit-config
58-
set('FileName', 'dirdoesnotexist')
5955

6056
create('T3Channel', 'NetworkAccessPoint')
6157
cd('/Servers/%s/NetworkAccessPoints/T3Channel' % admin_server_name)
6258
set('PublicPort', t3_channel_port)
6359
set('PublicAddress', t3_public_address)
6460
# Give incorrect listenaddress, introspector overrides with sit-config
65-
set('ListenAddress', 'junk')
61+
#set('ListenAddress', '')
6662
set('ListenPort', t3_channel_port)
6763

64+
cd('/Servers/%s' % admin_server_name)
65+
create(admin_server_name,'Log')
66+
cd('/Servers/%s/Log/%s' % (admin_server_name, admin_server_name))
67+
# Give incorrect filelog, introspector overrides with sit-config
68+
set('FileName', 'dirdoesnotexist')
69+
70+
6871

6972
# Set the admin user's username and password
7073
# ==========================================

0 commit comments

Comments
 (0)