File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed
Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/python
2+ # -*- coding: utf-8 -*-
3+
4+ from __future__ import absolute_import , division , print_function
5+ __metaclass__ = type
6+
7+ import atexit
8+ import errno
9+ import os
10+
11+ from ansible .module_utils .basic import AnsibleModule
12+
13+ CLEANUP_FILE = '/tmp/mitogen_test_atexit_cleanup_canary.txt'
14+
15+
16+ def cleanup (file ):
17+ try :
18+ os .unlink (file )
19+ except OSError as exc :
20+ if exc .errno == errno .ENOENT :
21+ pass
22+ raise
23+
24+
25+ def main ():
26+ module = AnsibleModule (
27+ argument_spec = {},
28+ )
29+
30+ atexit .register (cleanup , CLEANUP_FILE )
31+
32+ with open (CLEANUP_FILE , 'wb' ) as f :
33+ f .truncate ()
34+
35+ result = {
36+ 'changed' : True ,
37+ }
38+ module .exit_json (** result )
39+
40+
41+
42+ if __name__ == '__main__' :
43+ main ()
Original file line number Diff line number Diff line change 1919- import_playbook : issue_1066__add_host__host_key_checking.yml
2020- import_playbook : issue_1079__wait_for_connection_timeout.yml
2121- import_playbook : issue_1087__template_streamerror.yml
22+ - import_playbook : issue_1360_atexit_cleanup.yml
Original file line number Diff line number Diff line change 1+ - name : regression/issue_1360_atexit_cleanup.yml
2+ hosts : test-targets
3+ gather_facts : false
4+ become : false
5+ vars :
6+ cleanup_canary_path : /tmp/mitogen_test_atexit_cleanup_canary.txt
7+ tasks :
8+ - block :
9+ - name : Remove lingering cleanup canary
10+ file :
11+ path : " {{ cleanup_canary_path }}"
12+ state : absent
13+
14+ - name : Run module with atexit cleanup
15+ atexit_cleanup :
16+
17+ - name : Trigger exit of remote process
18+ meta : reset_connection
19+
20+ - name : Check presence of cleanup canary
21+ stat :
22+ path : " {{ cleanup_canary_path }}"
23+ register : cleanup_canary_stat
24+
25+ - assert :
26+ that :
27+ - not cleanup_canary_stat.stat.exists
28+ always :
29+ - name : Cleanup
30+ file :
31+ path : " {{ cleanup_canary_path }}"
32+ state : absent
33+ tags :
34+ - issue_1360
You can’t perform that action at this time.
0 commit comments