2016-10-13 02:33:12 +00: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 14:28:10 +00:00
|
|
|
- name: install git, needed for repo installs
|
|
|
|
package:
|
|
|
|
name: git
|
|
|
|
state: present
|
|
|
|
when: ansible_distribution != "MacOSX"
|
|
|
|
|
2016-10-13 02:33:12 +00:00
|
|
|
# first some tests installed system-wide
|
|
|
|
# verify things were not installed to start with
|
|
|
|
|
|
|
|
- name: ensure a package is not installed (precondition setup)
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
state: absent
|
2016-10-13 02:33:12 +00: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
|
|
|
|
|
|
|
|
- name: ensure a package is not installed
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
state: absent
|
2016-10-13 02:33:12 +00:00
|
|
|
register: uninstall_result
|
|
|
|
|
|
|
|
- name: removing an unremoved package should return unchanged
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not uninstall_result.changed"
|
|
|
|
|
|
|
|
- shell: "{{ ansible_python.executable }} -c 'import {{ pip_test_package }}'"
|
|
|
|
register: absent_result
|
|
|
|
ignore_errors: True
|
|
|
|
|
|
|
|
- name: verify {{ pip_test_package }} is not present
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "absent_result.rc != 0"
|
|
|
|
|
|
|
|
# now we're going to install the test package knowing it is uninstalled
|
|
|
|
# and check that installation was ok
|
|
|
|
|
|
|
|
- name: ensure a package is installed
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
register: install_result
|
|
|
|
|
|
|
|
- name: verify we recorded a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "install_result.changed == True"
|
|
|
|
|
|
|
|
- shell: "{{ ansible_python.executable }} -c 'import {{ pip_test_package }}'"
|
|
|
|
register: installed_result
|
|
|
|
|
|
|
|
# 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 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
state: absent
|
2016-10-13 02:33:12 +00:00
|
|
|
register: absent2
|
|
|
|
|
|
|
|
- name: assert a change occurred on uninstallation
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "absent2.changed"
|
|
|
|
|
|
|
|
# put the test package back
|
|
|
|
|
|
|
|
- name: now put it back in case someone wanted it (like us!)
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: "{{ pip_test_package }}"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Test virtualenv installations
|
|
|
|
|
2017-07-14 09:54:04 +00:00
|
|
|
- name: "make sure the test env doesn't exist"
|
2018-05-14 12:55:01 +00:00
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
name: "{{ output_dir }}/pipenv"
|
2016-10-13 02:33:12 +00:00
|
|
|
|
2017-06-01 08:23:32 +00:00
|
|
|
- name: install a working version of setuptools in the virtualenv
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: setuptools
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
|
|
|
version: 33.1.1
|
2017-06-01 08:23:32 +00:00
|
|
|
|
2016-10-13 02:33:12 +00:00
|
|
|
- name: create a requirement file with an vcs url
|
2018-05-14 12:55:01 +00:00
|
|
|
copy:
|
|
|
|
dest: "{{ output_dir }}/pipreq.txt"
|
|
|
|
content: "-e git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601"
|
2016-10-13 02:33:12 +00:00
|
|
|
|
|
|
|
- name: install the requirement file in a virtualenv
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
requirements: "{{ output_dir}}/pipreq.txt"
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
2016-10-13 02:33:12 +00:00
|
|
|
register: req_installed
|
|
|
|
|
|
|
|
- name: check that a change occurred
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "req_installed.changed"
|
|
|
|
|
2017-07-14 09:54:04 +00:00
|
|
|
- name: "repeat installation to check status didn't change"
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
requirements: "{{ output_dir}}/pipreq.txt"
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
2016-10-13 02:33:12 +00:00
|
|
|
register: req_installed
|
|
|
|
|
2017-07-14 09:54:04 +00:00
|
|
|
- name: "check that a change didn't occurr this time (bug ansible#1705)"
|
2016-10-13 02:33:12 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not req_installed.changed"
|
|
|
|
|
|
|
|
- name: install the same module from url
|
2017-07-14 09:54:04 +00:00
|
|
|
pip:
|
|
|
|
name: "git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601"
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
editable: True
|
2016-10-13 02:33:12 +00:00
|
|
|
register: url_installed
|
|
|
|
|
2017-07-14 09:54:04 +00:00
|
|
|
- name: "check that a change didn't occurr (bug ansible-modules-core#1645)"
|
2016-10-13 02:33:12 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not url_installed.changed"
|
|
|
|
|
|
|
|
# Test pip package in check mode doesn't always report changed.
|
|
|
|
|
|
|
|
# Special case for pip
|
|
|
|
- name: check for pip package
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: pip
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
|
|
|
|
- name: check for pip package in check_mode
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: pip
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
check_mode: True
|
|
|
|
register: pip_check_mode
|
|
|
|
|
|
|
|
- name: make sure pip in check_mode doesn't report changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not pip_check_mode.changed"
|
|
|
|
|
|
|
|
# Special case for setuptools
|
|
|
|
- name: check for setuptools package
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: setuptools
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
|
|
|
|
- name: check for setuptools package in check_mode
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: setuptools
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
check_mode: True
|
|
|
|
register: setuptools_check_mode
|
|
|
|
|
|
|
|
- name: make sure setuptools in check_mode doesn't report changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not setuptools_check_mode.changed"
|
|
|
|
|
|
|
|
|
|
|
|
# Normal case
|
|
|
|
- name: check for q package
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: q
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
|
|
|
|
- name: check for q package in check_mode
|
2018-05-14 12:55:01 +00:00
|
|
|
pip:
|
|
|
|
name: q
|
|
|
|
virtualenv: "{{ output_dir }}/pipenv"
|
|
|
|
state: present
|
2016-10-13 02:33:12 +00:00
|
|
|
check_mode: True
|
|
|
|
register: q_check_mode
|
|
|
|
|
|
|
|
- name: make sure q in check_mode doesn't report changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not q_check_mode.changed"
|
2017-09-12 17:01:29 +00: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:
|
|
|
|
- "pip_install_venv.changed"
|
2017-10-13 10:39:47 +00: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:
|
|
|
|
- "venv_chdir.changed"
|
2018-05-14 12:51:10 +00:00
|
|
|
|
|
|
|
# ansible#38785
|
|
|
|
- name: allow empty list of packages
|
|
|
|
pip:
|
|
|
|
name: []
|
|
|
|
register: pip_install_empty
|
|
|
|
|
|
|
|
- name: ensure empty install is successful
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- not pip_install_empty.changed
|