32
32
import static oracle .weblogic .kubernetes .TestConstants .BASE_IMAGES_REPO_SECRET_NAME ;
33
33
import static oracle .weblogic .kubernetes .TestConstants .DB_IMAGE_TO_USE_IN_SPEC ;
34
34
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
35
+ import static oracle .weblogic .kubernetes .TestConstants .FMWINFRA_IMAGE_NAME ;
36
+ import static oracle .weblogic .kubernetes .TestConstants .FMWINFRA_IMAGE_TAG ;
35
37
import static oracle .weblogic .kubernetes .TestConstants .FMWINFRA_IMAGE_TO_USE_IN_SPEC ;
36
38
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
37
39
import static oracle .weblogic .kubernetes .TestConstants .KIND_REPO ;
45
47
import static oracle .weblogic .kubernetes .utils .ApplicationUtils .callWebAppAndWaitTillReady ;
46
48
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
47
49
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
50
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
48
51
import static oracle .weblogic .kubernetes .utils .DbUtils .createRcuSecretWithUsernamePassword ;
49
52
import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
50
53
import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
@@ -184,9 +187,14 @@ void testFmwDomainInImageSample(String model) {
184
187
}
185
188
186
189
private void createDomainAndVerify (String domainName , Path sampleBase ) {
190
+ testUntil (
191
+ getInstanceAndContainerHostInfo (),
192
+ logger ,
193
+ "Successfully got both instance and container hostname infor" );
194
+
187
195
// run create-domain.sh to create domain.yaml file
188
196
logger .info ("Run create-domain.sh to create domain.yaml file" );
189
- CommandParams params = new CommandParams ().defaults ();
197
+ final CommandParams params = new CommandParams ().defaults ();
190
198
params .command ("sh "
191
199
+ Paths .get (sampleBase .toString (), "create-domain.sh" ).toString ()
192
200
+ " -i " + Paths .get (sampleBase .toString (), "create-domain-inputs.yaml" ).toString ()
@@ -197,8 +205,13 @@ private void createDomainAndVerify(String domainName, Path sampleBase) {
197
205
+ " -o "
198
206
+ Paths .get (sampleBase .toString ()));
199
207
200
- boolean result = Command .withParams (params ).execute ();
201
- assertTrue (result , "Failed to create domain.yaml" );
208
+ logger .info ("Going to run sample create-domain.sh" );
209
+ testUntil (
210
+ () -> {
211
+ return Command .withParams (params ).execute ();
212
+ },
213
+ logger ,
214
+ "Running sample create-domain.sh to create domain.yaml" );
202
215
203
216
//If the tests are running in kind cluster, push the image to kind registry
204
217
if (KIND_REPO != null ) {
@@ -220,11 +233,11 @@ private void createDomainAndVerify(String domainName, Path sampleBase) {
220
233
221
234
// run kubectl to create the domain
222
235
logger .info ("Run kubectl to create the domain" );
223
- params = new CommandParams ().defaults ();
224
- params .command ("kubectl apply -f "
236
+ CommandParams params1 = new CommandParams ().defaults ();
237
+ params1 .command ("kubectl apply -f "
225
238
+ Paths .get (sampleBase .toString (), "weblogic-domains/" + domainName + "/domain.yaml" ).toString ());
226
239
227
- result = Command .withParams (params ).execute ();
240
+ boolean result = Command .withParams (params1 ).execute ();
228
241
assertTrue (result , "Failed to create domain custom resource" );
229
242
230
243
// wait for the domain to exist
@@ -412,4 +425,42 @@ private Callable<Boolean> tagAndPushToKind(String originalImage, String taggedIm
412
425
});
413
426
}
414
427
428
+ private Callable <Boolean > getInstanceAndContainerHostInfo () {
429
+ return (() -> {
430
+ return getHostnameInfo ();
431
+ });
432
+ }
433
+
434
+ private Boolean getHostnameInfo () {
435
+
436
+ String fmwBaseImage = FMWINFRA_IMAGE_NAME + ":" + FMWINFRA_IMAGE_TAG ;
437
+ logger .info ("Getting host infor of running instance and container by image: " + fmwBaseImage );
438
+ String command1 = "cat /etc/resolv.conf && cat /etc/hosts" ;
439
+ CommandParams params1 =
440
+ defaultCommandParams ()
441
+ .command (command1 )
442
+ .saveResults (true );
443
+
444
+ String command2 = String .format (
445
+ "docker run %s /bin/bash -c \" cat /etc/resolv.conf && cat /etc/hosts\" " ,
446
+ fmwBaseImage );
447
+ CommandParams params2 =
448
+ defaultCommandParams ()
449
+ .command (command2 )
450
+ .saveResults (true )
451
+ .redirect (true );
452
+
453
+ if (Command .withParams (params1 ).execute ()
454
+ && params1 .stdout () != null
455
+ && params1 .stdout ().length () != 0
456
+ && Command .withParams (params2 ).execute ()
457
+ && params2 .stdout () != null
458
+ && params2 .stdout ().length () != 0 ) {
459
+ logger .info ("Got both instance and container host infor" );
460
+ return true ;
461
+ }
462
+
463
+ return false ;
464
+ }
465
+
415
466
}
0 commit comments