ansible: don't randomly fail due to temp directory cleanup.

Happens about 1 time in 3 when async task times out.
This commit is contained in:
David Wilson 2018-06-10 15:25:11 +01:00
parent fbb67e837e
commit 45b748833d
1 changed files with 16 additions and 1 deletions

View File

@ -38,6 +38,7 @@ how to build arguments for it, preseed related data, etc.
from __future__ import absolute_import
import cStringIO
import ctypes
import errno
import imp
import json
import logging
@ -148,7 +149,7 @@ class Runner(object):
implementation simply restores the original environment.
"""
self._env.revert()
self._cleanup_temp()
self._try_cleanup_temp()
def _cleanup_temp(self):
"""
@ -162,6 +163,20 @@ class Runner(object):
LOG.debug('Deleting %r', path)
ansible_mitogen.target.prune_tree(path)
def _try_cleanup_temp(self):
"""
During broker shutdown triggered by async task timeout or loss of
connection to the parent, it is possible for prune_tree() in
target.py::_on_broker_shutdown() to run before _cleanup_temp(), so skip
cleanup if the directory or a file disappears from beneath us.
"""
try:
self._cleanup_temp()
except (IOError, OSError) as e:
if e.args[0] == errno.ENOENT:
return
raise
def _run(self):
"""
The _run() method is expected to return a dictionary in the form of