Skip to content

Commit c2ea484

Browse files
maggiehe00rjeberhard
authored andcommitted
Jrf on PV P2 testcase: empty opss wallet file secret and opss.walletFileSecret does not have an entry with --from-file=walletFile
1 parent fe14998 commit c2ea484

File tree

3 files changed

+154
-28
lines changed

3 files changed

+154
-28
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItFmwDomainInPvUserCreateRcu.java

Lines changed: 107 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
2222
import oracle.weblogic.kubernetes.annotations.Namespaces;
2323
import oracle.weblogic.kubernetes.logging.LoggingFacade;
24+
import oracle.weblogic.kubernetes.utils.ExecResult;
2425
import org.junit.jupiter.api.BeforeAll;
2526
import org.junit.jupiter.api.DisplayName;
2627
import org.junit.jupiter.api.MethodOrderer;
@@ -56,6 +57,7 @@
5657
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify;
5758
import static oracle.weblogic.kubernetes.utils.DomainUtils.deleteDomainResource;
5859
import static oracle.weblogic.kubernetes.utils.FmwUtils.createDomainResourceSimplifyJrfPv;
60+
import static oracle.weblogic.kubernetes.utils.FmwUtils.restoreOpssWalletfileSecret;
5961
import static oracle.weblogic.kubernetes.utils.FmwUtils.saveAndRestoreOpssWalletfileSecret;
6062
import static oracle.weblogic.kubernetes.utils.FmwUtils.verifyDomainReady;
6163
import static oracle.weblogic.kubernetes.utils.ImageUtils.createBaseRepoSecret;
@@ -65,12 +67,15 @@
6567
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodDoesNotExist;
6668
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodLogContains;
6769
import static oracle.weblogic.kubernetes.utils.PodUtils.getExternalServicePodName;
70+
import static oracle.weblogic.kubernetes.utils.SecretUtils.createOpsswalletFileSecretWithoutFile;
6871
import static oracle.weblogic.kubernetes.utils.SecretUtils.createOpsswalletpasswordSecret;
6972
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
7073
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
74+
import static org.apache.commons.io.FileUtils.delete;
7175
import static org.apache.commons.io.FileUtils.deleteDirectory;
7276
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
7377
import static org.junit.jupiter.api.Assertions.assertNotNull;
78+
import static org.junit.jupiter.api.Assertions.assertTrue;
7479

7580
/**
7681
* Test to create a FMW domain on PV with DomainOnPvSimplification feature when user pre-creates RCU.
@@ -94,16 +99,23 @@ public class ItFmwDomainInPvUserCreateRcu {
9499
private static LoggingFacade logger = null;
95100
private static String DOMAINHOMEPREFIX = null;
96101
private static final String domainUid1 = "jrfdomainonpv-userrcu1";
102+
private static final String domainUid4 = "jrfdomainonpv-userrcu4";
97103
private static final String miiAuxiliaryImage1Tag = "jrf1" + MII_BASIC_IMAGE_TAG;
98104
private final String adminSecretName1 = domainUid1 + "-weblogic-credentials";
99105
private final String rcuaccessSecretName1 = domainUid1 + "-rcu-credentials";
100106
private final String opsswalletpassSecretName1 = domainUid1 + "-opss-wallet-password-secret";
101107
private final String opsswalletfileSecretName1 = domainUid1 + "-opss-wallet-file-secret";
108+
private final String adminSecretName4 = domainUid4 + "-weblogic-credentials";
109+
private final String rcuaccessSecretName4 = domainUid4 + "-rcu-credentials";
110+
private final String opsswalletpassSecretName4 = domainUid4 + "-opss-wallet-password-secret";
111+
private final String opsswalletfileSecretName4 = domainUid4 + "-opss-wallet-file-secret";
102112
private static final int replicaCount = 1;
103113

104114
private final String fmwModelFilePrefix = "model-fmwdomainonpv-rcu-wdt";
105115
private final String fmwModelFile = fmwModelFilePrefix + ".yaml";
106116
private static DomainCreationImage domainCreationImage1 = null;
117+
private static List<DomainCreationImage> domainCreationImages4 = new ArrayList<>();
118+
private static String configMapName = null;
107119

108120
/**
109121
* Assigns unique namespaces for DB, operator and domain.
@@ -273,6 +285,13 @@ void testFmwDomainOnPvUserProvideOpss() {
273285
assertDoesNotThrow(() -> deletePod("rcu", dbNamespace),
274286
"Got exception while deleting server " + "rcu");
275287
checkPodDoesNotExist("rcu", null, dbNamespace);
288+
//delete the wallet file ewallet.p12
289+
try {
290+
delete(new File("./ewallet.p12"));
291+
logger.info("Wallet file ewallet.p12 is deleted");
292+
} catch (IOException ioe) {
293+
logger.severe("Failed to delete file ewallet.p12", ioe);
294+
}
276295

277296
}
278297

@@ -476,7 +495,6 @@ void testFmwDomainOnPvUserCreatesRCUMultiImages() {
476495

477496
}
478497

479-
480498
/**
481499
* User creates RCU, Operate creates PV/PVC and FMW domain with additional WDT config map.
482500
* Verify Pod is ready and service exists for both admin server and managed servers.
@@ -485,19 +503,16 @@ void testFmwDomainOnPvUserCreatesRCUMultiImages() {
485503
@Order(5)
486504
@DisplayName("Create a FMW domain on PV with additional WDT config map when user per-creates RCU")
487505
void testFmwDomainOnPvUserCreatesRCUwdtConfigMap() {
488-
String domainUid = "jrfdomainonpv-userrcu4";
489-
String adminSecretName = domainUid + "-weblogic-credentials";
490-
String rcuaccessSecretName = domainUid + "-rcu-credentials";
491-
String opsswalletpassSecretName = domainUid + "-opss-wallet-password-secret";
492-
final String pvName = getUniqueName(domainUid + "-pv-");
493-
final String pvcName = getUniqueName(domainUid + "-pvc-");
506+
507+
final String pvName = getUniqueName(domainUid4 + "-pv-");
508+
final String pvcName = getUniqueName(domainUid4 + "-pvc-");
494509

495510
//create RCU schema
496511
assertDoesNotThrow(() -> createRcuSchema(FMWINFRA_IMAGE_TO_USE_IN_SPEC, RCUSCHEMAPREFIX + "4",
497512
dbUrl, dbNamespace), "create RCU schema failed");
498513

499514
// create a model property file
500-
File fmwModelPropFile = createWdtPropertyFile(domainUid, RCUSCHEMAPREFIX + "4");
515+
File fmwModelPropFile = createWdtPropertyFile(domainUid4, RCUSCHEMAPREFIX + "4");
501516

502517
// Create the repo secret to pull the image
503518
// this secret is used only for non-kind cluster
@@ -506,64 +521,129 @@ void testFmwDomainOnPvUserCreatesRCUwdtConfigMap() {
506521
// create secret for admin credentials
507522
logger.info("Create secret for admin credentials");
508523
assertDoesNotThrow(() -> createSecretWithUsernamePassword(
509-
adminSecretName,
524+
adminSecretName4,
510525
domainNamespace,
511526
ADMIN_USERNAME_DEFAULT,
512527
ADMIN_PASSWORD_DEFAULT),
513-
String.format("createSecret failed for %s", adminSecretName));
528+
String.format("createSecret failed for %s", adminSecretName4));
514529

515530
// create RCU access secret
516531
logger.info("Creating RCU access secret: {0}, with prefix: {1}, dbUrl: {2}, schemapassword: {3})",
517-
rcuaccessSecretName, RCUSCHEMAPREFIX + "4", RCUSCHEMAPASSWORD, dbUrl);
532+
rcuaccessSecretName4, RCUSCHEMAPREFIX + "4", RCUSCHEMAPASSWORD, dbUrl);
518533
assertDoesNotThrow(() -> createRcuAccessSecret(
519-
rcuaccessSecretName,
534+
rcuaccessSecretName4,
520535
domainNamespace,
521536
RCUSCHEMAPREFIX + "4",
522537
RCUSCHEMAPASSWORD,
523538
dbUrl),
524-
String.format("createSecret failed for %s", rcuaccessSecretName));
539+
String.format("createSecret failed for %s", rcuaccessSecretName4));
525540

526541
logger.info("Create OPSS wallet password secret");
527542
assertDoesNotThrow(() -> createOpsswalletpasswordSecret(
528-
opsswalletpassSecretName,
543+
opsswalletpassSecretName4,
529544
domainNamespace,
530545
ADMIN_PASSWORD_DEFAULT),
531-
String.format("createSecret failed for %s", opsswalletpassSecretName));
546+
String.format("createSecret failed for %s", opsswalletpassSecretName4));
532547

533-
DomainCreationImage domainCreationImage1 = createImage(fmwModelFile,fmwModelPropFile,"jrf4");
534-
List<DomainCreationImage> domainCreationImages = new ArrayList<>();
535-
domainCreationImages.add(domainCreationImage1);
548+
DomainCreationImage domainCreationImage = createImage(fmwModelFile,fmwModelPropFile,"jrf4");
549+
domainCreationImages4.add(domainCreationImage);
536550

537551
logger.info("create WDT configMap with jms model");
538-
String configMapName = "jmsconfigmap";
552+
configMapName = "jmsconfigmap";
539553
createConfigMapAndVerify(
540-
configMapName, domainUid, domainNamespace,
554+
configMapName, domainUid4, domainNamespace,
541555
Arrays.asList(MODEL_DIR + "/model.jms2.yaml"));
542556

543557
// create a domain custom resource configuration object
544558
logger.info("Creating domain custom resource with pvName: {0}", pvName);
545559
DomainResource domain = createDomainResourceSimplifyJrfPv(
546-
domainUid, domainNamespace, adminSecretName,
560+
domainUid4, domainNamespace, adminSecretName4,
547561
TEST_IMAGES_REPO_SECRET_NAME,
548-
rcuaccessSecretName,
549-
opsswalletpassSecretName, null,
550-
pvName, pvcName, domainCreationImages, configMapName);
562+
rcuaccessSecretName4,
563+
opsswalletpassSecretName4, null,
564+
pvName, pvcName, domainCreationImages4, configMapName);
551565

552566
createDomainAndVerify(domain, domainNamespace);
553567

554568
// verify that all servers are ready
555-
verifyDomainReady(domainNamespace, domainUid, replicaCount, "nosuffix");
569+
verifyDomainReady(domainNamespace, domainUid4, replicaCount, "nosuffix");
556570

557571
//create router for admin service on OKD
558-
String adminServerPodName = domainUid + "-admin-server";
572+
String adminServerPodName = domainUid4 + "-admin-server";
559573
String adminSvcExtHost = createRouteForOKD(getExternalServicePodName(adminServerPodName), domainNamespace);
560574
logger.info("admin svc host = {0}", adminSvcExtHost);
561575

562576
// check configuration for JMS
563577
checkConfiguredJMSresouce(domainNamespace, adminServerPodName, adminSvcExtHost);
564578

579+
}
580+
581+
/**
582+
* The user provides opss.walletFileSecret that is empty.
583+
* If "ewallet.p12" is an empty file, running opss-wallet.sh to restore the wallet file
584+
* secret will fail and return "Error: Wallet file 'ewallet.p12' is empty"
585+
* Create opss.walletFileSecret without entry with --from-file=walletFile to get an empty walletFileSecret
586+
* The operator will not mount the secret but proceed with normal domain creation without error
587+
*/
588+
@Test
589+
@Order(6)
590+
@DisplayName("Create a FMW domain on PV when user provide OPSS wallet file is empty")
591+
void testFmwDomainOnPvUserProvideEmptyOpss() {
592+
593+
final String pvName = getUniqueName(domainUid4 + "-pv-");
594+
final String pvcName = getUniqueName(domainUid4 + "-pvc-");
595+
596+
//create empty wallet file ewallet.p12
597+
try {
598+
File file = new File("ewallet.p12");
599+
if (file.createNewFile()) {
600+
logger.info("Empty wallet file ewallet.p12 is created: " + file.getAbsolutePath());
601+
} else {
602+
logger.info("Failed to create file ewallet.p12 ");
603+
}
604+
} catch (IOException ioe) {
605+
logger.severe("Failed to create file ewallet.p12", ioe);
606+
}
607+
608+
ExecResult result = restoreOpssWalletfileSecret(domainNamespace, domainUid4, opsswalletfileSecretName4);
609+
logger.info("restoreOpssWalletfileSecret returns msg: " + result.stdout());
610+
assertTrue(result.stdout().contains("Error: Wallet file 'ewallet.p12' is empty"));
611+
612+
//delete the empty wallet file ewallet.p12
613+
try {
614+
delete(new File("./ewallet.p12"));
615+
logger.info("Wallet file ewallet.p12 is deleted");
616+
} catch (IOException ioe) {
617+
logger.severe("Failed to delete file ewallet.p12", ioe);
618+
}
619+
620+
//create empty walletFileSecret
621+
createOpsswalletFileSecretWithoutFile(opsswalletfileSecretName4, domainNamespace);
622+
logger.info("Empty walletFile secret {0} is created in the namespace {1}",
623+
opsswalletfileSecretName4, domainNamespace);
624+
625+
logger.info("Deleting domain custom resource with namespace: {0}, domainUid {1}", domainNamespace, domainUid4);
626+
deleteDomainResource(domainNamespace, domainUid4);
627+
try {
628+
deleteDirectory(Paths.get("/share").toFile());
629+
} catch (IOException ioe) {
630+
logger.severe("Failed to cleanup directory /share", ioe);
631+
}
632+
logger.info("Creating domain custom resource with pvName: {0}", pvName);
633+
DomainResource domain = createDomainResourceSimplifyJrfPv(
634+
domainUid4, domainNamespace, adminSecretName4,
635+
TEST_IMAGES_REPO_SECRET_NAME,
636+
rcuaccessSecretName4,
637+
opsswalletpassSecretName4, opsswalletfileSecretName4,
638+
pvName, pvcName, domainCreationImages4, configMapName);
639+
640+
createDomainAndVerify(domain, domainNamespace);
641+
642+
// verify that all servers are ready
643+
verifyDomainReady(domainNamespace, domainUid4, replicaCount, "nosuffix");
644+
565645
// delete the domain
566-
deleteDomainResource(domainNamespace, domainUid);
646+
deleteDomainResource(domainNamespace, domainUid4);
567647
//delete the rcu pod
568648
assertDoesNotThrow(() -> deletePod("rcu", dbNamespace),
569649
"Got exception while deleting server " + "rcu");

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FmwUtils.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public static DomainResource createDomainResourceSimplifyJrfPv(
456456
}
457457

458458
/**
459-
* Save the OPSS key wallet from a running JRF domain's introspector configmap to a file.
459+
* Save and restore the OPSS key wallet from a running JRF domain's introspector configmap to a file.
460460
* @param namespace namespace where JRF domain exists
461461
* @param domainUid unique domain Uid
462462
* @param walletfileSecretName name of wallet file secret
@@ -492,4 +492,34 @@ public static void saveAndRestoreOpssWalletfileSecret(String namespace, String d
492492

493493
}
494494

495+
/**
496+
* Restore the OPSS key wallet from a running JRF domain's introspector configmap to a file.
497+
* @param namespace namespace where JRF domain exists
498+
* @param domainUid unique domain Uid
499+
* @param walletfileSecretName name of wallet file secret
500+
* @return ExecResult result of running corresponding script
501+
*/
502+
public static ExecResult restoreOpssWalletfileSecret(String namespace, String domainUid,
503+
String walletfileSecretName) {
504+
505+
logger = getLogger();
506+
Path saveAndRestoreOpssPath =
507+
Paths.get(RESOURCE_DIR, "bash-scripts", "opss-wallet.sh");
508+
String script = saveAndRestoreOpssPath.toString();
509+
logger.info("Script for saveAndRestoreOpss is {0)", script);
510+
511+
//restore opss wallet password secret
512+
String command = script + " -d " + domainUid + " -n " + namespace + " -r" + " -ws " + walletfileSecretName;
513+
logger.info("Restore wallet file command: {0}", command);
514+
ExecResult result = Command.withParams(
515+
defaultCommandParams()
516+
.command(command)
517+
.saveResults(true)
518+
.redirect(true))
519+
.executeAndReturnResult();
520+
521+
return result;
522+
523+
}
524+
495525
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/SecretUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ public static void createOpsswalletpasswordSecret(String secretName, String name
125125
assertTrue(secretCreated, String.format("create secret failed for %s", secretName));
126126
}
127127

128+
/**
129+
* Create a OPSS wallet file secret without file in the specified namespace.
130+
* This is for a negative test scenario
131+
* @param secretName secret name to create
132+
* @param namespace namespace in which the secret will be created
133+
*/
134+
public static void createOpsswalletFileSecretWithoutFile(String secretName, String namespace) {
135+
136+
boolean secretCreated = assertDoesNotThrow(() -> createSecret(new V1Secret()
137+
.metadata(new V1ObjectMeta()
138+
.name(secretName)
139+
.namespace(namespace))),
140+
"Create secret failed with ApiException");
141+
assertTrue(secretCreated, String.format("create secret failed for %s", secretName));
142+
}
143+
128144
/**
129145
* Create a secret with username and password and Elasticsearch host and port in the specified namespace.
130146
*

0 commit comments

Comments
 (0)