issue #454: fix AttributeError and atexit.yml test.

issue510
David Wilson 6 years ago
parent 824c7931a9
commit 3179951f5c

@ -357,10 +357,10 @@ class Runner(object):
class AtExitWrapper(object):
"""
Newer Ansibles use :func:`atexit.register` to trigger tmpdir cleanup when
AnsibleModule.tmpdir is responsible for creating its own temporary
directory, however with Mitogen processes are preserved across tasks,
meaning cleanup must happen earlier.
issue #397, #454: Newer Ansibles use :func:`atexit.register` to trigger
tmpdir cleanup when AnsibleModule.tmpdir is responsible for creating its
own temporary directory, however with Mitogen processes are preserved
across tasks, meaning cleanup must happen earlier.
Patch :func:`atexit.register`, catching :func:`shutil.rmtree` calls so they
can be executed on task completion, rather than on process shutdown.
@ -401,7 +401,7 @@ class AtExitWrapper(object):
self.deferred.append((func, targs, kwargs))
return
self.original_register(func, *targs, **kwargs)
self.original['register'](func, *targs, **kwargs)
class ModuleUtilsImporter(object):

@ -1,10 +1,13 @@
# issue #397: newer Ansibles rely on atexit to cleanup their temporary
# directories. Ensure atexit handlers run during runner completion.
# issue #397, #454: newer Ansibles rely on atexit to cleanup their temporary
# directories. Ensure atexit handlers calling shutil.rmtree() run during runner
# completion.
- name: integration/runner/atexit.yml
hosts: test-targets
gather_facts: false
any_errors_fatal: false
vars:
path: /tmp/atexit-should-delete-this
tasks:
#
@ -14,18 +17,15 @@
- custom_python_run_script:
script: |
import atexit
atexit.register(lambda:
open('/tmp/atexit-was-triggered', 'w').write('yep'))
import atexit, shutil
path = '{{path}}'
os.mkdir(path, int('777', 8))
atexit.register(shutil.rmtree, path)
- slurp:
path: /tmp/atexit-was-triggered
- stat:
path: "{{path}}"
register: out
- assert:
that:
- out.content|b64decode == "yep"
- file:
path: /tmp/atexit-was-triggered
state: absent
- not out.stat.exists

Loading…
Cancel
Save