Skip to content

Commit 5c2c33a

Browse files
authored
net, l2 bridge: Small fixes (#4097)
Small follow-up PR to apply requested changes: #3567 (comment) #3567 (comment) - Client is a mandatory parameter - Assign the DHCP interface on each VM according to the type client/server - Drop matrix in setup and use pytest.parametrize <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Expanded L2 bridge tests to run against both Linux and OVS bridge types and added a class-scoped fixture for selecting device type. * **Refactor** * Test fixtures and VM setup updated to propagate the chosen bridge device type and include explicit DHCP interface configuration for more consistent test provisioning. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents fb1a391 + a1db96e commit 5c2c33a

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

tests/network/l2_bridge/conftest.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
VMB_MPLS_ROUTE_TAG = 200
3737

3838

39+
@pytest.fixture(scope="class")
40+
def bridge_device_type(request):
41+
return request.param
42+
43+
3944
@pytest.fixture(scope="class")
4045
def l2_bridge_device_name(index_number):
4146
yield f"br{next(index_number)}test"
@@ -45,13 +50,13 @@ def l2_bridge_device_name(index_number):
4550
def l2_bridge_device_worker_1(
4651
nmstate_dependent_placeholder,
4752
admin_client,
48-
bridge_device_matrix__class__,
4953
hosts_common_available_ports,
5054
worker_node1,
55+
bridge_device_type,
5156
l2_bridge_device_name,
5257
):
5358
with network_device(
54-
interface_type=bridge_device_matrix__class__,
59+
interface_type=bridge_device_type,
5560
nncp_name=f"l2-bridge-{name_prefix(worker_node1.name)}",
5661
interface_name=l2_bridge_device_name,
5762
node_selector=get_node_selector_dict(node_selector=worker_node1.hostname),
@@ -65,13 +70,13 @@ def l2_bridge_device_worker_1(
6570
def l2_bridge_device_worker_2(
6671
nmstate_dependent_placeholder,
6772
admin_client,
68-
bridge_device_matrix__class__,
6973
hosts_common_available_ports,
7074
worker_node2,
75+
bridge_device_type,
7176
l2_bridge_device_name,
7277
):
7378
with network_device(
74-
interface_type=bridge_device_matrix__class__,
79+
interface_type=bridge_device_type,
7580
nncp_name=f"l2-bridge-{name_prefix(worker_node2.name)}",
7681
interface_name=l2_bridge_device_name,
7782
node_selector=get_node_selector_dict(node_selector=worker_node2.hostname),
@@ -84,17 +89,17 @@ def l2_bridge_device_worker_2(
8489
@pytest.fixture(scope="class")
8590
def dhcp_nad(
8691
admin_client,
87-
bridge_device_matrix__class__,
8892
namespace,
8993
l2_bridge_device_worker_1,
9094
l2_bridge_device_worker_2,
91-
l2_bridge_device_name,
9295
vlan_index_number,
96+
bridge_device_type,
97+
l2_bridge_device_name,
9398
):
9499
vlan_tag = next(vlan_index_number)
95100
with network_nad(
96101
namespace=namespace,
97-
nad_type=bridge_device_matrix__class__,
102+
nad_type=bridge_device_type,
98103
nad_name=f"{l2_bridge_device_name}-dhcp-broadcast-nad-vlan-{vlan_tag}",
99104
interface_name=l2_bridge_device_name,
100105
vlan=vlan_tag,
@@ -106,15 +111,15 @@ def dhcp_nad(
106111
@pytest.fixture(scope="class")
107112
def custom_eth_type_llpd_nad(
108113
admin_client,
109-
bridge_device_matrix__class__,
110114
namespace,
111115
l2_bridge_device_worker_1,
112116
l2_bridge_device_worker_2,
117+
bridge_device_type,
113118
l2_bridge_device_name,
114119
):
115120
with network_nad(
116121
namespace=namespace,
117-
nad_type=bridge_device_matrix__class__,
122+
nad_type=bridge_device_type,
118123
nad_name=f"{l2_bridge_device_name}-custom-eth-type-icmp-nad",
119124
interface_name=l2_bridge_device_name,
120125
client=admin_client,
@@ -125,15 +130,15 @@ def custom_eth_type_llpd_nad(
125130
@pytest.fixture(scope="class")
126131
def mpls_nad(
127132
admin_client,
128-
bridge_device_matrix__class__,
129133
namespace,
130134
l2_bridge_device_worker_1,
131135
l2_bridge_device_worker_2,
136+
bridge_device_type,
132137
l2_bridge_device_name,
133138
):
134139
with network_nad(
135140
namespace=namespace,
136-
nad_type=bridge_device_matrix__class__,
141+
nad_type=bridge_device_type,
137142
nad_name=f"{l2_bridge_device_name}-mpls-nad",
138143
interface_name=l2_bridge_device_name,
139144
client=admin_client,
@@ -144,15 +149,15 @@ def mpls_nad(
144149
@pytest.fixture(scope="class")
145150
def dot1q_nad(
146151
admin_client,
147-
bridge_device_matrix__class__,
148152
namespace,
149153
l2_bridge_device_worker_1,
150154
l2_bridge_device_worker_2,
155+
bridge_device_type,
151156
l2_bridge_device_name,
152157
):
153158
with network_nad(
154159
namespace=namespace,
155-
nad_type=bridge_device_matrix__class__,
160+
nad_type=bridge_device_type,
156161
nad_name=f"{l2_bridge_device_name}-dot1q-nad",
157162
interface_name=l2_bridge_device_name,
158163
client=admin_client,
@@ -202,6 +207,7 @@ def l2_bridge_running_vm_a(
202207
mpls_route_next_hop=random_ipv4_address(net_seed=4, host_address=2),
203208
client=unprivileged_client,
204209
node_selector=get_node_selector_dict(node_selector=worker_node1.hostname),
210+
dhcp_interface_config={"addresses": [f"{interface_ip_addresses[2]}/24"]},
205211
) as vm:
206212
vm.start(wait=True)
207213
vm.wait_for_agent_connected()
@@ -228,6 +234,7 @@ def l2_bridge_running_vm_b(namespace, worker_node2, l2_bridge_all_nads, unprivil
228234
mpls_route_next_hop=random_ipv4_address(net_seed=4, host_address=1),
229235
client=unprivileged_client,
230236
node_selector=get_node_selector_dict(node_selector=worker_node2.hostname),
237+
dhcp_interface_config={"dhcp4": False},
231238
) as vm:
232239
vm.start(wait=True)
233240
vm.wait_for_agent_connected()

tests/network/l2_bridge/libl2bridge.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,20 @@ def bridge_attached_vm(
372372
mpls_dest_tag,
373373
mpls_route_next_hop,
374374
mpls_local_ip,
375+
client,
376+
dhcp_interface_config,
375377
cloud_init_extra_user_data=None,
376-
client=None,
377378
node_selector=None,
378379
):
379380
cloud_init_data = _cloud_init_data(
380-
vm_name=name,
381381
ip_addresses=ip_addresses,
382382
mpls_local_ip=mpls_local_ip,
383383
mpls_local_tag=mpls_local_tag,
384384
mpls_dest_ip=mpls_dest_ip,
385385
mpls_dest_tag=mpls_dest_tag,
386386
mpls_route_next_hop=mpls_route_next_hop,
387387
cloud_init_extra_user_data=cloud_init_extra_user_data,
388+
dhcp_interface_config=dhcp_interface_config,
388389
)
389390
with VirtualMachineAttachedToBridge(
390391
namespace=namespace,
@@ -404,29 +405,23 @@ def bridge_attached_vm(
404405

405406

406407
def _cloud_init_data(
407-
vm_name,
408408
ip_addresses,
409409
mpls_local_ip,
410410
mpls_local_tag,
411411
mpls_dest_ip,
412412
mpls_dest_tag,
413413
mpls_route_next_hop,
414414
cloud_init_extra_user_data,
415+
dhcp_interface_config,
415416
):
416417
network_data_data = {
417418
"ethernets": {
418419
"eth1": {"addresses": [f"{ip_addresses[0]}/24"]},
419420
"eth2": {"addresses": [f"{ip_addresses[1]}/24"]},
420421
"eth4": {"addresses": [f"{ip_addresses[3]}/24"]},
422+
DHCP_INTERFACE_NAME: dhcp_interface_config,
421423
},
422424
}
423-
# Only DHCP server VM (vm-fedora-1) should have IP on eth3 interface
424-
if vm_name == "vm-fedora-1":
425-
network_data_data["ethernets"][DHCP_INTERFACE_NAME] = {"addresses": [f"{ip_addresses[2]}/24"]}
426-
427-
# DHCP client VM (vm-fedora-2) should be with dhcp=false, will be activated in test 'test_dhcp_broadcast'.
428-
if vm_name == "vm-fedora-2":
429-
network_data_data["ethernets"][DHCP_INTERFACE_NAME] = {"dhcp4": False}
430425

431426
runcmd = [
432427
"modprobe mpls_router", # In order to test mpls we need to load driver
@@ -466,7 +461,7 @@ def __init__(
466461
mpls_dest_ip: str,
467462
mpls_dest_tag: int,
468463
mpls_route_next_hop: str,
469-
client: DynamicClient | None = None,
464+
client: DynamicClient,
470465
cloud_init_data: dict[str, dict] | None = None,
471466
node_selector: dict[str, str] | None = None,
472467
):

tests/network/l2_bridge/test_l2_ovs_linux_bridge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
from libs.net.vmspec import lookup_iface_status_ip
99
from tests.network.l2_bridge.libl2bridge import wait_for_no_packet_loss_after_connection
1010
from tests.network.libs.dhcpd import DHCP_IP_RANGE_START
11-
from utilities.constants import TIMEOUT_2MIN
11+
from utilities.constants import LINUX_BRIDGE, OVS_BRIDGE, TIMEOUT_2MIN
1212
from utilities.network import assert_ping_successful
1313

1414
pytestmark = [pytest.mark.ipv4, pytest.mark.usefixtures("hyperconverged_ovs_annotations_enabled_scope_session")]
1515

1616
CUSTOM_ETH_PROTOCOL = "0x88B6" # rfc5342 Local Experimental Ethertype. Used to test custom eth type
1717

1818

19+
@pytest.mark.parametrize("bridge_device_type", [LINUX_BRIDGE, OVS_BRIDGE], indirect=True)
1920
@pytest.mark.s390x
2021
class TestL2Bridge:
2122
"""

0 commit comments

Comments
 (0)