summaryrefslogtreecommitdiff
path: root/cloudinit/temp_utils.py
diff options
context:
space:
mode:
authorJason Zions <jasonzio@microsoft.com>2019-01-15 21:37:17 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-01-15 21:37:17 +0000
commitfdadcb5fae51f4e6799314ab98e3aec56c79b17c (patch)
tree318df8c54326032f8be340633b1642c642b202be /cloudinit/temp_utils.py
parentf19dc8fa62d4fd8de33311c3c75c5b6da440bebe (diff)
downloadcloud-init-git-fdadcb5fae51f4e6799314ab98e3aec56c79b17c.tar.gz
net: Wait for dhclient to daemonize before reading lease file
cloud-init uses dhclient to fetch the DHCP lease so it can extract DHCP options. dhclient creates the leasefile, then writes to it; simply waiting for the leasefile to appear creates a race between dhclient and cloud-init. Instead, wait for dhclient to be parented by init. At that point, we know it has written to the leasefile, so it's safe to copy the file and kill the process. cloud-init creates a temporary directory in which to execute dhclient, and deletes that directory after it has killed the process. If cloud-init abandons waiting for dhclient to daemonize, it will still attempt to delete the temporary directory, but will not report an exception should that attempt fail. LP: #1794399
Diffstat (limited to 'cloudinit/temp_utils.py')
-rw-r--r--cloudinit/temp_utils.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/cloudinit/temp_utils.py b/cloudinit/temp_utils.py
index c98a1b53..346276ec 100644
--- a/cloudinit/temp_utils.py
+++ b/cloudinit/temp_utils.py
@@ -81,7 +81,7 @@ def ExtendedTemporaryFile(**kwargs):
@contextlib.contextmanager
-def tempdir(**kwargs):
+def tempdir(rmtree_ignore_errors=False, **kwargs):
# This seems like it was only added in python 3.2
# Make it since its useful...
# See: http://bugs.python.org/file12970/tempdir.patch
@@ -89,7 +89,7 @@ def tempdir(**kwargs):
try:
yield tdir
finally:
- shutil.rmtree(tdir)
+ shutil.rmtree(tdir, ignore_errors=rmtree_ignore_errors)
def mkdtemp(**kwargs):