2016-10-13 04:33:12 +02:00
|
|
|
# test code for the pip module
|
|
|
|
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# FIXME: replace the python test package
|
|
|
|
|
2018-05-02 16:28:10 +02:00
|
|
|
- name: install git, needed for repo installs
|
|
|
|
package:
|
|
|
|
name: git
|
|
|
|
state: present
|
|
|
|
when: ansible_distribution != "MacOSX"
|
|
|
|
|
2016-10-13 04:33:12 +02:00
|
|
|
# first some tests installed system-wide
|
|
|
|
# verify things were not installed to start with
|
|
|
|
|
2018-06-12 01:58:13 +02:00
|
|
|
- name: ensure packages are not installed (precondition setup)
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
2018-06-12 01:58:13 +02:00
|
|
|
name: "{{ pip_test_packages }}"
|
2018-05-14 14:55:01 +02:00
|
|
|
state: absent
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
# verify that a package that is uninstalled being set to absent
|
|
|
|
# results in an unchanged state and that the test package is not
|
|
|
|
# installed
|
|
|
|
|
2018-06-12 01:58:13 +02:00
|
|
|
- name: ensure packages are not installed
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
2018-06-12 01:58:13 +02:00
|
|
|
name: "{{ pip_test_packages }}"
|
2018-05-14 14:55:01 +02:00
|
|
|
state: absent
|
2016-10-13 04:33:12 +02:00
|
|
|
register: uninstall_result
|
|
|
|
|
2018-06-12 01:58:13 +02:00
|
|
|
- name: removing unremoved packages should return unchanged
|
|
|
|
assert:
|
2016-10-13 04:33:12 +02:00
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "not (uninstall_result is changed)"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
2018-06-12 01:58:13 +02:00
|
|
|
- command: "{{ ansible_python.executable }} -c 'import {{ item }}'"
|
2016-10-13 04:33:12 +02:00
|
|
|
register: absent_result
|
2018-06-12 01:58:13 +02:00
|
|
|
failed_when: "absent_result.rc == 0"
|
|
|
|
loop: '{{ pip_test_modules }}'
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
# now we're going to install the test package knowing it is uninstalled
|
|
|
|
# and check that installation was ok
|
|
|
|
|
2018-06-12 01:58:13 +02:00
|
|
|
- name: ensure packages are installed
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
2018-06-12 01:58:13 +02:00
|
|
|
name: "{{ pip_test_packages }}"
|
2018-05-14 14:55:01 +02:00
|
|
|
state: present
|
2016-10-13 04:33:12 +02:00
|
|
|
register: install_result
|
|
|
|
|
|
|
|
- name: verify we recorded a change
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "install_result is changed"
|
|
|
|
|
|
|
|
- command: "{{ ansible_python.executable }} -c 'import {{ item }}'"
|
|
|
|
loop: '{{ pip_test_modules }}'
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
# now remove it to test uninstallation of a package we are sure is installed
|
|
|
|
|
|
|
|
- name: now uninstall so we can see that a change occurred
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
2018-06-12 01:58:13 +02:00
|
|
|
name: "{{ pip_test_packages }}"
|
2018-05-14 14:55:01 +02:00
|
|
|
state: absent
|
2018-06-12 01:58:13 +02:00
|
|
|
register: absent2
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
- name: assert a change occurred on uninstallation
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "absent2 is changed"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
2018-06-12 01:58:13 +02:00
|
|
|
# put the test packages back
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
- name: now put it back in case someone wanted it (like us!)
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
2018-06-12 01:58:13 +02:00
|
|
|
name: "{{ item }}"
|
2018-05-14 14:55:01 +02:00
|
|
|
state: present
|
2018-06-12 01:58:13 +02:00
|
|
|
with_items: "{{ pip_test_packages }}"
|
|
|
|
register: squash_param
|
2016-10-13 04:33:12 +02:00
|
|
|
|
2018-06-12 01:58:13 +02:00
|
|
|
- name: check that list has been condensed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- squash_param.results|length == 1
|
|
|
|
- squash_param.results[0].name|sort == pip_test_packages|sort
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
# Test virtualenv installations
|
|
|
|
|
2017-07-14 11:54:04 +02:00
|
|
|
- name: "make sure the test env doesn't exist"
|
2018-05-14 14:55:01 +02:00
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
name: "{{ output_dir }}/pipenv"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
2017-06-01 10:23:32 +02:00
|
|
|
- name: install a working version of setuptools in the virtualenv
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
name: setuptools
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
|
|
|
version: 33.1.1
|
2017-06-01 10:23:32 +02:00
|
|
|
|
2016-10-13 04:33:12 +02:00
|
|
|
- name: create a requirement file with an vcs url
|
2018-05-14 14:55:01 +02:00
|
|
|
copy:
|
|
|
|
dest: "{{ output_dir }}/pipreq.txt"
|
|
|
|
content: "-e git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
- name: install the requirement file in a virtualenv
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
requirements: "{{ output_dir}}/pipreq.txt"
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
2016-10-13 04:33:12 +02:00
|
|
|
register: req_installed
|
|
|
|
|
|
|
|
- name: check that a change occurred
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "req_installed is changed"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
2017-07-14 11:54:04 +02:00
|
|
|
- name: "repeat installation to check status didn't change"
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
requirements: "{{ output_dir}}/pipreq.txt"
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
2016-10-13 04:33:12 +02:00
|
|
|
register: req_installed
|
|
|
|
|
2017-07-14 11:54:04 +02:00
|
|
|
- name: "check that a change didn't occurr this time (bug ansible#1705)"
|
2016-10-13 04:33:12 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "not (req_installed is changed)"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
- name: install the same module from url
|
2017-07-14 11:54:04 +02:00
|
|
|
pip:
|
|
|
|
name: "git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601"
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
editable: True
|
2016-10-13 04:33:12 +02:00
|
|
|
register: url_installed
|
|
|
|
|
2017-07-14 11:54:04 +02:00
|
|
|
- name: "check that a change didn't occurr (bug ansible-modules-core#1645)"
|
2016-10-13 04:33:12 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "not (url_installed is changed)"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
# Test pip package in check mode doesn't always report changed.
|
|
|
|
|
|
|
|
# Special case for pip
|
|
|
|
- name: check for pip package
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
name: pip
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
- name: check for pip package in check_mode
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
name: pip
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 04:33:12 +02:00
|
|
|
check_mode: True
|
|
|
|
register: pip_check_mode
|
|
|
|
|
|
|
|
- name: make sure pip in check_mode doesn't report changed
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "not (pip_check_mode is changed)"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
# Special case for setuptools
|
|
|
|
- name: check for setuptools package
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
name: setuptools
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
- name: check for setuptools package in check_mode
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
name: setuptools
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 04:33:12 +02:00
|
|
|
check_mode: True
|
|
|
|
register: setuptools_check_mode
|
|
|
|
|
|
|
|
- name: make sure setuptools in check_mode doesn't report changed
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "not (setuptools_check_mode is changed)"
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Normal case
|
|
|
|
- name: check for q package
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
name: q
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 04:33:12 +02:00
|
|
|
|
|
|
|
- name: check for q package in check_mode
|
2018-05-14 14:55:01 +02:00
|
|
|
pip:
|
|
|
|
name: q
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 04:33:12 +02:00
|
|
|
check_mode: True
|
|
|
|
register: q_check_mode
|
|
|
|
|
|
|
|
- name: make sure q in check_mode doesn't report changed
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "not (q_check_mode is changed)"
|
2017-09-12 19:01:29 +02:00
|
|
|
|
|
|
|
# ansible#23204
|
|
|
|
- name: ensure is a fresh virtualenv
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
name: "{{ output_dir }}/pipenv"
|
|
|
|
|
|
|
|
- name: install pip throught pip into fresh virtualenv
|
|
|
|
pip:
|
|
|
|
name: pip
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
register: pip_install_venv
|
|
|
|
|
|
|
|
- name: make sure pip in fresh virtualenv report changed
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "pip_install_venv is changed"
|
2017-10-13 12:39:47 +02:00
|
|
|
|
2018-08-13 19:59:01 +02:00
|
|
|
# https://github.com/ansible/ansible/issues/37912
|
|
|
|
# support chdir without virtualenv
|
|
|
|
- name: create chdir test directories
|
|
|
|
file:
|
|
|
|
state: directory
|
|
|
|
name: "{{ output_dir }}/{{ item }}"
|
|
|
|
loop:
|
|
|
|
- pip_module
|
|
|
|
- pip_root
|
|
|
|
- pip_module/ansible_test_pip_chdir
|
|
|
|
|
|
|
|
- name: copy test module
|
|
|
|
copy:
|
|
|
|
src: "{{ item }}"
|
|
|
|
dest: "{{ output_dir }}/pip_module/{{ item }}"
|
|
|
|
loop:
|
|
|
|
- setup.py
|
|
|
|
- ansible_test_pip_chdir/__init__.py
|
|
|
|
|
|
|
|
- name: install test module
|
|
|
|
pip:
|
|
|
|
name: .
|
|
|
|
chdir: "{{ output_dir }}/pip_module"
|
|
|
|
extra_args: --user --upgrade --root {{ output_dir }}/pip_root
|
|
|
|
|
|
|
|
- name: register python_site_lib
|
2018-10-19 09:00:34 +02:00
|
|
|
command: '{{ ansible_python.executable }} -c "import site; print(site.USER_SITE)"'
|
2018-08-13 19:59:01 +02:00
|
|
|
register: pip_python_site_lib
|
|
|
|
|
|
|
|
- name: register python_user_base
|
2018-10-19 09:00:34 +02:00
|
|
|
command: '{{ ansible_python.executable }} -c "import site; print(site.USER_BASE)"'
|
2018-08-13 19:59:01 +02:00
|
|
|
register: pip_python_user_base
|
|
|
|
|
|
|
|
- name: run test module
|
|
|
|
shell: "PYTHONPATH=$(echo {{ output_dir }}/pip_root{{ pip_python_site_lib.stdout }}) {{ output_dir }}/pip_root{{ pip_python_user_base.stdout }}/bin/ansible_test_pip_chdir"
|
|
|
|
register: pip_chdir_command
|
|
|
|
|
|
|
|
- name: make sure command ran
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- pip_chdir_command.stdout == "success"
|
|
|
|
|
2017-10-13 12:39:47 +02:00
|
|
|
# https://github.com/ansible/ansible/issues/25122
|
|
|
|
- name: ensure is a fresh virtualenv
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
name: "{{ output_dir }}/pipenv"
|
|
|
|
|
|
|
|
- name: install requirements file into virtual + chdir
|
|
|
|
pip:
|
|
|
|
name: q
|
|
|
|
chdir: "{{ output_dir }}/"
|
|
|
|
virtualenv: "pipenv"
|
|
|
|
state: present
|
|
|
|
register: venv_chdir
|
|
|
|
|
|
|
|
- name: make sure fresh virtualenv + chdir report changed
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "venv_chdir is changed"
|
2018-05-14 14:51:10 +02:00
|
|
|
|
|
|
|
# ansible#38785
|
|
|
|
- name: allow empty list of packages
|
|
|
|
pip:
|
|
|
|
name: []
|
|
|
|
register: pip_install_empty
|
|
|
|
|
|
|
|
- name: ensure empty install is successful
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-12 01:58:13 +02:00
|
|
|
- "not (pip_install_empty is changed)"
|
2018-06-06 09:52:43 +02:00
|
|
|
|
|
|
|
# https://github.com/ansible/ansible/issues/41043
|
|
|
|
- name: do not consider an empty string as a version
|
|
|
|
pip:
|
|
|
|
name: q
|
|
|
|
state: present
|
|
|
|
version: ""
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
register: pip_install_empty_version_string
|
|
|
|
|
|
|
|
- name: ensure that task installation did not fail
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- pip_install_empty_version_string is successful
|
2018-08-17 17:46:53 +02:00
|
|
|
|
|
|
|
# test version specifiers
|
|
|
|
- name: make sure no test_package installed now
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_packages }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: install package with version specifiers
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
version: "<100,!=1.0,>0.0.0"
|
|
|
|
register: version
|
|
|
|
|
|
|
|
- name: assert package installed correctly
|
|
|
|
assert:
|
|
|
|
that: "version.changed"
|
|
|
|
|
|
|
|
- name: reinstall package
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
version: "<100,!=1.0,>0.0.0"
|
|
|
|
register: version2
|
|
|
|
|
|
|
|
- name: assert no changes ocurred
|
|
|
|
assert:
|
|
|
|
that: "not version2.changed"
|
|
|
|
|
|
|
|
- name: test the check_mod
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
version: "<100,!=1.0,>0.0.0"
|
|
|
|
check_mode: yes
|
|
|
|
register: version3
|
|
|
|
|
|
|
|
- name: assert no changes
|
|
|
|
assert:
|
|
|
|
that: "not version3.changed"
|
|
|
|
|
|
|
|
- name: test the check_mod with unsatisfied version
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
version: ">100.0.0"
|
|
|
|
check_mode: yes
|
|
|
|
register: version4
|
|
|
|
|
|
|
|
- name: assert changed
|
|
|
|
assert:
|
|
|
|
that: "version4.changed"
|
|
|
|
|
|
|
|
- name: uninstall test packages for next test
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_packages }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: test invalid combination of arguments
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_pkg_ver }}"
|
|
|
|
version: "1.11.1"
|
|
|
|
ignore_errors: yes
|
|
|
|
register: version5
|
|
|
|
|
|
|
|
- name: assert the invalid combination should fail
|
|
|
|
assert:
|
|
|
|
that: "version5 is failed"
|
|
|
|
|
|
|
|
- name: another invalid combination of arguments
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_pkg_ver[0] }}"
|
|
|
|
version: "<100.0.0"
|
|
|
|
ignore_errors: yes
|
|
|
|
register: version6
|
|
|
|
|
|
|
|
- name: assert invalid combination should fail
|
|
|
|
assert:
|
|
|
|
that: "version6 is failed"
|
|
|
|
|
|
|
|
- name: try to install invalid package
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_pkg_ver_unsatisfied }}"
|
|
|
|
ignore_errors: yes
|
|
|
|
register: version7
|
|
|
|
|
|
|
|
- name: assert install should fail
|
|
|
|
assert:
|
|
|
|
that: "version7 is failed"
|
|
|
|
|
|
|
|
- name: test install multi-packages with version specifiers
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_pkg_ver }}"
|
|
|
|
register: version8
|
|
|
|
|
|
|
|
- name: assert packages installed correctly
|
|
|
|
assert:
|
|
|
|
that: "version8.changed"
|
|
|
|
|
|
|
|
- name: test install multi-packages with check_mode
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_pkg_ver }}"
|
|
|
|
check_mode: yes
|
|
|
|
register: version9
|
|
|
|
|
|
|
|
- name: assert no change
|
|
|
|
assert:
|
|
|
|
that: "not version9.changed"
|
|
|
|
|
|
|
|
- name: test install unsatisfied multi-packages with check_mode
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_pkg_ver_unsatisfied }}"
|
|
|
|
check_mode: yes
|
|
|
|
register: version10
|
|
|
|
|
|
|
|
- name: assert changes needed
|
|
|
|
assert:
|
|
|
|
that: "version10.changed"
|
|
|
|
|
|
|
|
- name: uninstall packages for next test
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_packages }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: test install multi package provided by one single string
|
|
|
|
pip:
|
|
|
|
name: "{{pip_test_pkg_ver[0]}},{{pip_test_pkg_ver[1]}}"
|
|
|
|
register: version11
|
|
|
|
|
|
|
|
- name: assert the install ran correctly
|
|
|
|
assert:
|
|
|
|
that: "version11.changed"
|
|
|
|
|
|
|
|
- name: test install multi package provided by one single string with check_mode
|
|
|
|
pip:
|
|
|
|
name: "{{pip_test_pkg_ver[0]}},{{pip_test_pkg_ver[1]}}"
|
|
|
|
check_mode: yes
|
|
|
|
register: version12
|
|
|
|
|
|
|
|
- name: assert no changes needed
|
|
|
|
assert:
|
|
|
|
that: "not version12.changed"
|
|
|
|
|
|
|
|
- name: test module can parse the combination of multi-packages one line and git url
|
|
|
|
pip:
|
|
|
|
name:
|
|
|
|
- git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601
|
|
|
|
- "{{pip_test_pkg_ver[0]}},{{pip_test_pkg_ver[1]}}"
|
|
|
|
|
|
|
|
- name: test the invalid package name
|
|
|
|
pip:
|
|
|
|
name: djan=+-~!@#$go>1.11.1,<1.11.3
|
|
|
|
ignore_errors: yes
|
|
|
|
register: version13
|
|
|
|
|
|
|
|
- name: the invalid package should make module failed
|
|
|
|
assert:
|
|
|
|
that: "version13 is failed"
|
|
|
|
|
|
|
|
- name: clean up
|
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_packages }}"
|
|
|
|
state: absent
|