commit
252a8c643c
@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Wrap ansible-playbook, setting up some test of the test environment.
|
||||
|
||||
# Used by delegate_to.yml to ensure "sudo -E" preserves environment.
|
||||
export I_WAS_PRESERVED=1
|
||||
export MITOGEN_MAX_INTERPRETERS=3
|
||||
|
||||
if [ "${ANSIBLE_STRATEGY:0:7}" = "mitogen" ]
|
||||
then
|
||||
EXTRA='{"is_mitogen": true}'
|
||||
else
|
||||
EXTRA='{"is_mitogen": false}'
|
||||
fi
|
||||
|
||||
exec ~/src/cpython/venv/bin/ansible-playbook -e "$EXTRA" -e ansible_python_interpreter=/Users/dmw/src/cpython/venv/bin/python2.7 "$@"
|
@ -0,0 +1,9 @@
|
||||
|
||||
# `stub_connections/`
|
||||
|
||||
The playbooks in this directory use stub implementations of various third party
|
||||
tools (kubectl etc.) to verify arguments passed by Ansible to Mitogen and
|
||||
subsequently onward to the tool result in something that looks sane.
|
||||
|
||||
These are bare minimum tests just to ensure sporadically tested connection
|
||||
methods haven't broken in embarrasingly obvious ways.
|
@ -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
|
@ -0,0 +1,5 @@
|
||||
- import_playbook: kubectl.yml
|
||||
- import_playbook: lxc.yml
|
||||
- import_playbook: lxd.yml
|
||||
- import_playbook: setns_lxc.yml
|
||||
- import_playbook: setns_lxd.yml
|
@ -0,0 +1,21 @@
|
||||
|
||||
- name: integration/stub_connections/kubectl.yml
|
||||
hosts: test-targets
|
||||
gather_facts: false
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- meta: end_play
|
||||
when: not is_mitogen
|
||||
|
||||
- meta: end_play
|
||||
when: ansible_version.full < '2.5'
|
||||
|
||||
- custom_python_detect_environment:
|
||||
vars:
|
||||
ansible_connection: kubectl
|
||||
mitogen_kubectl_path: stub-kubectl.py
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- out.env.THIS_IS_STUB_KUBECTL == '1'
|
@ -0,0 +1,18 @@
|
||||
|
||||
- name: integration/stub_connections/lxc.yml
|
||||
hosts: test-targets
|
||||
gather_facts: false
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- meta: end_play
|
||||
when: not is_mitogen
|
||||
|
||||
- custom_python_detect_environment:
|
||||
vars:
|
||||
ansible_connection: lxc
|
||||
mitogen_lxc_attach_path: stub-lxc-attach.py
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- out.env.THIS_IS_STUB_LXC_ATTACH == '1'
|
@ -0,0 +1,18 @@
|
||||
|
||||
- name: integration/stub_connections/lxd.yml
|
||||
hosts: test-targets
|
||||
gather_facts: false
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- meta: end_play
|
||||
when: not is_mitogen
|
||||
|
||||
- custom_python_detect_environment:
|
||||
vars:
|
||||
ansible_connection: lxd
|
||||
mitogen_lxc_path: stub-lxc.py
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- out.env.THIS_IS_STUB_LXC == '1'
|
@ -0,0 +1,31 @@
|
||||
# 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:
|
||||
- meta: end_play
|
||||
when: not is_mitogen
|
||||
|
||||
- include_tasks: _end_play_if_not_sudo_linux.yml
|
||||
|
||||
- command: |
|
||||
sudo -nE ansible
|
||||
-i localhost,
|
||||
-c setns
|
||||
-e mitogen_kind=lxc
|
||||
-e mitogen_lxc_info_path=stub-lxc-info.py
|
||||
-m shell
|
||||
-a "echo hi"
|
||||
localhost
|
||||
args:
|
||||
chdir: ../..
|
||||
warn: false
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that: result.rc == 0
|
@ -0,0 +1,32 @@
|
||||
# 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_lxd.yml
|
||||
hosts: test-targets
|
||||
gather_facts: false
|
||||
any_errors_fatal: false
|
||||
connection: local
|
||||
tasks:
|
||||
- meta: end_play
|
||||
when: not is_mitogen
|
||||
|
||||
- include_tasks: _end_play_if_not_sudo_linux.yml
|
||||
|
||||
- command: |
|
||||
sudo -nE ansible
|
||||
-i localhost,
|
||||
-c setns
|
||||
-e mitogen_kind=lxd
|
||||
-e mitogen_lxc_path=stub-lxc.py
|
||||
-m shell
|
||||
-a "echo hi"
|
||||
localhost
|
||||
args:
|
||||
chdir: ../..
|
||||
warn: false
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that: result.rc == 0
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
export ANSIBLE_STRATEGY=mitogen_linear
|
||||
exec ./run_ansible_playbook.sh "$@"
|
||||
exec ./run_ansible_playbook.py "$@"
|
||||
|
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python
|
||||
# Wrap ansible-playbook, setting up some test of the test environment.
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
GIT_BASEDIR = os.path.dirname(
|
||||
os.path.abspath(
|
||||
os.path.join(__file__, '..', '..')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Used by delegate_to.yml to ensure "sudo -E" preserves environment.
|
||||
os.environ['I_WAS_PRESERVED'] = '1'
|
||||
|
||||
# Used by LRU tests.
|
||||
os.environ['MITOGEN_MAX_INTERPRETERS'] = '3'
|
||||
|
||||
# Add test stubs to path.
|
||||
os.environ['PATH'] = '%s%s%s' % (
|
||||
os.path.join(GIT_BASEDIR, 'tests', 'data', 'stubs'),
|
||||
os.pathsep,
|
||||
os.environ['PATH'],
|
||||
)
|
||||
|
||||
extra = {
|
||||
'is_mitogen': os.environ.get('ANSIBLE_STRATEGY', '').startswith('mitogen'),
|
||||
'git_basedir': GIT_BASEDIR,
|
||||
}
|
||||
|
||||
args = ['ansible-playbook']
|
||||
args += ['-e', json.dumps(extra)]
|
||||
args += sys.argv[1:]
|
||||
os.execvp(args[0], args)
|
@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Wrap ansible-playbook, setting up some test of the test environment.
|
||||
|
||||
# Used by delegate_to.yml to ensure "sudo -E" preserves environment.
|
||||
export I_WAS_PRESERVED=1
|
||||
export MITOGEN_MAX_INTERPRETERS=3
|
||||
|
||||
if [ "${ANSIBLE_STRATEGY:0:7}" = "mitogen" ]
|
||||
then
|
||||
EXTRA='{"is_mitogen": true}'
|
||||
else
|
||||
EXTRA='{"is_mitogen": false}'
|
||||
fi
|
||||
|
||||
exec ansible-playbook -e "$EXTRA" "$@"
|
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python
|
||||
# I produce text every 100ms, for testing mitogen.core.iter_read()
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
i += 1
|
||||
sys.stdout.write(str(i))
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.1)
|
@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
# I produce text every 100ms, for testing mitogen.core.iter_read()
|
||||
|
||||
i=0
|
||||
|
||||
while :; do
|
||||
i=$(($i + 1))
|
||||
echo "$i"
|
||||
sleep 0.1
|
||||
done
|
@ -1,3 +1,7 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/python
|
||||
# I am a Python interpreter that sits idle until the connection times out.
|
||||
exec -a mitogen-tests-python-never-responds.sh sleep 86400
|
||||
|
||||
import time
|
||||
|
||||
while True:
|
||||
time.sleep(86400)
|
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# Mainly for use in stubconnections/kubectl.yml
|
||||
|
||||
print 'PID: 1'
|
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
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['THIS_IS_STUB_LXC'] = '1'
|
||||
os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:])
|
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# I consume 65535 bytes every 10ms, for testing mitogen.core.write_all()
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
while True:
|
||||
os.read(0, 65535)
|
||||
time.sleep(0.01)
|
@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
# I consume 65535 bytes every 10ms, for testing mitogen.core.write_all()
|
||||
|
||||
while :; do
|
||||
read -n 65535
|
||||
sleep 0.01
|
||||
done
|
@ -0,0 +1,29 @@
|
||||
|
||||
import os
|
||||
|
||||
import mitogen
|
||||
import mitogen.parent
|
||||
|
||||
import unittest2
|
||||
|
||||
import testlib
|
||||
|
||||
|
||||
class ConstructorTest(testlib.RouterMixin, testlib.TestCase):
|
||||
kubectl_path = testlib.data_path('stubs/stub-kubectl.py')
|
||||
|
||||
def test_okay(self):
|
||||
context = self.router.kubectl(
|
||||
pod='pod_name',
|
||||
kubectl_path=self.kubectl_path
|
||||
)
|
||||
|
||||
argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV'))
|
||||
self.assertEquals(argv[0], self.kubectl_path)
|
||||
self.assertEquals(argv[1], 'exec')
|
||||
self.assertEquals(argv[2], '-it')
|
||||
self.assertEquals(argv[3], 'pod_name')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
Loading…
Reference in New Issue