issue #321: simplify temp directory handling.
parent
2fcea4b199
commit
a2686b1a2c
@ -1,63 +1,115 @@
|
||||
#
|
||||
# Ensure _make_tmp_path returns the same result across invocations for a single
|
||||
# user account, and that the path returned cleans itself up on connection
|
||||
# termination.
|
||||
#
|
||||
# Related bugs prior to the new-style handling:
|
||||
# https://github.com/dw/mitogen/issues/239
|
||||
# https://github.com/dw/mitogen/issues/301
|
||||
|
||||
- name: integration/action/make_tmp_path.yml
|
||||
hosts: test-targets
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- name: "Find out root's homedir."
|
||||
# Runs first because it blats regular Ansible facts with junk, so
|
||||
# non-become run fixes that up.
|
||||
setup: gather_subset=min
|
||||
become: true
|
||||
register: root_facts
|
||||
|
||||
- name: "Find regular homedir"
|
||||
setup: gather_subset=min
|
||||
register: user_facts
|
||||
|
||||
#
|
||||
# non-become
|
||||
# non-root
|
||||
#
|
||||
|
||||
- action_passthrough:
|
||||
- name: "Find regular temp path"
|
||||
action_passthrough:
|
||||
method: _make_tmp_path
|
||||
register: out
|
||||
register: tmp_path
|
||||
|
||||
- name: "Write some junk in regular temp path"
|
||||
shell: hostname > {{tmp_path.result}}/hostname
|
||||
|
||||
- name: "Verify junk did not persist across tasks"
|
||||
stat: path={{tmp_path.result}}/hostname
|
||||
register: junk_stat
|
||||
|
||||
- name: "Verify junk did not persist across tasks"
|
||||
assert:
|
||||
that:
|
||||
- not junk_stat.stat.exists
|
||||
|
||||
- name: "Verify temp path hasn't changed since start"
|
||||
action_passthrough:
|
||||
method: _make_tmp_path
|
||||
register: tmp_path2
|
||||
|
||||
- name: "Verify temp path hasn't changed since start"
|
||||
assert:
|
||||
that:
|
||||
- tmp_path2.result == tmp_path.result
|
||||
|
||||
- name: "Verify temp path changes across connection reset"
|
||||
mitogen_shutdown_all:
|
||||
|
||||
- name: "Verify temp path changes across connection reset"
|
||||
action_passthrough:
|
||||
method: _make_tmp_path
|
||||
register: tmp_path2
|
||||
|
||||
- assert:
|
||||
# This string must match ansible.cfg::remote_tmp
|
||||
that: out.result.startswith("{{user_facts.ansible_facts.ansible_user_dir}}/.ansible/mitogen-tests/")
|
||||
- name: "Verify temp path changes across connection reset"
|
||||
assert:
|
||||
that:
|
||||
- tmp_path2.result != tmp_path.result
|
||||
|
||||
- stat:
|
||||
path: "{{out.result}}"
|
||||
register: st
|
||||
- name: "Verify old path disappears across connection reset"
|
||||
stat: path={{tmp_path.result}}
|
||||
register: junk_stat
|
||||
|
||||
- assert:
|
||||
that: st.stat.exists and st.stat.isdir and st.stat.mode == "0700"
|
||||
- name: "Verify old path disappears across connection reset"
|
||||
assert:
|
||||
that:
|
||||
- not junk_stat.stat.exists
|
||||
|
||||
- file:
|
||||
path: "{{out.result}}"
|
||||
state: absent
|
||||
#
|
||||
# root
|
||||
#
|
||||
|
||||
- name: "Find root temp path"
|
||||
become: true
|
||||
action_passthrough:
|
||||
method: _make_tmp_path
|
||||
register: tmp_path_root
|
||||
|
||||
- name: "Verify root temp path differs from regular path"
|
||||
assert:
|
||||
that:
|
||||
- tmp_path2.result != tmp_path_root.result
|
||||
|
||||
#
|
||||
# become. make_tmp_path() must evaluate HOME in the context of the SSH
|
||||
# user, not the become user.
|
||||
# readonly homedir
|
||||
#
|
||||
|
||||
- action_passthrough:
|
||||
- name: "Try writing to temp directory for the readonly_homedir user"
|
||||
become: true
|
||||
become_user: mitogen__readonly_homedir
|
||||
action_passthrough:
|
||||
method: _make_tmp_path
|
||||
register: out
|
||||
register: tmp_path
|
||||
|
||||
- name: "Try writing to temp directory for the readonly_homedir user"
|
||||
become: true
|
||||
become_user: mitogen__readonly_homedir
|
||||
shell: hostname > {{tmp_path.result}}/hostname
|
||||
|
||||
- assert:
|
||||
# This string must match ansible.cfg::remote_tmp
|
||||
that: out.result.startswith("{{user_facts.ansible_facts.ansible_user_dir}}/.ansible/mitogen-tests/")
|
||||
#
|
||||
# modules get the same temp dir
|
||||
#
|
||||
|
||||
- stat:
|
||||
path: "{{out.result}}"
|
||||
register: st
|
||||
- name: "Verify modules get the same tmpdir as the action plugin"
|
||||
action_passthrough:
|
||||
method: _make_tmp_path
|
||||
register: tmp_path
|
||||
|
||||
- assert:
|
||||
that: st.stat.exists and st.stat.isdir and st.stat.mode == "0700"
|
||||
- name: "Verify modules get the same tmpdir as the action plugin"
|
||||
custom_python_detect_environment:
|
||||
register: out
|
||||
|
||||
- file:
|
||||
path: "{{out.result}}"
|
||||
state: absent
|
||||
# v2.6 related: https://github.com/ansible/ansible/pull/39833
|
||||
- name: "Verify modules get the same tmpdir as the action plugin"
|
||||
assert:
|
||||
that:
|
||||
- out.module_tmpdir == tmp_path.result
|
||||
|
@ -1,2 +0,0 @@
|
||||
|
||||
- import_playbook: readonly_homedir.yml
|
@ -1,20 +0,0 @@
|
||||
# https://github.com/dw/mitogen/issues/239
|
||||
# While remote_tmp is used in the context of the SSH user by action code
|
||||
# running on the controller, Ansiballz ignores it and uses the system default
|
||||
# instead.
|
||||
|
||||
- name: integration/remote_tmp/readonly_homedir.yml
|
||||
hosts: test-targets
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- custom_python_detect_environment:
|
||||
become: true
|
||||
become_user: mitogen__readonly_homedir
|
||||
register: out
|
||||
vars:
|
||||
ansible_become_pass: readonly_homedir_password
|
||||
|
||||
- name: Verify system temp directory was used.
|
||||
assert:
|
||||
that:
|
||||
- out.__file__.startswith("/tmp/ansible_")
|
Loading…
Reference in New Issue