Skip to content

Commit

Permalink
Optimize the format. Added run_command exception detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
lixintao committed Jun 28, 2024
1 parent 6ee72ff commit 53feb48
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions avocado/utils/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,10 @@ def set_mtu(self, mtu, timeout=30):
up again. Default is 30.
"""
cmd = f"ip link set {self.name} mtu {mtu}"
run_command(cmd, self.host, sudo=True)
try:
run_command(cmd, self.host, sudo=True)
except Exception as ex:
raise NWException(f"Failed to set MTU. {ex}")
wait_for(self.is_link_up, timeout=timeout)
if int(mtu) != self.get_mtu():
raise NWException("Failed to set MTU.")
Expand Down Expand Up @@ -694,8 +697,7 @@ def are_packets_lost(self, peer_ip, options=None, sudo=False):
:param options: Type is List. Options such as -c, -f. Default is None
:param sudo: If sudo permissions are needed. Default is False
"""
cmd = f"ping -I {self.name} {peer_ip}"
cmd = f"{cmd} "
cmd = f"ping -I {self.name} {peer_ip} "
if options is not None:
for elem in options:
cmd += f"{elem} "
Expand Down Expand Up @@ -772,7 +774,7 @@ def validate_ipv4_netmask_format(self, netmask):
if not 0 <= num <= 255:
return False
octet_bin = [format(int(i), "08b") for i in netmask_list]
binary_netmask = ("").join(octet_bin)
binary_netmask = "".join(octet_bin)
accept_zero_only = False
first_bit = True
for symbol in binary_netmask:
Expand Down

0 comments on commit 53feb48

Please sign in to comment.