From 1b17aa1d1a02346b35cdd69acc7d41e6306ebdbb Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 23 Oct 2018 14:42:44 +0100 Subject: [PATCH] ansible: fix temp cleanup regression and add test; closes #397. --- ansible_mitogen/mixins.py | 5 ++- tests/ansible/integration/action/all.yml | 1 + .../integration/action/remove_tmp_path.yml | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/ansible/integration/action/remove_tmp_path.yml diff --git a/ansible_mitogen/mixins.py b/ansible_mitogen/mixins.py index d4fcbd0d..4c06063b 100644 --- a/ansible_mitogen/mixins.py +++ b/ansible_mitogen/mixins.py @@ -190,7 +190,10 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase): """ # The actual removal is pipelined by Connection.close(). LOG.debug('_remove_tmp_path(%r)', tmp_path) - self._connection._shell.tmpdir = None + # Upstream _remove_tmp_path resets shell.tmpdir here, however + # connection.py uses that as the sole location of the temporary + # directory, if one exists. + # self._connection._shell.tmpdir = None def _transfer_data(self, remote_path, data): """ diff --git a/tests/ansible/integration/action/all.yml b/tests/ansible/integration/action/all.yml index 75f77243..018973a9 100644 --- a/tests/ansible/integration/action/all.yml +++ b/tests/ansible/integration/action/all.yml @@ -4,5 +4,6 @@ - import_playbook: make_tmp_path.yml - import_playbook: remote_expand_user.yml - import_playbook: remote_file_exists.yml +- import_playbook: remove_tmp_path.yml - import_playbook: synchronize.yml - import_playbook: transfer_data.yml diff --git a/tests/ansible/integration/action/remove_tmp_path.yml b/tests/ansible/integration/action/remove_tmp_path.yml new file mode 100644 index 00000000..566e4f3f --- /dev/null +++ b/tests/ansible/integration/action/remove_tmp_path.yml @@ -0,0 +1,40 @@ +# +# Ensure _remove_tmp_path cleans up the temporary path. +# +# +- name: integration/action/remove_tmp_path.yml + hosts: test-targets + any_errors_fatal: true + tasks: + - meta: end_play + when: not is_mitogen + + # + # Use the copy module to cause a temporary directory to be created, and + # return a result with a 'src' attribute pointing into that directory. + # + + - copy: + dest: /tmp/remove_tmp_path_test + content: "{{ 123123 | random }}" + register: out + + - stat: + path: "{{out.src}}" + register: out2 + + - assert: + that: + - not out2.stat.exists + + - stat: + path: "{{out.src|dirname}}" + register: out2 + + - assert: + that: + - not out2.stat.exists + + - file: + path: /tmp/remove_tmp_path_test + state: absent