Skip to content

Commit

Permalink
remove all occurrences of deprecated function get_os_interface and ch…
Browse files Browse the repository at this point in the history
…eck for None in get_device_name
  • Loading branch information
kthare10 committed Jun 22, 2024
1 parent 2eeb993 commit 74c0d98
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions fabrictestbed_extensions/fablib/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __str__(self):
["VLAN", self.get_vlan()],
["MAC", self.get_mac()],
["Physical Device", self.get_physical_os_interface_name()],
["Device", self.get_os_interface()],
["Device", self.get_device_name()],
["Address", self.get_ip_addr()],
["Numa Node", self.get_numa_node()],
]
Expand Down Expand Up @@ -177,7 +177,7 @@ def toDict(self, skip=[]):
if self.get_node() and str(self.get_node().get_reservation_state()) == "Active":
mac = str(self.get_mac())
physical_dev = str(self.get_physical_os_interface_name())
dev = str(self.get_os_interface())
dev = str(self.get_device_name())
ip_addr = str(self.get_ip_addr())
else:
mac = ""
Expand Down Expand Up @@ -316,30 +316,26 @@ def get_device_name(self) -> str:
"""
try:
fablib_data = self.get_fablib_data()
if "dev" in fablib_data:
return fablib_data["dev"]
if "dev" in fablib_data and fablib_data.get("dev"):
return fablib_data.get("dev")
else:
# logging.debug(f"iface: {self}")
os_iface = self.get_physical_os_interface_name()
vlan = self.get_vlan()

fablib_data["base_dev"] = os_iface
if vlan is not None:
os_iface = f"{os_iface}.{vlan}"

fablib_data["base_dev"] = os_iface
fablib_data["dev"] = os_iface

self.set_fablib_data(fablib_data)
return os_iface

except:
os_iface = None

return os_iface
except Exception as e:
logging.error(f"get_device_name: error occurred - e: {e}")

def get_os_interface(self) -> str:
"""
Deprecated: see interface.get_device_name()
Gets a name of the interface the operating system uses for this
FABLib interface.
Expand All @@ -348,6 +344,9 @@ def get_os_interface(self) -> str:
:return: OS interface name
:rtype: String
.. deprecated:: 1.6.5
Use `get_device_name()` instead.
"""
try:
# logging.debug(f"iface: {self}")
Expand Down Expand Up @@ -719,8 +718,8 @@ def get_ip_link(self):

links = json.loads(stdout)

dev = self.get_os_interface()
if dev == None:
dev = self.get_device_name()
if dev is None:
return links

for link in links:
Expand All @@ -733,7 +732,7 @@ def get_ip_link(self):
def get_ip_addr_show(self, dev=None):
try:
if not dev:
dev = self.get_os_interface()
dev = self.get_device_name()

stdout, stderr = self.get_node().execute(
f"ip -j addr show {dev}", quiet=True
Expand All @@ -757,7 +756,7 @@ def get_ip_addr_ssh(self, dev=None):

addrs = json.loads(stdout)

dev = self.get_os_interface()
dev = self.get_device_name()
# print(f"dev: {dev}")

if dev is None:
Expand All @@ -782,14 +781,12 @@ def get_ips(self, family=None):
"""
return_ips = []
try:
dev = self.get_os_interface()

ip_addr = self.get_ip_addr()

# print(f"{ip_addr}")

for addr_info in ip_addr["addr_info"]:
if family == None:
if family is None:
return_ips.append(addr_info["local"])
else:
if addr_info["family"] == family:
Expand Down

0 comments on commit 74c0d98

Please sign in to comment.