2121import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
2222import oracle .weblogic .kubernetes .annotations .Namespaces ;
2323import oracle .weblogic .kubernetes .logging .LoggingFacade ;
24+ import oracle .weblogic .kubernetes .utils .ExecResult ;
2425import org .junit .jupiter .api .BeforeAll ;
2526import org .junit .jupiter .api .DisplayName ;
2627import org .junit .jupiter .api .MethodOrderer ;
5657import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
5758import static oracle .weblogic .kubernetes .utils .DomainUtils .deleteDomainResource ;
5859import static oracle .weblogic .kubernetes .utils .FmwUtils .createDomainResourceSimplifyJrfPv ;
60+ import static oracle .weblogic .kubernetes .utils .FmwUtils .restoreOpssWalletfileSecret ;
5961import static oracle .weblogic .kubernetes .utils .FmwUtils .saveAndRestoreOpssWalletfileSecret ;
6062import static oracle .weblogic .kubernetes .utils .FmwUtils .verifyDomainReady ;
6163import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
6567import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodDoesNotExist ;
6668import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodLogContains ;
6769import static oracle .weblogic .kubernetes .utils .PodUtils .getExternalServicePodName ;
70+ import static oracle .weblogic .kubernetes .utils .SecretUtils .createOpsswalletFileSecretWithoutFile ;
6871import static oracle .weblogic .kubernetes .utils .SecretUtils .createOpsswalletpasswordSecret ;
6972import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
7073import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
74+ import static org .apache .commons .io .FileUtils .delete ;
7175import static org .apache .commons .io .FileUtils .deleteDirectory ;
7276import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
7377import 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" );
0 commit comments