From 7acc9e68fafbbd7c56587aebe752ba6ba8c8a3db Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Thu, 30 Nov 2017 13:09:30 -0700 Subject: ec2: Fix sandboxed dhclient background process cleanup. There is a race condition where our sandboxed dhclient properly writes a lease file but has not yet written a pid file. If the sandbox temporary directory is torn down before the dhclient subprocess writes a pidfile DataSourceEc2Local gets a traceback and the instance will fallback to DataSourceEc2 in the init-network stage. This wastes boot cycles we'd rather not spend. Fix handling of sandboxed dhclient to wait for both pidfile and leasefile before proceding. If either file doesn't show in 5 seconds, log a warning and return empty lease results {}. LP: #1735331 --- cloudinit/util.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'cloudinit/util.py') diff --git a/cloudinit/util.py b/cloudinit/util.py index e1290aa8..6c014ba5 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -2541,4 +2541,26 @@ def load_shell_content(content, add_empty=False, empty_val=None): return data +def wait_for_files(flist, maxwait, naplen=.5, log_pre=""): + need = set(flist) + waited = 0 + while True: + need -= set([f for f in need if os.path.exists(f)]) + if len(need) == 0: + LOG.debug("%sAll files appeared after %s seconds: %s", + log_pre, waited, flist) + return [] + if waited == 0: + LOG.debug("%sWaiting up to %s seconds for the following files: %s", + log_pre, maxwait, flist) + if waited + naplen > maxwait: + break + time.sleep(naplen) + waited += naplen + + LOG.debug("%sStill missing files after %s seconds: %s", + log_pre, maxwait, need) + return need + + # vi: ts=4 expandtab -- cgit v1.2.3