diff --git a/tests/network/l2_bridge/test_bridge_nic_hot_plug.py b/tests/network/l2_bridge/test_bridge_nic_hot_plug.py index d767dff4de..7de2e1538f 100644 --- a/tests/network/l2_bridge/test_bridge_nic_hot_plug.py +++ b/tests/network/l2_bridge/test_bridge_nic_hot_plug.py @@ -117,7 +117,7 @@ def hot_plugged_interface_with_address(running_vm_for_nic_hot_plug, index_number set_secondary_static_ip_address( vm=running_vm_for_nic_hot_plug, ipv4_address=random_ipv4_address(net_seed=0, host_address=next(index_number)), - vmi_interface=hot_plugged_interface.name, + vmi_interface=hot_plugged_interface, ) @@ -158,7 +158,7 @@ def hot_plugged_second_interface_with_address( set_secondary_static_ip_address( vm=running_vm_with_secondary_and_hot_plugged_interfaces, ipv4_address=random_ipv4_address(net_seed=0, host_address=next(index_number)), - vmi_interface=hot_plugged_interface_on_vm_created_with_secondary_interface.name, + vmi_interface=hot_plugged_interface_on_vm_created_with_secondary_interface, ) diff --git a/tests/network/l2_bridge/utils.py b/tests/network/l2_bridge/utils.py index 219a71dadc..69fff7c8e0 100644 --- a/tests/network/l2_bridge/utils.py +++ b/tests/network/l2_bridge/utils.py @@ -3,6 +3,7 @@ import re import time +from kubernetes.dynamic.client import ResourceField from ocp_resources.resource import ResourceEditor from timeout_sampler import TimeoutExpiredError, TimeoutSampler @@ -186,12 +187,12 @@ def create_bridge_interface_for_hot_plug( yield br -def set_secondary_static_ip_address(vm, ipv4_address, vmi_interface): - guest_vm_interface = get_guest_vm_interface_name_by_vmi_interface_name( - vm=vm, - vm_interface_name=vmi_interface, +def set_secondary_static_ip_address( + vm: VirtualMachineForTests, ipv4_address: str, vmi_interface: ResourceField +) -> None: + console_command = ( + f"sudo ip addr add {ipv4_address}/{IPV4_ADDRESS_SUBNET_PREFIX_LENGTH} dev {vmi_interface.interfaceName}" ) - console_command = f"sudo ip addr add {ipv4_address}/{IPV4_ADDRESS_SUBNET_PREFIX_LENGTH} dev {guest_vm_interface}" LOGGER.info(f"Sending command to {vm.name} console: '{console_command}'") with console.Console(vm=vm) as vm_console: vm_console.sendline(console_command) @@ -199,8 +200,8 @@ def set_secondary_static_ip_address(vm, ipv4_address, vmi_interface): # Verify the IP address was set successfully. # The function fails on timeout if the interface or its address are not found, # so there's no need to check its return code. - hot_plugged_interface_ip = get_vmi_ip_v4_by_name(vm=vm, name=vmi_interface) - LOGGER.info(f"{vm.name}/{vmi_interface} set with IP address {hot_plugged_interface_ip}") + hot_plugged_interface_ip = get_vmi_ip_v4_by_name(vm=vm, name=vmi_interface.name) + LOGGER.info(f"{vm.name}/{vmi_interface.name} set with IP address {hot_plugged_interface_ip}") def hot_plug_interface_and_set_address( @@ -220,20 +221,12 @@ def hot_plug_interface_and_set_address( set_secondary_static_ip_address( vm=vm, ipv4_address=ipv4_address, - vmi_interface=iface.name, + vmi_interface=iface, ) return iface -def get_guest_vm_interface_name_by_vmi_interface_name(vm, vm_interface_name): - vmi_interfaces = vm.vmi.interfaces - for interface in vmi_interfaces: - if interface["name"] == vm_interface_name: - return interface["interfaceName"] - raise IfaceNotFound(name=vm_interface_name) - - @contextlib.contextmanager def create_vm_for_hot_plug( namespace_name,