@@ -212,7 +212,7 @@ public void verifyAdminServerExternalService(String username, String password) t
212212
213213 // logger.info("Inside verifyAdminServerExternalService");
214214 if (exposeAdminNodePort ) {
215- String nodePortHost = TestUtils . getHostName ();
215+ String nodePortHost = getHostNameForCurl ();
216216 String nodePort = getNodePort ();
217217 logger .info ("nodePortHost " + nodePortHost + " nodePort " + nodePort );
218218
@@ -363,11 +363,7 @@ public void callWebAppAndVerifyLoadBalancing(String webappName, boolean verifyLo
363363 if (!loadBalancer .equals ("NONE" )) {
364364 // url
365365 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 ("/" );
371367 if (loadBalancer .equals ("APACHE" )) {
372368 testAppUrl .append ("weblogic/" );
373369 }
@@ -599,7 +595,7 @@ public void verifyAdminConsoleViaLB() throws Exception {
599595 logger .info ("This check is done only for APACHE load balancer" );
600596 return ;
601597 }
602- String nodePortHost = TestUtils . getHostName ();
598+ String nodePortHost = getHostNameForCurl ();
603599 int nodePort = getAdminSericeLBNodePort ();
604600 String responseBodyFile =
605601 userProjectsDir + "/weblogic-domains/" + domainUid + "/testconsole.response.body" ;
@@ -1112,4 +1108,25 @@ private String getNodePort() throws Exception {
11121108 + "for the admin server in domain." );
11131109 }
11141110 }
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+ }
11151132}
0 commit comments