Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/network/l2_bridge/test_bridge_nic_hot_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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,
)


Expand Down
25 changes: 9 additions & 16 deletions tests/network/l2_bridge/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -186,21 +187,21 @@ 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)

# 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(
Expand All @@ -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,
Expand Down