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
|
- name: integration/action/make_tmp_path.yml
|
||||||
hosts: test-targets
|
hosts: test-targets
|
||||||
any_errors_fatal: true
|
any_errors_fatal: true
|
||||||
tasks:
|
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
|
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:
|
- name: "Verify temp path changes across connection reset"
|
||||||
# This string must match ansible.cfg::remote_tmp
|
assert:
|
||||||
that: out.result.startswith("{{user_facts.ansible_facts.ansible_user_dir}}/.ansible/mitogen-tests/")
|
that:
|
||||||
|
- tmp_path2.result != tmp_path.result
|
||||||
|
|
||||||
- stat:
|
- name: "Verify old path disappears across connection reset"
|
||||||
path: "{{out.result}}"
|
stat: path={{tmp_path.result}}
|
||||||
register: st
|
register: junk_stat
|
||||||
|
|
||||||
- assert:
|
- name: "Verify old path disappears across connection reset"
|
||||||
that: st.stat.exists and st.stat.isdir and st.stat.mode == "0700"
|
assert:
|
||||||
|
that:
|
||||||
|
- not junk_stat.stat.exists
|
||||||
|
|
||||||
- file:
|
#
|
||||||
path: "{{out.result}}"
|
# root
|
||||||
state: absent
|
#
|
||||||
|
|
||||||
|
- 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
|
# readonly homedir
|
||||||
# user, not the become user.
|
|
||||||
#
|
#
|
||||||
|
|
||||||
- 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
|
method: _make_tmp_path
|
||||||
register: out
|
register: tmp_path
|
||||||
|
|
||||||
|
- name: "Try writing to temp directory for the readonly_homedir user"
|
||||||
become: true
|
become: true
|
||||||
|
become_user: mitogen__readonly_homedir
|
||||||
|
shell: hostname > {{tmp_path.result}}/hostname
|
||||||
|
|
||||||
- assert:
|
#
|
||||||
# This string must match ansible.cfg::remote_tmp
|
# modules get the same temp dir
|
||||||
that: out.result.startswith("{{user_facts.ansible_facts.ansible_user_dir}}/.ansible/mitogen-tests/")
|
#
|
||||||
|
|
||||||
- stat:
|
- name: "Verify modules get the same tmpdir as the action plugin"
|
||||||
path: "{{out.result}}"
|
action_passthrough:
|
||||||
register: st
|
method: _make_tmp_path
|
||||||
|
register: tmp_path
|
||||||
|
|
||||||
- assert:
|
- name: "Verify modules get the same tmpdir as the action plugin"
|
||||||
that: st.stat.exists and st.stat.isdir and st.stat.mode == "0700"
|
custom_python_detect_environment:
|
||||||
|
register: out
|
||||||
|
|
||||||
- file:
|
# v2.6 related: https://github.com/ansible/ansible/pull/39833
|
||||||
path: "{{out.result}}"
|
- name: "Verify modules get the same tmpdir as the action plugin"
|
||||||
state: absent
|
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