net, network policy: Use fixtures' ports#4051
Conversation
Small follow-up requested change. Use the ports provided by the fixtures instead of the ports constant to improve test readability and clearly distinguish between allowed and disallowed ports. Signed-off-by: Asia Khromov <azhivovk@redhat.com>
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
📝 WalkthroughWalkthroughThe change refactors fixture usage in network policy tests by converting decorator-based fixture injection to parameter-based injection, enabling tests to use fixture-provided port lists instead of a hardcoded constant. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/network/network_policy/test_network_policy.py (1)
42-59: 🧹 Nitpick | 🔵 TrivialMEDIUM: Derive the denied port from the fixture allow-list, not a fixed index
Line 51 correctly switched the allowed probe to fixture data, but Line 58 still hardcodes
TEST_PORTS[1]. If the fixture’s allowed set changes, this can drift from the test intent. Compute a blocked port as “not inallow_single_http_port.ports”.Suggested refactor
def test_network_policy_allow_single_http_port( subtests, network_policy_vma, network_policy_vmb, allow_single_http_port, ): + allowed_port = allow_single_http_port.ports[0] + blocked_port = next( + candidate_port for candidate_port in TEST_PORTS if candidate_port not in allow_single_http_port.ports + ) pod_ips = network_policy_vma.vmi.virt_launcher_pod.instance.status.podIPs for pod_ip_entry in pod_ips: dst_ip = pod_ip_entry["ip"] with subtests.test(msg=f"Testing {dst_ip}"): run_ssh_commands( host=network_policy_vmb.ssh_exec, commands=[ - shlex.split(format_curl_command(ip_address=dst_ip, port=allow_single_http_port.ports[0], head=True)) + shlex.split(format_curl_command(ip_address=dst_ip, port=allowed_port, head=True)) ], ) with pytest.raises(CommandExecFailed): run_ssh_commands( host=network_policy_vmb.ssh_exec, - commands=[shlex.split(format_curl_command(ip_address=dst_ip, port=TEST_PORTS[1], head=True))], + commands=[shlex.split(format_curl_command(ip_address=dst_ip, port=blocked_port, head=True))], )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/network/network_policy/test_network_policy.py` around lines 42 - 59, The test still hardcodes a denied port via TEST_PORTS[1]; change it to derive a blocked port from the allow-list fixture instead: compute a port_not_allowed by selecting any port from TEST_PORTS (or another test-port source) that is not in allow_single_http_port.ports, then use that port in the second run_ssh_commands call; update references in the loop where pod_ips, network_policy_vma.vmi.virt_launcher_pod.instance.status.podIPs, run_ssh_commands, and format_curl_command are used so the denied-port assertion uses the computed port_not_allowed rather than TEST_PORTS[1].
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/network/network_policy/test_network_policy.py`:
- Around line 42-59: The test still hardcodes a denied port via TEST_PORTS[1];
change it to derive a blocked port from the allow-list fixture instead: compute
a port_not_allowed by selecting any port from TEST_PORTS (or another test-port
source) that is not in allow_single_http_port.ports, then use that port in the
second run_ssh_commands call; update references in the loop where pod_ips,
network_policy_vma.vmi.virt_launcher_pod.instance.status.podIPs,
run_ssh_commands, and format_curl_command are used so the denied-port assertion
uses the computed port_not_allowed rather than TEST_PORTS[1].
|
/verified Verified on BM with cnv-4.22: |
Test execution plan request detailsCRITICAL: You MUST post an inline review comment on the first changed line of the first file. As an expert software testing engineer, analyze all modified files in this PR and create a targeted test execution plan. Analysis Requirements:
Your deliverable: Test Execution Plan
Guidelines:
Hardware-Related Checks (SR-IOV, GPU, DPDK): When PR modifies fixtures for hardware-specific resources:
CRITICAL WORKFLOW COMPLETION RULES: When responding to this test execution plan request, you MUST follow these rules EXACTLY:
ABSOLUTE PROHIBITIONS (violating these creates empty/meaningless reviews):
Remember: The pull request review is visible to users. Additional comments are redundant noise. CRITICAL: Before setting "Run smoke tests: True", you MUST use shell scripts to: |
|
|
||
|
|
||
| @pytest.mark.usefixtures("allow_single_http_port") | ||
| @pytest.mark.order(before="test_network_policy_allow_all_http") |
There was a problem hiding this comment.
Test Execution Plan
Run smoke tests: False
Rationale:
- No smoke tests exist in the network_policy module
- Changes are purely refactoring: replacing TEST_PORTS constant usage with fixture-provided ports
- Fixtures (allow_single_http_port, allow_all_http_ports) are function-scoped and local to network_policy tests
- No smoke test dependencies traced to these fixtures
Tests to Execute:
tests/network/network_policy/test_network_policy.py
Verification Focus:
- test_network_policy_allow_single_http_port: Verify fixture parameter usage (allow_single_http_port.ports[0])
- test_network_policy_allow_all_http: Verify iteration over allow_all_http_ports.ports
- test_network_policy_deny_all_http: Verify removal of usefixtures decorator doesn't break test
Notes:
- User has already verified: 3 passed on BM with cnv-4.22
- Pure refactoring change improves readability by using fixture-provided ports instead of hardcoded constants
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 5957 🏁 Script executed: Length of output: 3712 🧠 Learnings used |
Small follow-up requested change https://github.com/RedHatQE/openshift-virtualization-tests/pull/3588/changes#r2753623060
Use the ports provided by the fixtures instead
of the ports constant to improve test readability
and clearly distinguish between allowed and
disallowed ports.
Summary by CodeRabbit
Release Notes