mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Only use Paramiko in tests when needed. (#54826)
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
needs/ssh
|
||||
shippable/posix/group3
|
||||
needs/target/setup_paramiko
|
||||
destructive # potentially installs/uninstalls OS packages via setup_paramiko
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../connection_posix/test.sh
|
||||
7
test/integration/targets/connection_paramiko_ssh/runme.sh
Executable file
7
test/integration/targets/connection_paramiko_ssh/runme.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
source ../setup_paramiko/setup.sh
|
||||
|
||||
./test.sh
|
||||
1
test/integration/targets/connection_paramiko_ssh/test.sh
Symbolic link
1
test/integration/targets/connection_paramiko_ssh/test.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../connection_posix/test.sh
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Install Paramiko for Python 2 on CentOS 6
|
||||
yum:
|
||||
name: python-paramiko
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Install Paramiko for Python 2 on FreeBSD 11
|
||||
pkgng:
|
||||
name: py27-paramiko
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Install Paramiko for Python 2 on FreeBSD 12
|
||||
pkgng:
|
||||
name: py27-paramiko
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Install Paramiko for Python 3 on FreeBSD 12
|
||||
pkgng:
|
||||
name: py36-paramiko
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Install Paramiko for Python 2 on Ubuntu 16
|
||||
apt:
|
||||
name: python-paramiko
|
||||
7
test/integration/targets/setup_paramiko/install-fail.yml
Normal file
7
test/integration/targets/setup_paramiko/install-fail.yml
Normal file
@@ -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."
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Install Paramiko for Python 2
|
||||
package:
|
||||
name: python2-paramiko
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Install Paramiko for Python 3
|
||||
package:
|
||||
name: python3-paramiko
|
||||
16
test/integration/targets/setup_paramiko/install.yml
Normal file
16
test/integration/targets/setup_paramiko/install.yml
Normal file
@@ -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
test/integration/targets/setup_paramiko/inventory
Normal file
1
test/integration/targets/setup_paramiko/inventory
Normal file
@@ -0,0 +1 @@
|
||||
localhost ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}"
|
||||
@@ -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
test/integration/targets/setup_paramiko/setup.sh
Normal file
8
test/integration/targets/setup_paramiko/setup.sh
Normal file
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
- name: Uninstall Paramiko for Python 2 on FreeBSD 11
|
||||
pkgng:
|
||||
name: py27-paramiko
|
||||
state: absent
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
- name: Uninstall Paramiko for Python 2 on FreeBSD 12
|
||||
pkgng:
|
||||
name: py27-paramiko
|
||||
state: absent
|
||||
@@ -0,0 +1,4 @@
|
||||
- name: Uninstall Paramiko for Python 3 on FreeBSD 12
|
||||
pkgng:
|
||||
name: py36-paramiko
|
||||
state: absent
|
||||
@@ -0,0 +1,5 @@
|
||||
- name: Uninstall Paramiko for Python 2 using apt
|
||||
apt:
|
||||
name: python-paramiko
|
||||
state: absent
|
||||
autoremove: yes
|
||||
@@ -0,0 +1,5 @@
|
||||
- name: Uninstall Paramiko for Python 3 using apt
|
||||
apt:
|
||||
name: python3-paramiko
|
||||
state: absent
|
||||
autoremove: yes
|
||||
@@ -0,0 +1,4 @@
|
||||
- name: Uninstall Paramiko using dnf history undo
|
||||
command: dnf history undo last --assumeyes
|
||||
args:
|
||||
warn: no
|
||||
@@ -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."
|
||||
@@ -0,0 +1,4 @@
|
||||
- name: Uninstall Paramiko using yum history undo
|
||||
command: yum history undo last --assumeyes
|
||||
args:
|
||||
warn: no
|
||||
@@ -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
|
||||
@@ -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
test/integration/targets/setup_paramiko/uninstall.yml
Normal file
18
test/integration/targets/setup_paramiko/uninstall.yml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user