Skip to content

Commit

Permalink
Merge pull request #342 from fabric-testbed/341-get_device_name-add-e…
Browse files Browse the repository at this point in the history
…rror-logging-and-none-check

341 get device name add error logging and none check
  • Loading branch information
kthare10 authored Jun 24, 2024
2 parents 2eeb993 + 441ba37 commit 46c4397
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased

### Fixed
- Get Device Name and corresponding deprecated function (Issue[#341](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/341))
- Failures when adding interfaces to a network (Issue[#329](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/329))
- Add Facility Port to allow adding multiple interfaces (Issue [#289](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/289))
- validate_config errors out when config directory does not exist (Issue [#299](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/299))
Expand Down
38 changes: 19 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,29 @@ 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:

if os_iface and vlan:
os_iface = f"{os_iface}.{vlan}"

fablib_data["dev"] = os_iface

self.set_fablib_data(fablib_data)
if 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 +347,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 +721,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 +735,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 +759,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 +784,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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
"numpy",
"ipython>=8.12.0",
"fabric_fss_utils>=1.5.1",
"recordclass==0.21.1",
"atomicwrites"
]

Expand Down

0 comments on commit 46c4397

Please sign in to comment.