diff options
author | Rick Elrod <rick@elrod.me> | 2020-04-06 11:18:48 -0500 |
---|---|---|
committer | Matt Clay <matt@mystile.com> | 2020-04-21 11:31:33 -0700 |
commit | a5c671da74d1068b5c8b425b1b8a06c1b134c646 (patch) | |
tree | 9a971c2ba0b224d010303e89fd71deffb38b85d6 | |
parent | 27e40233503625a075f8ef753336318969e201f4 (diff) | |
download | ansible-a5c671da74d1068b5c8b425b1b8a06c1b134c646.tar.gz |
[stable-2.7] pip - Fix check_mode for prerelease packages (#68690)
* pip - Fix check_mode for prerelease packages
Fixes #68592.
Signed-off-by: Rick Elrod <rick@elrod.me>
Co-authored-by: Matt Martz <matt@sivel.net>.
(cherry picked from commit 82c60db49b7b2f64c68308bcdb9d61231c21df24)
Co-authored-by: Rick Elrod <rick@elrod.me>
-rw-r--r-- | changelogs/fragments/68592-pip-check_mode-prereleases.yml | 2 | ||||
-rw-r--r-- | lib/ansible/modules/packaging/language/pip.py | 2 | ||||
-rw-r--r-- | test/integration/targets/pip/tasks/pip.yml | 35 | ||||
-rw-r--r-- | test/integration/targets/pip/vars/main.yml | 2 |
4 files changed, 39 insertions, 2 deletions
diff --git a/changelogs/fragments/68592-pip-check_mode-prereleases.yml b/changelogs/fragments/68592-pip-check_mode-prereleases.yml new file mode 100644 index 0000000000..754ed7b2fa --- /dev/null +++ b/changelogs/fragments/68592-pip-check_mode-prereleases.yml @@ -0,0 +1,2 @@ +bugfixes: + - "pip - check_mode with ``state: present`` now returns the correct state for pre-release versioned packages" diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index 404aac949e..07072ee4f3 100644 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -523,7 +523,7 @@ class Package: if not self._plain_package: return False try: - return self._requirement.specifier.contains(version_to_test) + return self._requirement.specifier.contains(version_to_test, prereleases=True) except AttributeError: # old setuptools has no specifier, do fallback version_to_test = LooseVersion(version_to_test) diff --git a/test/integration/targets/pip/tasks/pip.yml b/test/integration/targets/pip/tasks/pip.yml index 791e03dc6b..f459948e66 100644 --- a/test/integration/targets/pip/tasks/pip.yml +++ b/test/integration/targets/pip/tasks/pip.yml @@ -530,3 +530,38 @@ assert: that: "'distribute' in remove_distribute.cmd" when: ansible_python.version.major == 2 + +# https://github.com/ansible/ansible/issues/68592 +# Handle pre-release version numbers in check_mode for already-installed +# packages. +# TODO: Limiting to py3 test boxes for now so the example of 'black' installs, +# we should probably find another package to use with a similar versioning +# scheme or make a small one and enable this test for py2 as well. +- block: + - name: Install a beta version of a package + pip: + name: black + version: 19.10b0 + state: present + + - name: Use check_mode and ensure that the package is shown as installed + check_mode: true + pip: + name: black + state: present + register: pip_prereleases + + - name: Uninstall the beta package if we need to + pip: + name: black + version: 19.10b0 + state: absent + when: pip_prereleases is changed + + - assert: + that: + - pip_prereleases is successful + - pip_prereleases is not changed + - '"black==19.10b0" in pip_prereleases.stdout_lines' + + when: ansible_python.version.major == 3 diff --git a/test/integration/targets/pip/vars/main.yml b/test/integration/targets/pip/vars/main.yml index d51e741c6a..a4bbf81e5c 100644 --- a/test/integration/targets/pip/vars/main.yml +++ b/test/integration/targets/pip/vars/main.yml @@ -3,7 +3,7 @@ pip_test_packages: - sampleproject - decorator pip_test_pkg_ver: - - sampleproject<=100, !=9.0.0,>=0.0.1 + - sampleproject<=100, !=9.0.0,>=0.0.1 - decorator<100 ,!=9,>=0.0.1 pip_test_pkg_ver_unsatisfied: - sampleproject>= 999.0.0 |