@@ -212,7 +212,7 @@ public void verifyAdminServerExternalService(String username, String password) t
212
212
213
213
// logger.info("Inside verifyAdminServerExternalService");
214
214
if (exposeAdminNodePort ) {
215
- String nodePortHost = TestUtils . getHostName ();
215
+ String nodePortHost = getHostNameForCurl ();
216
216
String nodePort = getNodePort ();
217
217
logger .info ("nodePortHost " + nodePortHost + " nodePort " + nodePort );
218
218
@@ -363,11 +363,7 @@ public void callWebAppAndVerifyLoadBalancing(String webappName, boolean verifyLo
363
363
if (!loadBalancer .equals ("NONE" )) {
364
364
// url
365
365
StringBuffer testAppUrl = new StringBuffer ("http://" );
366
- testAppUrl
367
- .append (TestUtils .getHostName ())
368
- .append (":" )
369
- .append (loadBalancerWebPort )
370
- .append ("/" );
366
+ testAppUrl .append (getHostNameForCurl ()).append (":" ).append (loadBalancerWebPort ).append ("/" );
371
367
if (loadBalancer .equals ("APACHE" )) {
372
368
testAppUrl .append ("weblogic/" );
373
369
}
@@ -599,7 +595,7 @@ public void verifyAdminConsoleViaLB() throws Exception {
599
595
logger .info ("This check is done only for APACHE load balancer" );
600
596
return ;
601
597
}
602
- String nodePortHost = TestUtils . getHostName ();
598
+ String nodePortHost = getHostNameForCurl ();
603
599
int nodePort = getAdminSericeLBNodePort ();
604
600
String responseBodyFile =
605
601
userProjectsDir + "/weblogic-domains/" + domainUid + "/testconsole.response.body" ;
@@ -1112,4 +1108,25 @@ private String getNodePort() throws Exception {
1112
1108
+ "for the admin server in domain." );
1113
1109
}
1114
1110
}
1111
+
1112
+ private String getHostNameForCurl () throws Exception {
1113
+ if (System .getenv ("K8S_NODEPORT_HOST" ) != null ) {
1114
+ return System .getenv ("K8S_NODEPORT_HOST" );
1115
+ } else {
1116
+ // ExecResult result = ExecCommand.exec("hostname | awk -F. '{print $1}'");
1117
+ ExecResult result1 =
1118
+ ExecCommand .exec ("kubectl get nodes -o=jsonpath='{range .items[0]}{.metadata.name}'" );
1119
+ if (result1 .exitValue () != 0 ) {
1120
+ throw new RuntimeException ("FAILURE: Could not get K8s Node name" );
1121
+ }
1122
+ ExecResult result2 =
1123
+ ExecCommand .exec (
1124
+ "nslookup " + result1 .stdout () + " | grep \" ^Name\" | awk '{ print $2 }'" );
1125
+ if (result2 .stdout ().trim ().equals ("" )) {
1126
+ return result1 .stdout ().trim ();
1127
+ } else {
1128
+ return result2 .stdout ().trim ();
1129
+ }
1130
+ }
1131
+ }
1115
1132
}
0 commit comments