issue #409: add stub LXC test, refactor playbooks.

issue260
David Wilson 6 years ago
parent e832ddec13
commit 0e8f451190

@ -0,0 +1,17 @@
# End the play if we're not on Linux and a raw 'sudo' command isn't available.
# Expects connection:local
- shell: uname -s
register: out
- meta: end_play
when: out.stdout != 'Linux'
- command: sudo -n whoami
args:
warn: false
ignore_errors: true
register: sudo_available
- meta: end_play
when: sudo_available.rc != 0

@ -1,2 +1,3 @@
- import_playbook: kubectl.yml - import_playbook: kubectl.yml
- import_playbook: setns_lxc.yml - import_playbook: setns_lxc.yml
- import_playbook: setns_lxd.yml

@ -4,6 +4,9 @@
gather_facts: false gather_facts: false
any_errors_fatal: true any_errors_fatal: true
tasks: tasks:
- meta: end_play
when: ansible_version.full < '2.5'
- custom_python_detect_environment: - custom_python_detect_environment:
vars: vars:
ansible_connection: kubectl ansible_connection: kubectl

@ -1,4 +1,3 @@
# issue #409. # issue #409.
# setns is hard -- it wants to do superuser syscalls, so we must run it in a # setns is hard -- it wants to do superuser syscalls, so we must run it in a
# child Ansible via sudo. But that only works if sudo works. # child Ansible via sudo. But that only works if sudo works.
@ -9,17 +8,7 @@
any_errors_fatal: false any_errors_fatal: false
connection: local connection: local
tasks: tasks:
- setup: - include_tasks: _end_play_if_not_sudo_linux.yml
register: out
- debug: msg={{out}}
- command: sudo -n whoami
args:
warn: false
ignore_errors: true
register: sudo_available
when: out.ansible_facts.ansible_system == 'Linux'
- command: | - command: |
sudo -nE ansible sudo -nE ansible
@ -39,8 +28,4 @@
register: result register: result
- assert: - assert:
that: | that: result.rc == 0
(out.ansible_facts.ansible_system != 'Linux') or
(sudo_available != 0) or
(result.rc == 0)

@ -0,0 +1,29 @@
# issue #409.
# setns is hard -- it wants to do superuser syscalls, so we must run it in a
# child Ansible via sudo. But that only works if sudo works.
- name: integration/stub_connections/setns_lxc.yml
hosts: test-targets
gather_facts: false
any_errors_fatal: false
connection: local
tasks:
- include_tasks: _end_play_if_not_sudo_linux.yml
- command: |
sudo -nE ansible
-i localhost,
-c setns
-e mitogen_kind=lxd
-e mitogen_lxc_info_path=stub-lxc.py
-m shell
-a "echo hi"
localhost
args:
chdir: ../..
warn: false
register: result
- assert:
that: result.rc == 0

@ -3,5 +3,10 @@
import sys import sys
import os import os
# setns.py fetching leader PID.
if sys.argv[1] == 'info':
print 'Pid: 1'
sys.exit(0)
os.environ['ORIGINAL_ARGV'] = repr(sys.argv) os.environ['ORIGINAL_ARGV'] = repr(sys.argv)
os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:]) os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:])

Loading…
Cancel
Save