Automation fix for ifconfig command
Changes:
- ifconfig error message:
Command 'ifconfig' returned non-zero exit status 127.
- New implementaion uses socket module to get the hostname.
Change-Id: I3b60efe5b88fb44676b729cb8b28ebb9cf735638
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
diff --git a/lib/bmc_network_utils.py b/lib/bmc_network_utils.py
index 00a675f..c2ea9f8 100644
--- a/lib/bmc_network_utils.py
+++ b/lib/bmc_network_utils.py
@@ -13,6 +13,7 @@
import re
import ipaddress
import subprocess
+import socket
from robot.libraries.BuiltIn import BuiltIn
import json
import bmc_ssh_utils as bsu
@@ -20,16 +21,15 @@
ip_regex = r"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}"
-def get_running_system_ip():
+def get_hostname():
r"""
- Get the IP address of server from which robot code is running.
+ Get the host name of server from which robot code is running.
+
"""
- stdout = subprocess.check_output("/sbin/ifconfig", shell=True)
- stdout = stdout.decode("utf-8")
- ip_list = re.findall(ip_regex, stdout)
+ host_name = socket.gethostname()
- return ip_list
+ return host_name
def netmask_prefix_length(netmask):
diff --git a/openpower/ext_interfaces/test_client_identifier.robot b/openpower/ext_interfaces/test_client_identifier.robot
index 97d9cff..92124d1 100644
--- a/openpower/ext_interfaces/test_client_identifier.robot
+++ b/openpower/ext_interfaces/test_client_identifier.robot
@@ -129,11 +129,13 @@
${sessions}= Redfish.Get Properties /redfish/v1/SessionService/Sessions/${session_id}
Rprint Vars sessions
@{words} = Split String ${sessions["Oem"]["OpenBMC"]["ClientOriginIP"]} :
- ${ipaddr}= Get Running System IP
+ ${host_name}= Get Hostname
+ ${host_name} ${ip_address}= Get Host Name IP host=${host_name}
+ Set Suite Variable ${ip_address}
Set Test Variable ${temp_ipaddr} ${words}[-1]
Valid Value client ['${sessions["Oem"]["OpenBMC"]["ClientID"]}']
Valid Value sessions["Id"] ['${session_id}']
- Valid Value temp_ipaddr ${ipaddr}
+ Valid Value temp_ipaddr ['${ip_address}']
END