-
Notifications
You must be signed in to change notification settings - Fork 78
net, tests, hot-plug: W/A guest-agent deadlock on hot-plugged interfaces #5584
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
Merged
Merged
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
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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import ipaddress | ||
| import json | ||
| import logging | ||
| from typing import TYPE_CHECKING, Final | ||
|
|
||
| from libs.net.vmspec import IpNotFound | ||
| from libs.vm.vm import BaseVirtualMachine | ||
| from utilities.virt import vm_console_run_commands | ||
|
|
||
| if TYPE_CHECKING: | ||
| from utilities.virt import VirtualMachineForTests | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def read_guest_interface_ipv4( | ||
| vm: VirtualMachineForTests | BaseVirtualMachine, | ||
| interface_name: str, | ||
| expected_ip: ipaddress.IPv4Address | None = None, | ||
| ) -> ipaddress.IPv4Interface: | ||
| """Retrieve the IPv4 address and prefix length of an interface from the VM guest OS. | ||
|
|
||
| Args: | ||
| vm: The virtual machine to query. | ||
| interface_name: The name of the network interface (e.g., "eth0"). | ||
| expected_ip: When provided, the command filters to this specific host address | ||
| using 'ip addr show to <expected_ip>', which returns output only when | ||
| that address is configured on the interface. Useful when the interface | ||
| may carry multiple addresses. | ||
|
|
||
| Returns: | ||
| IPv4 address with prefix length (e.g., 192.168.1.5/24). | ||
|
|
||
| Raises: | ||
| IpNotFound: If no matching IPv4 address is found or console output cannot be parsed. | ||
| """ | ||
| to_filter: Final[str] = f" to {expected_ip}" if expected_ip is not None else "" | ||
| cmd: Final[str] = f"ip -j -4 addr show {interface_name}{to_filter}" | ||
|
|
||
| output = vm_console_run_commands(vm=vm, commands=[cmd], timeout=30) | ||
| LOGGER.info(f"Command {cmd} output: {output[cmd]}") | ||
|
|
||
| try: | ||
| iface_info = json.loads(output[cmd][1]) | ||
| except (IndexError, json.JSONDecodeError) as err: | ||
| raise IpNotFound(f"Failed to parse console JSON from VM {vm.name} for '{cmd}': {output[cmd]}") from err | ||
|
|
||
| if iface_info and "addr_info" in iface_info[0]: | ||
| for addr in iface_info[0]["addr_info"]: | ||
| if addr.get("family") == "inet": | ||
| if expected_ip is None or ipaddress.IPv4Address(addr["local"]) == expected_ip: | ||
| return ipaddress.IPv4Interface(address=f"{addr['local']}/{addr['prefixlen']}") | ||
|
|
||
| raise IpNotFound( | ||
| f"{'No IPv4 address' if expected_ip is None else str(expected_ip)} found on {interface_name} in VM {vm.name}" | ||
| ) | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.