Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use Paramiko in tests when needed. #54826

Merged
merged 2 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
# be suitable)
jinja2
PyYAML
paramiko
cryptography
2 changes: 2 additions & 0 deletions test/integration/targets/connection_paramiko_ssh/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
needs/ssh
shippable/posix/group3
needs/target/setup_paramiko
destructive # potentially installs/uninstalls OS packages via setup_paramiko
1 change: 0 additions & 1 deletion test/integration/targets/connection_paramiko_ssh/runme.sh

This file was deleted.

7 changes: 7 additions & 0 deletions test/integration/targets/connection_paramiko_ssh/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -eux

source ../setup_paramiko/setup.sh

./test.sh
1 change: 1 addition & 0 deletions test/integration/targets/connection_paramiko_ssh/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install Paramiko for Python 2 on CentOS 6
yum:
name: python-paramiko
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install Paramiko for Python 2 on FreeBSD 11
pkgng:
name: py27-paramiko
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: Downgrade to pip version 18.1 to work around a PEP 517 virtualenv bug
# pip 19.0.0 added support for PEP 517
# versions as recent as 19.0.3 fail to install paramiko in a virtualenv due to a BackendUnavailable exception
# installation without a virtualenv succeeds
pip:
name: pip==18.1
- name: Install Paramiko for Python 3 on FreeBSD 11
pip: # no py36-paramiko package exists for FreeBSD 11
name: paramiko
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install Paramiko for Python 2 on FreeBSD 12
pkgng:
name: py27-paramiko
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install Paramiko for Python 3 on FreeBSD 12
pkgng:
name: py36-paramiko
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Install Paramiko for Python 3 on RHEL 8
yum:
# src https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_paramiko/python-paramiko-2.4.2-4.el8.src.rpm
name: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_paramiko/python3-ansible_paramiko-2.4.2-4.el8.noarch.rpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install Paramiko for Python 2 on Ubuntu 16
apt:
name: python-paramiko
7 changes: 7 additions & 0 deletions test/integration/targets/setup_paramiko/install-fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Install Paramiko
fail:
msg: "Install of Paramiko on distribution '{{ ansible_distribution }}' with major version '{{ ansible_distribution_major_version }}'
with package manager '{{ ansible_pkg_mgr }}' on Python {{ ansible_python.version.major }} has not been implemented.
Use native OS packages if available, otherwise use pip.
Be sure to uninstall automatically installed dependencies when possible.
Do not implement a generic fallback to pip, as that would allow distributions not yet configured to go undetected."
3 changes: 3 additions & 0 deletions test/integration/targets/setup_paramiko/install-python-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install Paramiko for Python 2
package:
name: python2-paramiko
3 changes: 3 additions & 0 deletions test/integration/targets/setup_paramiko/install-python-3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install Paramiko for Python 3
package:
name: python3-paramiko
16 changes: 16 additions & 0 deletions test/integration/targets/setup_paramiko/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- hosts: localhost
tasks:
- name: Detect Paramiko
detect_paramiko:
register: detect_paramiko
- name: Persist Result
copy:
content: "{{ detect_paramiko }}"
dest: "{{ lookup('env', 'OUTPUT_DIR') }}/detect-paramiko.json"
- name: Install Paramiko
when: not detect_paramiko.found
include_tasks: "{{ item }}"
with_first_found:
- "install-{{ ansible_distribution }}-{{ ansible_distribution_major_version }}-python-{{ ansible_python.version.major }}.yml"
- "install-python-{{ ansible_python.version.major }}.yml"
- "install-fail.yml"
1 change: 1 addition & 0 deletions test/integration/targets/setup_paramiko/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}"
31 changes: 31 additions & 0 deletions test/integration/targets/setup_paramiko/library/detect_paramiko.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python
"""Ansible module to detect the presence of both the normal and Ansible-specific versions of Paramiko."""

from __future__ import absolute_import, division, print_function

__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule

try:
import paramiko
except ImportError:
paramiko = None

try:
import ansible_paramiko
except ImportError:
ansible_paramiko = None


def main():
module = AnsibleModule(argument_spec={})
module.exit_json(**dict(
found=bool(paramiko or ansible_paramiko),
paramiko=bool(paramiko),
ansible_paramiko=bool(ansible_paramiko),
))


if __name__ == '__main__':
main()
8 changes: 8 additions & 0 deletions test/integration/targets/setup_paramiko/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Usage: source ../setup_paramiko/setup.sh

set -eux

source virtualenv.sh # for pip installs, if needed, otherwise unused
ansible-playbook ../setup_paramiko/install.yml -i ../setup_paramiko/inventory "$@"
trap 'ansible-playbook ../setup_paramiko/uninstall.yml -i ../setup_paramiko/inventory "$@"' EXIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko for Python 2 on FreeBSD 11
pkgng:
name: py27-paramiko
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko for Python 3 on FreeBSD 11
pip: # no py36-paramiko package exists for FreeBSD 11
name: paramiko
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko for Python 2 on FreeBSD 12
pkgng:
name: py27-paramiko
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko for Python 3 on FreeBSD 12
pkgng:
name: py36-paramiko
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Uninstall Paramiko for Python 2 using apt
apt:
name: python-paramiko
state: absent
autoremove: yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Uninstall Paramiko for Python 3 using apt
apt:
name: python3-paramiko
state: absent
autoremove: yes
4 changes: 4 additions & 0 deletions test/integration/targets/setup_paramiko/uninstall-dnf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko using dnf history undo
command: dnf history undo last --assumeyes
args:
warn: no
7 changes: 7 additions & 0 deletions test/integration/targets/setup_paramiko/uninstall-fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Uninstall Paramiko
fail:
msg: "Uninstall of Paramiko on distribution '{{ ansible_distribution }}' with major version '{{ ansible_distribution_major_version }}'
with package manager '{{ ansible_pkg_mgr }}' on Python {{ ansible_python.version.major }} has not been implemented.
Use native OS packages if available, otherwise use pip.
Be sure to uninstall automatically installed dependencies when possible.
Do not implement a generic fallback to pip, as that would allow distributions not yet configured to go undetected."
4 changes: 4 additions & 0 deletions test/integration/targets/setup_paramiko/uninstall-yum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko using yum history undo
command: yum history undo last --assumeyes
args:
warn: no
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko for Python 2 using zypper
command: zypper --quiet --non-interactive remove --clean-deps python2-paramiko
args:
warn: no
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Uninstall Paramiko for Python 3 using zypper
command: zypper --quiet --non-interactive remove --clean-deps python3-paramiko
args:
warn: no
18 changes: 18 additions & 0 deletions test/integration/targets/setup_paramiko/uninstall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- hosts: localhost
vars:
detect_paramiko: '{{ lookup("file", lookup("env", "OUTPUT_DIR") + "/detect-paramiko.json") | from_json }}'
tasks:
- name: Uninstall Paramiko and Verify Results
when: not detect_paramiko.found
block:
- name: Uninstall Paramiko
include_tasks: "{{ item }}"
with_first_found:
- "uninstall-{{ ansible_distribution }}-{{ ansible_distribution_major_version }}-python-{{ ansible_python.version.major }}.yml"
- "uninstall-{{ ansible_pkg_mgr }}-python-{{ ansible_python.version.major }}.yml"
- "uninstall-{{ ansible_pkg_mgr }}.yml"
- "uninstall-fail.yml"
- name: Verify Paramiko was uninstalled
detect_paramiko:
register: detect_paramiko
failed_when: detect_paramiko.found
16 changes: 8 additions & 8 deletions test/runner/completion/docker.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
default name=quay.io/ansible/default-test-container:1.6.0 python=3.6,2.6,2.7,3.5,3.7,3.8 python3.8=/usr/local/bin/python3.8 seccomp=unconfined
centos6 name=quay.io/ansible/centos6-test-container:1.4.0 python=2.6 seccomp=unconfined
centos7 name=quay.io/ansible/centos7-test-container:1.4.0 python=2.7 seccomp=unconfined
fedora28 name=quay.io/ansible/fedora28-test-container:1.5.0 python=2.7
fedora29 name=quay.io/ansible/fedora29-test-container:1.5.0 python=3.7
opensuse15py2 name=quay.io/ansible/opensuse15py2-test-container:1.7.0 python=2.7
opensuse15 name=quay.io/ansible/opensuse15-test-container:1.7.0 python=3.6
ubuntu1604 name=quay.io/ansible/ubuntu1604-test-container:1.4.0 python=2.7 seccomp=unconfined
ubuntu1804 name=quay.io/ansible/ubuntu1804-test-container:1.6.0 python=3.6 seccomp=unconfined
centos6 name=quay.io/ansible/centos6-test-container:1.8.0 python=2.6 seccomp=unconfined
centos7 name=quay.io/ansible/centos7-test-container:1.8.0 python=2.7 seccomp=unconfined
fedora28 name=quay.io/ansible/fedora28-test-container:1.8.0 python=2.7
fedora29 name=quay.io/ansible/fedora29-test-container:1.8.0 python=3.7
opensuse15py2 name=quay.io/ansible/opensuse15py2-test-container:1.8.0 python=2.7
opensuse15 name=quay.io/ansible/opensuse15-test-container:1.8.0 python=3.6
ubuntu1604 name=quay.io/ansible/ubuntu1604-test-container:1.8.0 python=2.7 seccomp=unconfined
ubuntu1804 name=quay.io/ansible/ubuntu1804-test-container:1.8.0 python=3.6 seccomp=unconfined
1 change: 0 additions & 1 deletion test/runner/requirements/integration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ cryptography
jinja2
junit-xml
ordereddict ; python_version < '2.7'
paramiko
pyyaml
1 change: 0 additions & 1 deletion test/runner/requirements/sanity.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cryptography
jinja2
mock
paramiko
pycodestyle
pylint ; python_version >= '3.5' # pylint 2.0.0 and later require python 3+
pytest
Expand Down
1 change: 0 additions & 1 deletion test/runner/requirements/windows-integration.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cryptography
jinja2
junit-xml
paramiko
ntlm-auth
requests-ntlm
requests-credssp
Expand Down