Skip to content

Commit ad8f564

Browse files
CherryPicked: [cnv-4.20] net: Randomize IPv4 address (#2655)
cherry-pick #2552 into cnv-4.20 requested-by azhivovk Signed-off-by: Asia Khromov <[email protected]> Co-authored-by: Asia Zhivov Khromov <[email protected]>
1 parent 6c7fbf5 commit ad8f564

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

tests/network/bgp/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
generate_frr_conf,
3030
wait_for_bgp_connection_established,
3131
)
32+
from tests.network.libs.ip import random_ipv4_address
3233
from tests.network.libs.label_selector import LabelSelector
3334
from tests.network.libs.nodenetworkstate import DEFAULT_ROUTE_V4, lookup_br_ex_gateway_v4
3435
from tests.network.libs.vm_factory import udn_vm
@@ -38,8 +39,8 @@
3839
BGP_DATA_PATH: Final[Path] = Path(__file__).resolve().parent / "data" / "frr-config"
3940
CUDN_BGP_LABEL: Final[dict] = {"cudn-bgp": "blue"}
4041
CUDN_SUBNET_IPV4: Final[str] = "192.168.10.0/24"
41-
EXTERNAL_PROVIDER_SUBNET_IPV4: Final[str] = "10.250.100.0/24"
42-
EXTERNAL_PROVIDER_IP_V4: Final[str] = "10.250.100.150/24"
42+
EXTERNAL_PROVIDER_SUBNET_IPV4: Final[str] = f"{random_ipv4_address(net_seed=1, host_address=0)}/24"
43+
EXTERNAL_PROVIDER_IP_V4: Final[str] = f"{random_ipv4_address(net_seed=1, host_address=150)}/24"
4344
IPERF3_SERVER_PORT: Final[int] = 2354
4445

4546

tests/network/macspoof/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pyhelper_utils.shell import run_ssh_commands
99
from timeout_sampler import TimeoutSampler
1010

11+
from tests.network.libs.ip import random_ipv4_address
1112
from utilities.constants import LINUX_BRIDGE, TIMEOUT_30SEC
1213
from utilities.infra import get_node_selector_dict, name_prefix
1314
from utilities.network import (
@@ -102,7 +103,9 @@ def linux_bridge_attached_vma(
102103
linux_macspoof_nad,
103104
):
104105
name = "vma"
105-
networks, network_data_data = _networks_data(nad=linux_macspoof_nad, ip="10.200.0.1/24")
106+
networks, network_data_data = _networks_data(
107+
nad=linux_macspoof_nad, ip=f"{random_ipv4_address(net_seed=0, host_address=1)}/24"
108+
)
106109
cloud_init_data = compose_cloud_init_data_dict(
107110
network_data=network_data_data,
108111
)
@@ -128,7 +131,9 @@ def linux_bridge_attached_vmb(
128131
linux_macspoof_nad,
129132
):
130133
name = "vmb"
131-
networks, network_data_data = _networks_data(nad=linux_macspoof_nad, ip="10.200.0.2/24")
134+
networks, network_data_data = _networks_data(
135+
nad=linux_macspoof_nad, ip=f"{random_ipv4_address(net_seed=0, host_address=2)}/24"
136+
)
132137
cloud_init_data = compose_cloud_init_data_dict(
133138
network_data=network_data_data,
134139
)

tests/network/migration/test_migration.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pyhelper_utils.shell import run_ssh_commands
1313
from timeout_sampler import TimeoutSampler
1414

15+
from tests.network.libs.ip import random_ipv4_address
1516
from tests.network.utils import (
1617
assert_ssh_alive,
1718
run_ssh_in_background,
@@ -113,7 +114,9 @@ def vma(
113114
):
114115
name = "vma"
115116
networks = {br1test_nad.name: br1test_nad.name}
116-
network_data_data = {"ethernets": {"eth1": {"addresses": ["10.200.0.1/24"]}}}
117+
network_data_data = {
118+
"ethernets": {"eth1": {"addresses": [f"{random_ipv4_address(net_seed=0, host_address=1)}/24"]}}
119+
}
117120
cloud_init_data = compose_cloud_init_data_dict(
118121
network_data=network_data_data,
119122
ipv6_network_data=dual_stack_network_data,
@@ -142,7 +145,9 @@ def vmb(
142145
):
143146
name = "vmb"
144147
networks = {br1test_nad.name: br1test_nad.name}
145-
network_data_data = {"ethernets": {"eth1": {"addresses": ["10.200.0.2/24"]}}}
148+
network_data_data = {
149+
"ethernets": {"eth1": {"addresses": [f"{random_ipv4_address(net_seed=0, host_address=2)}/24"]}}
150+
}
146151
cloud_init_data = compose_cloud_init_data_dict(
147152
network_data=network_data_data,
148153
ipv6_network_data=dual_stack_network_data,

tests/network/upgrade/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from ocp_resources.virtual_machine import VirtualMachine
33

4+
from tests.network.libs.ip import random_ipv4_address
45
from utilities.constants import (
56
ES_NONE,
67
KMP_DISABLED_LABEL,
@@ -43,7 +44,7 @@ def vma_upgrade_mac_spoof(worker_node1, unprivileged_client, upgrade_linux_macsp
4344
networks=vm_nad_networks_data,
4445
interfaces=sorted(vm_nad_networks_data.keys()),
4546
client=unprivileged_client,
46-
cloud_init_data=cloud_init(ip_address="10.200.0.1"),
47+
cloud_init_data=cloud_init(ip_address=random_ipv4_address(net_seed=0, host_address=1)),
4748
body=fedora_vm_body(name=name),
4849
node_selector=get_node_selector_dict(node_selector=worker_node1.hostname),
4950
run_strategy=VirtualMachine.RunStrategy.ALWAYS,
@@ -61,7 +62,7 @@ def vmb_upgrade_mac_spoof(worker_node1, unprivileged_client, upgrade_linux_macsp
6162
networks=vm_nad_networks_data,
6263
interfaces=sorted(vm_nad_networks_data.keys()),
6364
client=unprivileged_client,
64-
cloud_init_data=cloud_init(ip_address="10.200.0.2"),
65+
cloud_init_data=cloud_init(ip_address=random_ipv4_address(net_seed=0, host_address=2)),
6566
body=fedora_vm_body(name=name),
6667
node_selector=get_node_selector_dict(node_selector=worker_node1.hostname),
6768
run_strategy=VirtualMachine.RunStrategy.ALWAYS,

tests/network/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
1111

1212
from tests.network.constants import BRCNV
13+
from tests.network.libs.ip import random_ipv4_address
1314
from utilities.constants import (
1415
IPV4_STR,
1516
OS_FLAVOR_FEDORA,
@@ -273,7 +274,9 @@ def vm_for_brcnv_tests(
273274
network_data = {"ethernets": {}}
274275
for idx, nad in enumerate(nads, start=1):
275276
networks[nad.name] = nad.name
276-
network_data["ethernets"][f"eth{idx}"] = {"addresses": [f"10.0.20{idx}.{address_suffix}/24"]}
277+
network_data["ethernets"][f"eth{idx}"] = {
278+
"addresses": [f"{random_ipv4_address(net_seed=idx, host_address=address_suffix)}/24"]
279+
}
277280
cloud_init_data = compose_cloud_init_data_dict(network_data=network_data)
278281

279282
with VirtualMachineForTests(

0 commit comments

Comments
 (0)