You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/pip/tasks/pip.yml

276 lines
6.9 KiB
YAML

# 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
- name: install git, needed for repo installs
package:
name: git
state: present
when: ansible_distribution != "MacOSX"
# first some tests installed system-wide
# verify things were not installed to start with
- name: ensure packages are not installed (precondition setup)
pip:
name: "{{ pip_test_packages }}"
state: absent
# 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 packages are not installed
pip:
name: "{{ pip_test_packages }}"
state: absent
register: uninstall_result
- name: removing unremoved packages should return unchanged
assert:
that:
- "not (uninstall_result is changed)"
- command: "{{ ansible_python.executable }} -c 'import {{ item }}'"
register: absent_result
failed_when: "absent_result.rc == 0"
loop: '{{ pip_test_modules }}'
# now we're going to install the test package knowing it is uninstalled
# and check that installation was ok
- name: ensure packages are installed
pip:
name: "{{ pip_test_packages }}"
state: present
register: install_result
- name: verify we recorded a change
assert:
that:
- "install_result is changed"
- command: "{{ ansible_python.executable }} -c 'import {{ item }}'"
loop: '{{ pip_test_modules }}'
# 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
pip:
name: "{{ pip_test_packages }}"
state: absent
register: absent2
- name: assert a change occurred on uninstallation
assert:
that:
- "absent2 is changed"
# put the test packages back
- name: now put it back in case someone wanted it (like us!)
pip:
name: "{{ item }}"
state: present
with_items: "{{ pip_test_packages }}"
register: squash_param
- name: check that list has been condensed
assert:
that:
- squash_param.results|length == 1
- squash_param.results[0].name|sort == pip_test_packages|sort
# Test virtualenv installations
- name: "make sure the test env doesn't exist"
file:
state: absent
name: "{{ output_dir }}/pipenv"
- name: install a working version of setuptools in the virtualenv
pip:
name: setuptools
virtualenv: "{{ output_dir }}/pipenv"
state: present
version: 33.1.1
- name: create a requirement file with an vcs url
copy:
dest: "{{ output_dir }}/pipreq.txt"
content: "-e git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601"
- name: install the requirement file in a virtualenv
pip:
requirements: "{{ output_dir}}/pipreq.txt"
virtualenv: "{{ output_dir }}/pipenv"
register: req_installed
- name: check that a change occurred
assert:
that:
- "req_installed is changed"
- name: "repeat installation to check status didn't change"
pip:
requirements: "{{ output_dir}}/pipreq.txt"
virtualenv: "{{ output_dir }}/pipenv"
register: req_installed
- name: "check that a change didn't occurr this time (bug ansible#1705)"
assert:
that:
- "not (req_installed is changed)"
- name: install the same module from url
pip:
name: "git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601"
virtualenv: "{{ output_dir }}/pipenv"
editable: True
register: url_installed
- name: "check that a change didn't occurr (bug ansible-modules-core#1645)"
assert:
that:
- "not (url_installed is changed)"
# Test pip package in check mode doesn't always report changed.
# Special case for pip
- name: check for pip package
pip:
name: pip
virtualenv: "{{ output_dir }}/pipenv"
state: present
- name: check for pip package in check_mode
pip:
name: pip
virtualenv: "{{ output_dir }}/pipenv"
state: present
check_mode: True
register: pip_check_mode
- name: make sure pip in check_mode doesn't report changed
assert:
that:
- "not (pip_check_mode is changed)"
# Special case for setuptools
- name: check for setuptools package
pip:
name: setuptools
virtualenv: "{{ output_dir }}/pipenv"
state: present
- name: check for setuptools package in check_mode
pip:
name: setuptools
virtualenv: "{{ output_dir }}/pipenv"
state: present
check_mode: True
register: setuptools_check_mode
- name: make sure setuptools in check_mode doesn't report changed
assert:
that:
- "not (setuptools_check_mode is changed)"
# Normal case
- name: check for q package
pip:
name: q
virtualenv: "{{ output_dir }}/pipenv"
state: present
- name: check for q package in check_mode
pip:
name: q
virtualenv: "{{ output_dir }}/pipenv"
state: present
check_mode: True
register: q_check_mode
- name: make sure q in check_mode doesn't report changed
assert:
that:
- "not (q_check_mode is changed)"
# 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 is changed"
# 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 is changed"
# 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 is changed)"
# 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