From 320eba3a51f1dac468a8675cae67f12bc0dc9e13 Mon Sep 17 00:00:00 2001 From: lixintao Date: Fri, 28 Jun 2024 15:20:22 +0800 Subject: [PATCH] Optimize the format. Added run_command exception detection. Signed-off-by: lixintao --- avocado/utils/network/interfaces.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/avocado/utils/network/interfaces.py b/avocado/utils/network/interfaces.py index b29207544f..23bb63ed21 100644 --- a/avocado/utils/network/interfaces.py +++ b/avocado/utils/network/interfaces.py @@ -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.") @@ -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} " @@ -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: