-
Notifications
You must be signed in to change notification settings - Fork 69
Enhance wait_for_vm_interfaces to detect and log missing interfaces #4113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
geetikakay
wants to merge
1
commit into
RedHatQE:main
Choose a base branch
from
geetikakay:interface_checks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,12 +138,23 @@ def wait_for_vm_interfaces(vmi: VirtualMachineInstance, timeout: int = TIMEOUT_1 | |
| timeout=timeout, | ||
| ) | ||
| LOGGER.info(f"Wait for {vmi.name} network interfaces") | ||
| expected_names = { | ||
| iface.name for iface in vmi.instance.spec.domain.devices.interfaces if iface.get("state") != "absent" | ||
| } | ||
| sampler = TimeoutSampler(wait_timeout=timeout, sleep=1, func=lambda: vmi.instance) | ||
| for sample in sampler: | ||
| interfaces = sample.get("status", {}).get("interfaces", []) | ||
| active_interfaces = [interface for interface in interfaces if interface.get("interfaceName")] | ||
| if len(active_interfaces) == len(interfaces): | ||
| return True | ||
| reported_names = set() | ||
| try: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| for sample in sampler: | ||
| interfaces = sample.get("status", {}).get("interfaces", []) | ||
| reported_names = {iface.get("name") for iface in interfaces if iface.get("name")} | ||
| if reported_names == expected_names and all(iface.get("interfaceName") for iface in interfaces): | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return True | ||
|
geetikakay marked this conversation as resolved.
|
||
| except TimeoutExpiredError: | ||
| LOGGER.error( | ||
| f"VMI {vmi.name}: expected interfaces: {expected_names}, reported: {reported_names}. " | ||
| f"Missing (not reported by guest agent): {expected_names - reported_names}." | ||
|
geetikakay marked this conversation as resolved.
|
||
| ) | ||
| raise | ||
| return False | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you ever seen the different in number of interfaces between
vmi.instance.spec.domain.devices.interfacesand .status.interfaces`?wrapping to
try/exceptand print clear error message is a good initiative, but may be it would be enough to keep old logic and printinterfacesandactive_interfacesUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have done these tests with this PR:
scenario 4 tracks it,, missing interface.. old logic would silently pass it.
by comparing reported_names == expected_names we now detecting when a spec interface doesn't show up in status and report
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scenario 4 is interesting, but the guest-agent output already checked by
if interface.get("interfaceName")]We have observed some flaky issue with guest-agent interfaces after migration, and it was caught by existing automation:
and in collected VMI status we don't have guest-agent as a infoSource and don't have "interfaceName":
I agree - adding something meaninfgul like echo
interfacesandactive_interfacesto error message can be very useful, but may be the existing logic works fine and you are hunting for the same flaky issue..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at https://github.com/kubevirt/kubevirt/blob/main/tests/libnet/hotplug.go#L51-L54 and for dynamic changes it looked for vmi.spec.
this code change introduces similar spec comparison approach as VerifyDynamicInterfaceChange which will make checks more reliable.from the testing i did this change behaves as expected in all scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against of updating logic, just trying to understand if we really need it and how safe is it.
You are updating the global function which is used in almost all tests in the repo.
However, from my understanding, we can get
absentstate only when we hot-unplug the interface. If we have any "absent" interface in all other regular scenarios it would sound as a bug which your changes potentially could hide.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dshchedr thanks for reviewing this, I really appreciate it. These are very valid questions and I agree we should be thoughtful about the impact since this helper is used across many scenarios. It makes sense to have clear discussion around the behavior change
I looked in code about state: absent ,based on upstream code validation check it can happen only on non default interfaces and never on default interface. admission webhooks checks and rejects for default.
there is a test coverage in that area as well .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharing the links I came across while digging into this concept in case they are useful for discussion and can be referred later if needed