Skip to content

Commit 7c3dadf

Browse files
authored
Merge pull request #534 from sathnaga/serverip_fixup
Fixup: Alternate method to get server ip for boxes with older nc utility
2 parents bfdad02 + a6d1204 commit 7c3dadf

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

common/OpTestSystem.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,24 @@ def get_my_ip_from_host_perspective(self):
12931293
log.debug("Processing in Exception path, e={}".format(e))
12941294
raw_pty.sendcontrol('c') # to avoid incase nc command hangs
12951295
time.sleep(2) # give it time to recover
1296-
log.debug("Exception path sleeping 2 seconds to recover")
1297-
# Petitboot does not support hostname -I
1298-
log.warning(
1299-
"Using my_ip={} from Exception path handling, this may not work".format(my_ip))
1296+
try:
1297+
ip = subprocess.check_output(['hostname', '-i']).decode('utf-8').strip()
1298+
ip_lst = subprocess.check_output(['hostname', '-I']).decode('utf-8').strip().split()
1299+
# Let's validate the IP
1300+
for item in ip_lst:
1301+
if item == ip:
1302+
my_ip = ip
1303+
break
1304+
if not my_ip:
1305+
if len(ip_lst) == 1:
1306+
my_ip = ip_lst[0]
1307+
else:
1308+
log.warning("Unable to get server ip, "
1309+
"hostname -i does not provide valid IP, "
1310+
"correct and proceed with installation")
1311+
except subprocess.CalledProcessError as e:
1312+
log.warning("Unable to get server ip, hostname -i/-I "
1313+
"commands not supported in server")
13001314

13011315
return my_ip
13021316

0 commit comments

Comments
 (0)