From 99e1299f80ca43e8c69f0adaef6067ca77a65c71 Mon Sep 17 00:00:00 2001 From: Yossi Segev Date: Sun, 9 Aug 2026 13:31:07 +0300 Subject: [PATCH] net, tests, hot-plug: W/A guest-agent deadlock on hot-plugged interfaces (#5584) CNV-77961 causes guest-agent to stop reporting newly hot-plugged interfaces, failing tests that depend on interface data from VMI status. This changes works around the partial VMI status report by validating the interface from the guest console, so tests continue to run until the issue is fixed. This flow is valid because it reflects user's behavior - users (and their tools) don't necessarily inspect the openshift resources (VMI status) for checking guest components, but rather might do that directly via the guest. As part of this change, functionality from another package (user_defined_network/ip_specification) was re-used, therefore this package is handled here as well, including a race fix by explicitly checking the interfaces are available. Originally composed by: Anat Wax Assisted-by: Claude Assisted-by: Yossi Segev CNV-77961 https://redhat.atlassian.net/browse/CNV-88390 - **Bug Fixes** - Improved discovery of hot-plugged network interfaces when guest-agent information is unavailable. - Added console-based fallback for verifying secondary IPv4 addresses. - Added retries and clearer error handling when interfaces or addresses cannot be found. - Improved detection of malformed network information and mismatched IPv4 addresses. - **Refactor** - Consolidated guest IPv4 address detection into a shared networking utility. - Updated network validation tests to use the shared behavior. Co-authored-by: Anat Wax Signed-off-by: Yossi Segev --- tests/network/libs/guest.py | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/network/libs/guest.py diff --git a/tests/network/libs/guest.py b/tests/network/libs/guest.py new file mode 100644 index 0000000000..bbce0bfa1e --- /dev/null +++ b/tests/network/libs/guest.py @@ -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 + +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 ', 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}" + )