@@ -264,6 +264,28 @@ private static String getMethodName(TestInfo testInfo) {
264264
265265 }
266266
267+ private static CommandResult executeAndVerify (String command ) throws Exception {
268+ logger .info ("Executing command: " + command );
269+ CommandResult result = Runner .run (command );
270+ assertEquals (0 , result .exitValue (), "for command: " + command );
271+ logger .info (result .stdout ());
272+ return result ;
273+ }
274+
275+ /**
276+ * Determine if a Docker image exists on the local system.
277+ */
278+ private static boolean imageExists (String imageTag ) throws IOException , InterruptedException {
279+ return !getImageId (imageTag ).isEmpty ();
280+ }
281+
282+ /**
283+ * Get the docker identifier for this image tag.
284+ */
285+ private static String getImageId (String imageTag ) throws IOException , InterruptedException {
286+ return Runner .run ("docker images -q " + imageTag ).stdout ().trim ();
287+ }
288+
267289 private void verifyFileInImage (String imagename , String filename , String expectedContent ) throws Exception {
268290 logger .info ("verifying the file content in image" );
269291 String command = "docker run --rm " + imagename + " bash -c 'cat " + filename + "'" ;
@@ -289,14 +311,6 @@ private void createDBContainer() throws Exception {
289311 checkCmdInLoop (command );
290312 }
291313
292- private static CommandResult executeAndVerify (String command ) throws Exception {
293- logger .info ("Executing command: " + command );
294- CommandResult result = Runner .run (command );
295- assertEquals (0 , result .exitValue (), "for command: " + command );
296- logger .info (result .stdout ());
297- return result ;
298- }
299-
300314 /**
301315 * Test caching of an installer of type JDK.
302316 *
@@ -538,8 +552,8 @@ void createWlsImg(TestInfo testInfo) throws Exception {
538552 assertEquals (0 , result .exitValue (), "for command: " + command );
539553
540554 // verify the docker image is created
541- String imageId = Runner . run ( "docker images -q " + tagName , out , logger ). stdout (). trim ( );
542- assertFalse ( imageId . isEmpty (), "Image was not created: " + tagName );
555+ assertTrue ( imageExists ( tagName ), "Image was not created: " + tagName );
556+
543557 wlsImgBuilt = true ;
544558 }
545559 }
@@ -568,8 +582,8 @@ void updateWlsImg(TestInfo testInfo) throws Exception {
568582 assertEquals (0 , result .exitValue (), "for command: " + command );
569583
570584 // verify the docker image is created
571- String imageId = Runner . run ( "docker images -q " + tagName , out , logger ). stdout (). trim ( );
572- assertFalse ( imageId . isEmpty (), "Image was not created: " + tagName );
585+ assertTrue ( imageExists ( tagName ), "Image was not created: " + tagName );
586+
573587 // TODO should check that patch and OPatch were applied
574588 }
575589 }
@@ -603,8 +617,8 @@ void createWlsImgUsingWdt(TestInfo testInfo) throws Exception {
603617 assertEquals (0 , result .exitValue (), "for command: " + command );
604618
605619 // verify the docker image is created
606- String imageId = Runner . run ( "docker images -q " + tagName , out , logger ). stdout (). trim ( );
607- assertFalse ( imageId . isEmpty (), "Image was not created: " + tagName );
620+ assertTrue ( imageExists ( tagName ), "Image was not created: " + tagName );
621+
608622 domainImgBuilt = true ;
609623 }
610624 }
@@ -633,8 +647,7 @@ void rebaseWlsImg(TestInfo testInfo) throws Exception {
633647 assertEquals (0 , result .exitValue (), "for command: " + command );
634648
635649 // verify the docker image is created
636- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
637- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
650+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
638651 }
639652 }
640653
@@ -688,8 +701,7 @@ void createFmwImgFullInternetAccess(TestInfo testInfo) throws Exception {
688701 assertEquals (0 , result .exitValue (), "for command: " + command );
689702
690703 // verify the docker image is created
691- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
692- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
704+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
693705 }
694706 }
695707
@@ -744,8 +756,7 @@ void createJrfDomainImgUsingWdt(TestInfo testInfo) throws Exception {
744756 assertEquals (0 , result .exitValue (), "for command: " + command );
745757
746758 // verify the docker image is created
747- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
748- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
759+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
749760 }
750761 }
751762
@@ -784,8 +795,7 @@ void createRestrictedJrfDomainImgUsingWdt(TestInfo testInfo) throws Exception {
784795 assertEquals (0 , result .exitValue (), "for command: " + command );
785796
786797 // verify the docker image is created
787- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
788- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
798+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
789799 }
790800 }
791801
@@ -821,8 +831,7 @@ void createWlsImgUsingMultiModels(TestInfo testInfo) throws Exception {
821831 assertEquals (0 , result .exitValue (), "for command: " + command );
822832
823833 // verify the docker image is created
824- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
825- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
834+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
826835 }
827836 }
828837
@@ -851,8 +860,7 @@ void createWlsImgWithAdditionalBuildCommands(TestInfo testInfo) throws Exception
851860 assertEquals (0 , result .exitValue (), "for command: " + command );
852861
853862 // verify the docker image is created
854- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
855- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
863+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
856864 }
857865
858866 // verify the file created in [before-jdk-install] section
@@ -891,8 +899,7 @@ void createImageWithServerJRE(TestInfo testInfo) throws Exception {
891899 assertEquals (0 , result .exitValue (), "for command: " + command );
892900
893901 // verify the docker image is created
894- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
895- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
902+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
896903 }
897904 }
898905
@@ -919,8 +926,7 @@ void updateImageWithServerJRE(TestInfo testInfo) throws Exception {
919926 assertEquals (0 , result .exitValue (), "for command: " + command );
920927
921928 // verify the docker image is created
922- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
923- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
929+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
924930 }
925931 }
926932
@@ -962,8 +968,7 @@ void createMiiOl8slim(TestInfo testInfo) throws Exception {
962968 assertEquals (0 , result .exitValue (), "for command: " + command );
963969
964970 // verify the docker image is created
965- String imageId = Runner .run ("docker images -q " + tagName , out , logger ).stdout ().trim ();
966- assertFalse (imageId .isEmpty (), "Image was not created: " + tagName );
971+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
967972
968973 validateDirectoryPermissions ("/u01/domains" , "drwxrwxr-x" , tagName , out );
969974 validateDirectoryPermissions ("/u01/wdt" , "drwxrwxr-x" , tagName , out );
@@ -991,4 +996,68 @@ private void validateDirectoryPermissions(String directory, String expected, Str
991996 // When running on an SELinux host, the permissions shown by ls will end with a "."
992997 assertTrue (tokens [0 ].startsWith (expected ), "Incorrect directory permissions for " + directory );
993998 }
999+
1000+ /**
1001+ * update a WLS image with a model.
1002+ *
1003+ * @throws Exception - if any error occurs
1004+ */
1005+ @ Test
1006+ @ Order (28 )
1007+ @ Tag ("nightly" )
1008+ @ DisplayName ("Use Update to add a WDT model to createWlsImg" )
1009+ void updateAddModel (TestInfo testInfo ) throws Exception {
1010+ assumeTrue (wlsImgBuilt );
1011+
1012+ String tagName = build_tag + ":" + getMethodName (testInfo );
1013+ String command = new UpdateCommand ()
1014+ .fromImage (build_tag + ":createWlsImg" ) //from step 10, createWlsImg()
1015+ .tag (tagName )
1016+ .wdtVersion (WDT_VERSION )
1017+ .wdtModel (WDT_MODEL )
1018+ .wdtVariables (WDT_VARIABLES )
1019+ .wdtArchive (WDT_ARCHIVE )
1020+ .wdtModelOnly (true )
1021+ .build ();
1022+
1023+ try (PrintWriter out = getTestMethodWriter (testInfo )) {
1024+ CommandResult result = Runner .run (command , out , logger );
1025+ assertEquals (0 , result .exitValue (), "for command: " + command );
1026+
1027+ // verify the docker image is created
1028+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
1029+ }
1030+ }
1031+
1032+ /**
1033+ * update a WLS image with another model.
1034+ *
1035+ * @throws Exception - if any error occurs
1036+ */
1037+ @ Test
1038+ @ Order (29 )
1039+ @ Tag ("nightly" )
1040+ @ DisplayName ("Use Update to add a second WDT model to createWlsImg" )
1041+ void updateAddSecondModel (TestInfo testInfo ) throws Exception {
1042+ String testFromImage = build_tag + ":updateAddModel" ;
1043+ // skip this test if updateAddModel() failed to create an image
1044+ assumeTrue (imageExists (testFromImage ));
1045+
1046+ String tagName = build_tag + ":" + getMethodName (testInfo );
1047+ String command = new UpdateCommand ()
1048+ .fromImage (testFromImage )
1049+ .tag (tagName )
1050+ .wdtVersion (WDT_VERSION )
1051+ .wdtModel (WDT_MODEL2 )
1052+ .wdtModelOnly (true )
1053+ .build ();
1054+
1055+ try (PrintWriter out = getTestMethodWriter (testInfo )) {
1056+ CommandResult result = Runner .run (command , out , logger );
1057+ assertEquals (0 , result .exitValue (), "for command: " + command );
1058+
1059+ // verify the docker image is created
1060+ assertTrue (imageExists (tagName ), "Image was not created: " + tagName );
1061+ }
1062+ }
9941063}
0 commit comments