Skip to content

Commit 2609d0b

Browse files
authored
net, network policy: Use fixtures' ports (#4051)
Small follow-up requested change https://github.com/RedHatQE/openshift-virtualization-tests/pull/3588/changes#r2753623060 Use the allowed ports provided by the fixtures in network policy object instead of the ports constant to improve test readability, and clearly distinguish between allowed and disallowed ports. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Updated network policy tests: renamed and reworked test fixtures and signatures to remove redundant decorators, tests now consume targeted fixtures and iterate over provided ports. This improves test clarity, reduces duplication, and makes the network policy test suite more reliable and easier to extend and maintain. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Asia Khromov <azhivovk@redhat.com>
1 parent 5c2c33a commit 2609d0b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

tests/network/network_policy/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def allow_all_http_ports(unprivileged_client, namespace_1):
4242

4343

4444
@pytest.fixture()
45-
def allow_single_http_port(unprivileged_client, namespace_1):
45+
def single_http_port_net_policy(unprivileged_client, namespace_1):
4646
with ApplyNetworkPolicy(
4747
name="allow-single-http-port",
4848
namespace=namespace_1.name,

tests/network/network_policy/test_network_policy.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def test_network_policy_deny_all_http(
3232
)
3333

3434

35-
@pytest.mark.usefixtures("allow_single_http_port")
3635
@pytest.mark.order(before="test_network_policy_allow_all_http")
3736
@pytest.mark.polarion("CNV-2775")
3837
@pytest.mark.single_nic
@@ -42,14 +41,19 @@ def test_network_policy_allow_single_http_port(
4241
network_policy_vma,
4342
network_policy_vmb,
4443
admin_client,
44+
single_http_port_net_policy,
4545
):
4646
pod_ips = network_policy_vma.vmi.get_virt_launcher_pod(privileged_client=admin_client).instance.status.podIPs
4747
for pod_ip_entry in pod_ips:
4848
dst_ip = pod_ip_entry["ip"]
4949
with subtests.test(msg=f"Testing {dst_ip}"):
5050
run_ssh_commands(
5151
host=network_policy_vmb.ssh_exec,
52-
commands=[shlex.split(format_curl_command(ip_address=dst_ip, port=TEST_PORTS[0], head=True))],
52+
commands=[
53+
shlex.split(
54+
format_curl_command(ip_address=dst_ip, port=single_http_port_net_policy.ports[0], head=True)
55+
)
56+
],
5357
)
5458

5559
with pytest.raises(CommandExecFailed):
@@ -59,7 +63,6 @@ def test_network_policy_allow_single_http_port(
5963
)
6064

6165

62-
@pytest.mark.usefixtures("allow_all_http_ports")
6366
@pytest.mark.polarion("CNV-2774")
6467
@pytest.mark.single_nic
6568
@pytest.mark.s390x
@@ -68,6 +71,7 @@ def test_network_policy_allow_all_http(
6871
network_policy_vma,
6972
network_policy_vmb,
7073
admin_client,
74+
allow_all_http_ports,
7175
):
7276
pod_ips = network_policy_vma.vmi.get_virt_launcher_pod(privileged_client=admin_client).instance.status.podIPs
7377
for pod_ip_entry in pod_ips:
@@ -76,6 +80,7 @@ def test_network_policy_allow_all_http(
7680
run_ssh_commands(
7781
host=network_policy_vmb.ssh_exec,
7882
commands=[
79-
shlex.split(format_curl_command(ip_address=dst_ip, port=port, head=True)) for port in TEST_PORTS
83+
shlex.split(format_curl_command(ip_address=dst_ip, port=port, head=True))
84+
for port in allow_all_http_ports.ports
8085
],
8186
)

0 commit comments

Comments
 (0)