virtual_network: respect configurable preferred interface state#6814
virtual_network: respect configurable preferred interface state#6814aniket-sahu-ibmx wants to merge 1 commit intoautotest:masterfrom
Conversation
…ancel if unmet What ---- Use a config-driven 'preferred_iface_state' parameter to select network interfaces for virtual_network tests. If no interface exists in the preferred state, cancel the test immediately with a clear message. Why --- This removes non-deterministic fallback mechanisms and external connectivity dependencies, aligning with tp-libvirt guidance to keep tests simple, environment-independent, and to use test.cancel() for unmet host prerequisites. How --- - Read 'preferred_iface_state' from the test params (default: "UP") - Retrieve interfaces only in that state - Cancel the test if none are found - Add logging describing selected interfaces Behavior -------- No change when the host provides an interface in the preferred state. Tests cancel cleanly otherwise, preventing ambiguous downstream failures. Testing ------- - Verified behavior with preferred_iface_state=UP on hosts with/without UP interfaces - Confirmed clear cancellation messages appear - Ran inspekt: inspekt checkall --disable-style E501,E265,W601,E402,E722,E741 --no-license-check Risk ---- Low. New logic only affects the interface selection stage.
WalkthroughThis pull request introduces a configurable Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
🧹 Nitpick comments (2)
libvirt/tests/src/virtual_network/iface_network.py (1)
127-132: Use preferred state in diagnostics for clearer cancellations.At Line 132, cancellation should include the configured state to avoid misleading “active interface” wording when the preferred state is not
UP.Suggested patch
preferred_state = params.get("preferred_iface_state", "UP") net_ifs = utils_net.get_net_if(state=preferred_state) + logging.debug("Host interfaces in preferred state '%s': %s", + preferred_state, net_ifs) # if no interfaces are available in preferred state, # cancel the test if len(net_ifs) == 0: - test.cancel("No active network interface available on host") + test.cancel("No network interface available on host with state '%s'" + % preferred_state)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libvirt/tests/src/virtual_network/iface_network.py` around lines 127 - 132, The cancellation message uses hardcoded "active network interface" text which can be misleading when a different preferred_state is configured; update the test.cancel call (following the utils_net.get_net_if call that sets net_ifs and the preferred_state variable) to include the preferred_state value so the message reflects the requested state (e.g., mention preferred_state in the string passed to test.cancel) and keep using net_ifs length check and test.cancel as before.libvirt/tests/src/virtual_network/iface_options.py (1)
106-111: Make cancel reason state-aware and log matched interfaces.At Line 111, the message says “active” even when
preferred_iface_statemay be different (e.g.,DOWN), which makes troubleshooting harder.Suggested patch
preferred_state = params.get("preferred_iface_state", "UP") net_ifs = utils_net.get_net_if(state=preferred_state) + logging.debug("Host interfaces in preferred state '%s': %s", + preferred_state, net_ifs) # if no interfaces are available in preferred state, # cancel the test if len(net_ifs) == 0: - test.cancel("No active network interface available on host") + test.cancel("No network interface available on host with state '%s'" + % preferred_state)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libvirt/tests/src/virtual_network/iface_options.py` around lines 106 - 111, The cancel message uses a hardcoded "active" phrase; change it to reflect the requested preferred_state and include the matched interfaces from net_ifs for debugging: when preferred_state is read from params via preferred_state and net_ifs is populated by utils_net.get_net_if(state=preferred_state), call test.cancel with a message that mentions the actual preferred_state (e.g., "No network interfaces in state DOWN") and append or log the net_ifs contents (or their names) so the failure shows which interfaces were inspected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@libvirt/tests/src/virtual_network/iface_network.py`:
- Around line 127-132: The cancellation message uses hardcoded "active network
interface" text which can be misleading when a different preferred_state is
configured; update the test.cancel call (following the utils_net.get_net_if call
that sets net_ifs and the preferred_state variable) to include the
preferred_state value so the message reflects the requested state (e.g., mention
preferred_state in the string passed to test.cancel) and keep using net_ifs
length check and test.cancel as before.
In `@libvirt/tests/src/virtual_network/iface_options.py`:
- Around line 106-111: The cancel message uses a hardcoded "active" phrase;
change it to reflect the requested preferred_state and include the matched
interfaces from net_ifs for debugging: when preferred_state is read from params
via preferred_state and net_ifs is populated by
utils_net.get_net_if(state=preferred_state), call test.cancel with a message
that mentions the actual preferred_state (e.g., "No network interfaces in state
DOWN") and append or log the net_ifs contents (or their names) so the failure
shows which interfaces were inspected.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
libvirt/tests/cfg/virtual_network/iface_network.cfglibvirt/tests/cfg/virtual_network/iface_options.cfglibvirt/tests/src/virtual_network/iface_network.pylibvirt/tests/src/virtual_network/iface_options.py
What
Use a config-driven 'preferred_iface_state' parameter to select network interfaces for virtual_network tests. If no interface exists in the preferred state, cancel the test immediately with a clear message.
Why
This removes non-deterministic fallback mechanisms and external connectivity dependencies, aligning with tp-libvirt guidance to keep tests simple, environment-independent, and to use test.cancel() for unmet host prerequisites.
How
Behavior
No change when the host provides an interface in the preferred state. Tests cancel cleanly otherwise, preventing ambiguous downstream failures.
Testing
Risk
Low. New logic only affects the interface selection stage.
Summary by CodeRabbit