Skip to content

Commit 0caa4e4

Browse files
committed
net, libs: Move NAD ref change helper
Move update_nad_references to libs/net/nad_ref.py so it is available to all test packages. Update all callers in l2_bridge nad_ref_change tests to import from the new location. Signed-off-by: Asia Khromov <azhivovk@redhat.com> Assisted-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 5e9c2fc commit 0caa4e4

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

tests/network/l2_bridge/nad_ref_change/lib_helpers.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from copy import deepcopy
21
from typing import Final
32

43
from kubernetes.dynamic import DynamicClient
54

6-
from libs.net.vmspec import wait_for_no_vmi_condition, wait_for_vmi_condition_status
75
from libs.vm.factory import base_vmspec, fedora_vm
86
from libs.vm.spec import (
97
CloudInitNoCloud,
@@ -75,26 +73,6 @@ def assert_no_connectivity(
7573
)
7674

7775

78-
def update_nad_references(vm: BaseVirtualMachine, nad_name_by_net: dict[str, str]) -> None:
79-
"""Update secondary network NAD references and wait for the change to be fully applied.
80-
81-
Patches the VM spec atomically, then waits for the MigrationRequired condition to
82-
appear (change detected) and disappear (migration completed).
83-
84-
Args:
85-
vm: The virtual machine to update.
86-
nad_name_by_net: Mapping of interface name to new NAD name.
87-
"""
88-
resource_version = vm.vmi.instance.metadata.resourceVersion
89-
networks = deepcopy(vm.template_spec.networks) or []
90-
for network in networks:
91-
if network.name in nad_name_by_net and network.multus:
92-
network.multus.networkName = nad_name_by_net[network.name]
93-
vm.set_networks(networks=networks)
94-
wait_for_vmi_condition_status(vm=vm, condition="MigrationRequired", resource_version=resource_version)
95-
wait_for_no_vmi_condition(vm=vm, condition="MigrationRequired")
96-
97-
9876
def two_secondary_bridge_vm(
9977
namespace: str,
10078
name: str,

tests/network/l2_bridge/nad_ref_change/test_nad_ref_change.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
GUEST_IFACE_2,
2222
assert_connectivity,
2323
assert_no_connectivity,
24-
update_nad_references,
2524
)
25+
from tests.network.libs.nad_ref import update_nad_references
2626

2727

2828
@pytest.mark.usefixtures("baseline_connectivity")

tests/network/libs/nad_ref.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from copy import deepcopy
2+
3+
from libs.net.vmspec import wait_for_no_vmi_condition, wait_for_vmi_condition_status
4+
from libs.vm.vm import BaseVirtualMachine
5+
6+
7+
def update_nad_references(vm: BaseVirtualMachine, nad_name_by_net: dict[str, str]) -> None:
8+
"""Update secondary network NAD references and wait for the change to be fully applied.
9+
10+
Patches the VM spec atomically, then waits for the MigrationRequired condition to
11+
appear (change detected) and disappear (migration completed).
12+
13+
Args:
14+
vm: The virtual machine to update.
15+
nad_name_by_net: Mapping of spec network name to new NAD name.
16+
"""
17+
resource_version = vm.vmi.instance.metadata.resourceVersion
18+
networks = deepcopy(vm.template_spec.networks) or []
19+
for network in networks:
20+
if network.name in nad_name_by_net and network.multus:
21+
network.multus.networkName = nad_name_by_net[network.name]
22+
vm.set_networks(networks=networks)
23+
wait_for_vmi_condition_status(vm=vm, condition="MigrationRequired", resource_version=resource_version)
24+
wait_for_no_vmi_condition(vm=vm, condition="MigrationRequired")

0 commit comments

Comments
 (0)