Skip to content

virtual_network: respect configurable preferred interface state#6814

Open
aniket-sahu-ibmx wants to merge 1 commit intoautotest:masterfrom
aniket-sahu-ibmx:fix-unknowninterface-nuclear-option
Open

virtual_network: respect configurable preferred interface state#6814
aniket-sahu-ibmx wants to merge 1 commit intoautotest:masterfrom
aniket-sahu-ibmx:fix-unknowninterface-nuclear-option

Conversation

@aniket-sahu-ibmx
Copy link

@aniket-sahu-ibmx aniket-sahu-ibmx commented Mar 2, 2026

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.

Summary by CodeRabbit

  • Chores
    • Enhanced test infrastructure by introducing configurable network interface state preferences. Tests now support flexible interface state specification across configurations while maintaining backward compatibility. Tests gracefully skip if the specified interface state is unavailable on the system.

…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.
@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

Walkthrough

This pull request introduces a configurable preferred_iface_state parameter for network interface testing. Two configuration files add a default "UP" parameter value. Two corresponding Python test modules are updated to replace hardcoded "UP" state references with the configurable parameter, defaulting to "UP" for backward compatibility. Both Python files add validation that cancels tests if no interfaces are found in the preferred state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: making the preferred interface state configurable instead of hard-coded.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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_state may 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6855b50 and 0ef9c02.

📒 Files selected for processing (4)
  • libvirt/tests/cfg/virtual_network/iface_network.cfg
  • libvirt/tests/cfg/virtual_network/iface_options.cfg
  • libvirt/tests/src/virtual_network/iface_network.py
  • libvirt/tests/src/virtual_network/iface_options.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant