summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <donaldsharp72@gmail.com>2025-04-11 08:41:02 -0400
committerGitHub <noreply@github.com>2025-04-11 08:41:02 -0400
commitf34ee05f8b2ca3381020763a936921935dec5002 (patch)
tree11270ec347183dc9967ab6f9db607b765a0f3cad
parent01085bfbec785e3732645abd3bf3de33f405ad46 (diff)
parent868796cf690003b8e0bf00241dcceccf3befe070 (diff)
Merge pull request #18633 from y-bharath14/srib-tests-v11
tests: Fix potential issues in mcast-tester.py
-rwxr-xr-xtests/topotests/lib/mcast-tester.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/tests/topotests/lib/mcast-tester.py b/tests/topotests/lib/mcast-tester.py
index 3645eef25e..ecb99dc82b 100755
--- a/tests/topotests/lib/mcast-tester.py
+++ b/tests/topotests/lib/mcast-tester.py
@@ -25,28 +25,46 @@ import time
#
def interface_name_to_index(name):
"Gets the interface index using its name. Returns None on failure."
- interfaces = json.loads(subprocess.check_output("ip -j link show", shell=True))
+ try:
+ interfaces = json.loads(subprocess.check_output("ip -j link show", shell=True))
+ except subprocess.CalledProcessError as err:
+ print(f"Error executing command: {err}")
+ return None
+ except json.JSONDecodeError as err:
+ print(f"Error decoding JSON: {err}")
+ return None
for interface in interfaces:
- if interface["ifname"] == name:
- return interface["ifindex"]
+ if interface.get("ifname") == name:
+ return interface.get("ifindex")
return None
def interface_index_to_address(index, iptype="inet"):
"Gets the interface main address using its name. Returns None on failure."
- interfaces = json.loads(subprocess.check_output("ip -j addr show", shell=True))
+ try:
+ interfaces = json.loads(subprocess.check_output("ip -j addr show", shell=True))
+ except subprocess.CalledProcessError as err:
+ print(f"Error executing command: {err}")
+ return None
+ except json.JSONDecodeError as err:
+ print(f"Error decoding JSON: {err}")
+ return None
for interface in interfaces:
- if interface["ifindex"] == index:
+ if interface.get("ifindex") == index:
break
+ else:
+ return None
- for address in interface["addr_info"]:
- if address["family"] == iptype:
+ for address in interface.get("addr_info"):
+ if address.get("family") == iptype:
break
+ else:
+ return None
- local_address = ipaddress.ip_address(address["local"])
+ local_address = ipaddress.ip_address(address.get("local"))
return local_address.packed