Default squash actions add pip (#41390)

* pip tests: remove trailing spaces

* pip tests: use Jinja tests

* fixup! pip tests: remove trailing spaces

* pip tests: use 'command' instead of 'shell' module

* pip tests: remove unused variable

* pip tests: use a package with fewer dependencies

sampleproject has one dependency: 'peppercorn' and peppercorn doesn't
have any dependency.

* pip tests: check that 'name' param handles list

* pip: squash package parameters

Note that squashing will be removed in 2.11, new code should directly
use a list with the 'name' parameter.
pull/19543/merge
Pilou 7 years ago committed by Brian Coca
parent dd8d74c351
commit 5d7afe9d95

@ -969,7 +969,7 @@ DEFAULT_SFTP_BATCH_MODE:
yaml: {key: ssh_connection.sftp_batch_mode} yaml: {key: ssh_connection.sftp_batch_mode}
DEFAULT_SQUASH_ACTIONS: DEFAULT_SQUASH_ACTIONS:
name: Squashable actions name: Squashable actions
default: apk, apt, dnf, homebrew, openbsd_pkg, pacman, pkgng, yum, zypper default: apk, apt, dnf, homebrew, openbsd_pkg, pacman, pip, pkgng, yum, zypper
description: description:
- Ansible can optimise actions that call modules that support list parameters when using ``with_`` looping. - Ansible can optimise actions that call modules that support list parameters when using ``with_`` looping.
Instead of calling the module once for each item, the module is called once with the full list. Instead of calling the module once for each item, the module is called once with the full list.

@ -27,72 +27,75 @@
# first some tests installed system-wide # first some tests installed system-wide
# verify things were not installed to start with # verify things were not installed to start with
- name: ensure a package is not installed (precondition setup) - name: ensure packages are not installed (precondition setup)
pip: pip:
name: "{{ pip_test_package }}" name: "{{ pip_test_packages }}"
state: absent state: absent
# verify that a package that is uninstalled being set to absent # verify that a package that is uninstalled being set to absent
# results in an unchanged state and that the test package is not # results in an unchanged state and that the test package is not
# installed # installed
- name: ensure a package is not installed - name: ensure packages are not installed
pip: pip:
name: "{{ pip_test_package }}" name: "{{ pip_test_packages }}"
state: absent state: absent
register: uninstall_result register: uninstall_result
- name: removing an unremoved package should return unchanged - name: removing unremoved packages should return unchanged
assert: assert:
that: that:
- "not uninstall_result.changed" - "not (uninstall_result is changed)"
- shell: "{{ ansible_python.executable }} -c 'import {{ pip_test_package }}'" - command: "{{ ansible_python.executable }} -c 'import {{ item }}'"
register: absent_result register: absent_result
ignore_errors: True failed_when: "absent_result.rc == 0"
loop: '{{ pip_test_modules }}'
- 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 # now we're going to install the test package knowing it is uninstalled
# and check that installation was ok # and check that installation was ok
- name: ensure a package is installed - name: ensure packages are installed
pip: pip:
name: "{{ pip_test_package }}" name: "{{ pip_test_packages }}"
state: present state: present
register: install_result register: install_result
- name: verify we recorded a change - name: verify we recorded a change
assert: assert:
that: that:
- "install_result.changed == True" - "install_result is changed"
- shell: "{{ ansible_python.executable }} -c 'import {{ pip_test_package }}'" - command: "{{ ansible_python.executable }} -c 'import {{ item }}'"
register: installed_result loop: '{{ pip_test_modules }}'
# now remove it to test uninstallation of a package we are sure is installed # 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 - name: now uninstall so we can see that a change occurred
pip: pip:
name: "{{ pip_test_package }}" name: "{{ pip_test_packages }}"
state: absent state: absent
register: absent2 register: absent2
- name: assert a change occurred on uninstallation - name: assert a change occurred on uninstallation
assert: assert:
that: that:
- "absent2.changed" - "absent2 is changed"
# put the test package back # put the test packages back
- name: now put it back in case someone wanted it (like us!) - name: now put it back in case someone wanted it (like us!)
pip: pip:
name: "{{ pip_test_package }}" name: "{{ item }}"
state: present 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 # Test virtualenv installations
@ -122,7 +125,7 @@
- name: check that a change occurred - name: check that a change occurred
assert: assert:
that: that:
- "req_installed.changed" - "req_installed is changed"
- name: "repeat installation to check status didn't change" - name: "repeat installation to check status didn't change"
pip: pip:
@ -133,7 +136,7 @@
- name: "check that a change didn't occurr this time (bug ansible#1705)" - name: "check that a change didn't occurr this time (bug ansible#1705)"
assert: assert:
that: that:
- "not req_installed.changed" - "not (req_installed is changed)"
- name: install the same module from url - name: install the same module from url
pip: pip:
@ -145,7 +148,7 @@
- name: "check that a change didn't occurr (bug ansible-modules-core#1645)" - name: "check that a change didn't occurr (bug ansible-modules-core#1645)"
assert: assert:
that: that:
- "not url_installed.changed" - "not (url_installed is changed)"
# Test pip package in check mode doesn't always report changed. # Test pip package in check mode doesn't always report changed.
@ -167,7 +170,7 @@
- name: make sure pip in check_mode doesn't report changed - name: make sure pip in check_mode doesn't report changed
assert: assert:
that: that:
- "not pip_check_mode.changed" - "not (pip_check_mode is changed)"
# Special case for setuptools # Special case for setuptools
- name: check for setuptools package - name: check for setuptools package
@ -187,7 +190,7 @@
- name: make sure setuptools in check_mode doesn't report changed - name: make sure setuptools in check_mode doesn't report changed
assert: assert:
that: that:
- "not setuptools_check_mode.changed" - "not (setuptools_check_mode is changed)"
# Normal case # Normal case
@ -208,7 +211,7 @@
- name: make sure q in check_mode doesn't report changed - name: make sure q in check_mode doesn't report changed
assert: assert:
that: that:
- "not q_check_mode.changed" - "not (q_check_mode is changed)"
# ansible#23204 # ansible#23204
- name: ensure is a fresh virtualenv - name: ensure is a fresh virtualenv
@ -225,7 +228,7 @@
- name: make sure pip in fresh virtualenv report changed - name: make sure pip in fresh virtualenv report changed
assert: assert:
that: that:
- "pip_install_venv.changed" - "pip_install_venv is changed"
# https://github.com/ansible/ansible/issues/25122 # https://github.com/ansible/ansible/issues/25122
- name: ensure is a fresh virtualenv - name: ensure is a fresh virtualenv
@ -244,7 +247,7 @@
- name: make sure fresh virtualenv + chdir report changed - name: make sure fresh virtualenv + chdir report changed
assert: assert:
that: that:
- "venv_chdir.changed" - "venv_chdir is changed"
# ansible#38785 # ansible#38785
- name: allow empty list of packages - name: allow empty list of packages
@ -255,7 +258,7 @@
- name: ensure empty install is successful - name: ensure empty install is successful
assert: assert:
that: that:
- not pip_install_empty.changed - "not (pip_install_empty is changed)"
# https://github.com/ansible/ansible/issues/41043 # https://github.com/ansible/ansible/issues/41043
- name: do not consider an empty string as a version - name: do not consider an empty string as a version

@ -1 +1,7 @@
pip_test_package: tex pip_test_package: sampleproject
pip_test_packages:
- sampleproject
- decorator
pip_test_modules:
- sample
- decorator

Loading…
Cancel
Save