From 6109de51a0084d8452371fcbf415e5c3b4f406fe Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 3 May 2018 18:19:40 +0100 Subject: [PATCH] tests: Ansible SSH timeout test Also change Docker image to new 'mitogen' organization. --- tests/ansible/ansible.cfg | 3 +++ tests/ansible/hosts | 3 +++ tests/ansible/integration/all.yml | 1 + tests/ansible/integration/ssh/all.yml | 1 + tests/ansible/integration/ssh/timeouts.yml | 20 ++++++++++++++++++++ tests/ansible/osx_setup.yml | 10 ++++++++++ tests/build_docker_images.py | 7 ++++++- tests/data/docker/mitogen__slow_user.profile | 3 +++ tests/testlib.py | 2 +- 9 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/ansible/integration/ssh/all.yml create mode 100644 tests/ansible/integration/ssh/timeouts.yml create mode 100644 tests/data/docker/mitogen__slow_user.profile diff --git a/tests/ansible/ansible.cfg b/tests/ansible/ansible.cfg index 0abd2594..f9a6bc0e 100644 --- a/tests/ansible/ansible.cfg +++ b/tests/ansible/ansible.cfg @@ -8,6 +8,9 @@ library = lib/modules retry_files_enabled = False forks = 50 +# Required by integration/ssh/timeouts.yml +timeout = 3 + # On Travis, paramiko check fails due to host key checking enabled. host_key_checking = False diff --git a/tests/ansible/hosts b/tests/ansible/hosts index 45bfb9ef..96216413 100644 --- a/tests/ansible/hosts +++ b/tests/ansible/hosts @@ -2,6 +2,9 @@ [test-targets] localhost +[slow-connect-targets] +slow-localhost ansible_host=localhost ansible_user=mitogen__slow_user ansible_password=slow_user_password + [connection-delegation-test] cd-bastion cd-rack11 mitogen_via=ssh-user@cd-bastion diff --git a/tests/ansible/integration/all.yml b/tests/ansible/integration/all.yml index efb2614d..2d047f43 100644 --- a/tests/ansible/integration/all.yml +++ b/tests/ansible/integration/all.yml @@ -11,3 +11,4 @@ - import_playbook: playbook_semantics/all.yml - import_playbook: remote_tmp/all.yml - import_playbook: runner/all.yml +- import_playbook: ssh/all.yml diff --git a/tests/ansible/integration/ssh/all.yml b/tests/ansible/integration/ssh/all.yml new file mode 100644 index 00000000..8a3b7f88 --- /dev/null +++ b/tests/ansible/integration/ssh/all.yml @@ -0,0 +1 @@ +- import_playbook: timeouts.yml diff --git a/tests/ansible/integration/ssh/timeouts.yml b/tests/ansible/integration/ssh/timeouts.yml new file mode 100644 index 00000000..cf7d1a41 --- /dev/null +++ b/tests/ansible/integration/ssh/timeouts.yml @@ -0,0 +1,20 @@ +# Ensure 'ssh' connections time out correctly. + +- name: integration/ssh/timeouts_wrapper.yml + hosts: test-targets + tasks: + - connection: local + command: ansible slow-connect-targets -m custom_python_detect_environment #debug -a msg="--{{ 69 + 42 }}--" + register: out + ignore_errors: true + when: is_mitogen + + - assert: + that: + - | + '"changed": false' in out.stdout + - | + '"unreachable": true' in out.stdout + - | + '"msg": "Connection timed out."' in out.stdout + when: is_mitogen diff --git a/tests/ansible/osx_setup.yml b/tests/ansible/osx_setup.yml index d06c5fc2..3c53fd8f 100644 --- a/tests/ansible/osx_setup.yml +++ b/tests/ansible/osx_setup.yml @@ -29,6 +29,7 @@ - require_tty - pw_required - require_tty_pw_required + - slow_user when: ansible_system != 'Darwin' - name: Create Mitogen test users @@ -52,6 +53,7 @@ - pw_required - require_tty_pw_required - readonly_homedir + - slow_user when: ansible_system == 'Darwin' - name: Create Mitogen test users @@ -88,6 +90,14 @@ - name: Readonly homedir for one account shell: "chown -R root: ~mitogen__readonly_homedir" + - name: Slow bash profile for one account + copy: + dest: ~mitogen__slow_user/.{{item}} + src: ../data/docker/mitogen__slow_user.profile + with_items: + - bashrc + - profile + - name: Require a TTY for two accounts lineinfile: path: /etc/sudoers diff --git a/tests/build_docker_images.py b/tests/build_docker_images.py index 0915aa46..bef87861 100755 --- a/tests/build_docker_images.py +++ b/tests/build_docker_images.py @@ -47,6 +47,7 @@ RUN \ useradd -s /bin/bash -m mitogen__require_tty && \ useradd -s /bin/bash -m mitogen__require_tty_pw_required && \ useradd -s /bin/bash -m mitogen__readonly_homedir && \ + useradd -s /bin/bash -m mitogen__slow_user && \ chown -R root: ~mitogen__readonly_homedir && \ { for i in `seq 1 21`; do useradd -s /bin/bash -m mitogen__user$i; done; } && \ ( echo 'root:rootpassword' | chpasswd; ) && \ @@ -58,10 +59,14 @@ RUN \ ( echo 'mitogen__require_tty:require_tty_password' | chpasswd; ) && \ ( echo 'mitogen__require_tty_pw_required:require_tty_pw_required_password' | chpasswd; ) && \ ( echo 'mitogen__readonly_homedir:readonly_homedir_password' | chpasswd; ) && \ + ( echo 'mitogen__slow_user:slow_user_password' | chpasswd; ) && \ mkdir ~mitogen__has_sudo_pubkey/.ssh && \ { echo '#!/bin/bash\nexec strace -ff -o /tmp/pywrap$$.trace python2.7 "$@"' > /usr/local/bin/pywrap; chmod +x /usr/local/bin/pywrap; } COPY data/docker/mitogen__has_sudo_pubkey.key.pub /home/mitogen__has_sudo_pubkey/.ssh/authorized_keys +COPY data/docker/mitogen__slow_user.profile /home/mitogen__slow_user/.profile +COPY data/docker/mitogen__slow_user.profile /home/mitogen__slow_user/.bashrc + RUN \ chown -R mitogen__has_sudo_pubkey ~mitogen__has_sudo_pubkey && \ chmod -R go= ~mitogen__has_sudo_pubkey @@ -93,6 +98,6 @@ for (distro, wheel, prefix) in (('debian', 'sudo', DEBIAN_DOCKERFILE), subprocess.check_call(sh('docker build %s -t %s -f %s', mydir, - 'd2mw/mitogen-%s-test' % (distro,), + 'mitogen/%s-test' % (distro,), dockerfile_fp.name )) diff --git a/tests/data/docker/mitogen__slow_user.profile b/tests/data/docker/mitogen__slow_user.profile new file mode 100644 index 00000000..6fd43a14 --- /dev/null +++ b/tests/data/docker/mitogen__slow_user.profile @@ -0,0 +1,3 @@ + +# mitogen__slow_user takes forever to log in. +sleep 10 diff --git a/tests/testlib.py b/tests/testlib.py index 4e01b4ea..0997752d 100644 --- a/tests/testlib.py +++ b/tests/testlib.py @@ -175,7 +175,7 @@ class DockerizedSshDaemon(object): def get_image(self): if not self.image: distro = os.environ.get('MITOGEN_TEST_DISTRO', 'debian') - self.image = 'd2mw/mitogen-%s-test' % (distro,) + self.image = 'mitogen/%s-test' % (distro,) return self.image def __init__(self):