Skip to content

Commit

Permalink
test(hotplug): fix race getting ipv6 (#5271)
Browse files Browse the repository at this point in the history
Add retry logic for _get_ip_addr to properly get the ipv6 address.

The  output of `ip --brief addr` can show
ens6 UP 192.168.13.34/20 metric 200 fe80::8fd:afff:fea3:f4ad/64
instead of
ens6 UP 192.168.13.34/20 metric 200 2a05:d012:ea0:c500:1373:45f4:aa83:517c/128 fe80::8fd:afff:fea3:f4ad/64
if executed so early that the kernel didn't expose the wanted ipv6
address.
  • Loading branch information
aciba90 authored Jun 4, 2024
1 parent e843f6a commit 7e4d293
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/integration_tests/modules/test_hotplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ def _wait_till_hotplug_complete(client, expected_runs=1):
raise Exception("Waiting for hotplug handler failed")


def _get_ip_addr(client):
def _get_ip_addr(client, *, _retries: int = 0):
ips = []
lines = client.execute("ip --brief addr").split("\n")
for line in lines:
attributes = line.split()
interface, state = attributes[0], attributes[1]
ip4_cidr = attributes[2] if len(attributes) > 2 else None

# Retry to wait for ipv6_cidr:
# ens6 UP <ipv4_cidr> metric 200 <ipv6_cidr> <ipv6_cidr scope link>
if len(attributes) == 6 and _retries < 3:
time.sleep(1)
return _get_ip_addr(client, _retries=_retries + 1)

# The output of `ip --brief addr` can contain metric info:
# ens5 UP <ipv4_cidr> metric 100 <ipv6_cidr> ...
ip6_cidr = None
Expand Down

0 comments on commit 7e4d293

Please sign in to comment.