fix(harness): fall back to --source arp for VM IP discovery (no leaseshelper)

wait_for_ip now tries --source lease first then --source arp; both produce
identical output handled by parse_lease_ip. Removes the suid leaseshelper
dependency introduced and backed out in Task 3. New unit test confirms
parse_lease_ip works on --source arp output format.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
sjat 2026-06-19 22:29:35 +02:00
parent 4933186d31
commit dc5cc8933f
2 changed files with 18 additions and 5 deletions

View file

@ -243,13 +243,18 @@ def up(host, name=None, mem_mib=DEFAULT_MEM_MIB, vcpus=DEFAULT_VCPUS):
def wait_for_ip(name, timeout=120): def wait_for_ip(name, timeout=120):
# Try --source lease first (fastest when leaseshelper works), then fall back to
# --source arp (reads the host neighbour/ARP table — no privileged helper needed,
# populated once the VM sends traffic). Both sources produce identical output that
# parse_lease_ip handles, so this removes the leaseshelper/suid dependency.
end = time.time() + timeout end = time.time() + timeout
while time.time() < end: while time.time() < end:
out = sh(["virsh", "domifaddr", name, "--source", "lease"], for source in ("lease", "arp"):
check=False, capture=True).stdout out = sh(["virsh", "domifaddr", name, "--source", source],
ip = parse_lease_ip(out) check=False, capture=True).stdout
if ip: ip = parse_lease_ip(out)
return ip if ip:
return ip
time.sleep(4) time.sleep(4)
raise SystemExit(f"timed out waiting for {name} to get a DHCP lease — " raise SystemExit(f"timed out waiting for {name} to get a DHCP lease — "
"VM left defined; run `integration-vm prune` to remove it") "VM left defined; run `integration-vm prune` to remove it")

View file

@ -32,6 +32,14 @@ def test_parse_lease_ip_extracts_ipv4():
def test_parse_lease_ip_none_when_absent(): def test_parse_lease_ip_none_when_absent():
assert ivm.parse_lease_ip("no leases\n") is None assert ivm.parse_lease_ip("no leases\n") is None
def test_parse_lease_ip_arp_source():
# virsh domifaddr --source arp output format is identical to --source lease;
# this test proves parse_lease_ip handles it so the arp fallback in wait_for_ip works.
out = (" Name MAC address Protocol Address\n"
"-------------------------------------------------------------------\n"
" vnet0 52:54:00:de:ad:be ipv4 192.168.150.73/24\n")
assert ivm.parse_lease_ip(out) == "192.168.150.73"
def test_meta_data_has_instance_and_hostname(): def test_meta_data_has_instance_and_hostname():
md = ivm.render_meta_data("iid-askari-x", "boma-it-askari-x") md = ivm.render_meta_data("iid-askari-x", "boma-it-askari-x")