From ac3db2adb9ca8826d96b222cb22bac74e95c3c49 Mon Sep 17 00:00:00 2001 From: Liam Hopkins Date: Tue, 12 Nov 2019 10:36:11 -0800 Subject: Wait on tentative v6 link-local addrs before DHCP (#861) --- .../google_compute_engine/distro_lib/helpers.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py index a0be6a0..c20b241 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py @@ -17,6 +17,7 @@ import os import subprocess +import time def CallDhclient( @@ -68,6 +69,23 @@ def CallDhclientIpv6(interfaces, logger, dhclient_script=None, interfaces) return + # Check for a 'tentative' IPv6 address which would prevent `dhclient -6` from + # succeeding below. This should only take 1 second, but we try for up to 5. + command = ['ip', '-6', '-o', 'a', 's', 'dev', interfaces[0], 'scope', + 'link', 'tentative'] + for i in range(5): + output = '' + try: + output = subprocess.check_output(command) + except subprocess.CalledProcessError as e: + logger.warning('Could not confirm tentative IPv6 address: %s.', e.output) + if output: + logger.info('Found tentative ipv6 link address %s, sleeping 1 second.', + output.strip()) + time.sleep(1) + else: + break + if dhclient_script and os.path.exists(dhclient_script): dhclient_command += ['-sf', dhclient_script] -- cgit v1.2.1