issue #454: fix AttributeError and atexit.yml test.
This commit is contained in:
parent
824c7931a9
commit
3179951f5c
|
@ -357,10 +357,10 @@ class Runner(object):
|
||||||
|
|
||||||
class AtExitWrapper(object):
|
class AtExitWrapper(object):
|
||||||
"""
|
"""
|
||||||
Newer Ansibles use :func:`atexit.register` to trigger tmpdir cleanup when
|
issue #397, #454: Newer Ansibles use :func:`atexit.register` to trigger
|
||||||
AnsibleModule.tmpdir is responsible for creating its own temporary
|
tmpdir cleanup when AnsibleModule.tmpdir is responsible for creating its
|
||||||
directory, however with Mitogen processes are preserved across tasks,
|
own temporary directory, however with Mitogen processes are preserved
|
||||||
meaning cleanup must happen earlier.
|
across tasks, meaning cleanup must happen earlier.
|
||||||
|
|
||||||
Patch :func:`atexit.register`, catching :func:`shutil.rmtree` calls so they
|
Patch :func:`atexit.register`, catching :func:`shutil.rmtree` calls so they
|
||||||
can be executed on task completion, rather than on process shutdown.
|
can be executed on task completion, rather than on process shutdown.
|
||||||
|
@ -401,7 +401,7 @@ class AtExitWrapper(object):
|
||||||
self.deferred.append((func, targs, kwargs))
|
self.deferred.append((func, targs, kwargs))
|
||||||
return
|
return
|
||||||
|
|
||||||
self.original_register(func, *targs, **kwargs)
|
self.original['register'](func, *targs, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ModuleUtilsImporter(object):
|
class ModuleUtilsImporter(object):
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
# issue #397: newer Ansibles rely on atexit to cleanup their temporary
|
# issue #397, #454: newer Ansibles rely on atexit to cleanup their temporary
|
||||||
# directories. Ensure atexit handlers run during runner completion.
|
# directories. Ensure atexit handlers calling shutil.rmtree() run during runner
|
||||||
|
# completion.
|
||||||
|
|
||||||
- name: integration/runner/atexit.yml
|
- name: integration/runner/atexit.yml
|
||||||
hosts: test-targets
|
hosts: test-targets
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
any_errors_fatal: false
|
any_errors_fatal: false
|
||||||
|
vars:
|
||||||
|
path: /tmp/atexit-should-delete-this
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -14,18 +17,15 @@
|
||||||
|
|
||||||
- custom_python_run_script:
|
- custom_python_run_script:
|
||||||
script: |
|
script: |
|
||||||
import atexit
|
import atexit, shutil
|
||||||
atexit.register(lambda:
|
path = '{{path}}'
|
||||||
open('/tmp/atexit-was-triggered', 'w').write('yep'))
|
os.mkdir(path, int('777', 8))
|
||||||
|
atexit.register(shutil.rmtree, path)
|
||||||
|
|
||||||
- slurp:
|
- stat:
|
||||||
path: /tmp/atexit-was-triggered
|
path: "{{path}}"
|
||||||
register: out
|
register: out
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- out.content|b64decode == "yep"
|
- not out.stat.exists
|
||||||
|
|
||||||
- file:
|
|
||||||
path: /tmp/atexit-was-triggered
|
|
||||||
state: absent
|
|
||||||
|
|
Loading…
Reference in New Issue