diff options
author | Mark Chappell <mchappel@redhat.com> | 2023-02-27 22:23:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 13:23:40 -0800 |
commit | f64e79be41f0fcd19d0ff693fc8ee804b21cf82c (patch) | |
tree | abee0372c8767803394cf4f8b046f005546cd5c2 | |
parent | 39fd899d83cfcbc6aa313512d2a7f61ac97cfa8a (diff) | |
download | ansible-f64e79be41f0fcd19d0ff693fc8ee804b21cf82c.tar.gz |
sanity tests - ignore pre-release versions for deprecation comparisons (#79185)
7 files changed, 66 insertions, 1 deletions
diff --git a/changelogs/fragments/20221021-deprecated-sanity.yml b/changelogs/fragments/20221021-deprecated-sanity.yml new file mode 100644 index 0000000000..5973fb3b01 --- /dev/null +++ b/changelogs/fragments/20221021-deprecated-sanity.yml @@ -0,0 +1,2 @@ +minor_changes: +- sanity tests - updates the collection-deprecated-version tests to ignore the ``prerelease`` component of the collection version (). diff --git a/test/integration/targets/ansible-test-sanity-pylint/aliases b/test/integration/targets/ansible-test-sanity-pylint/aliases new file mode 100644 index 0000000000..7741d44451 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-pylint/aliases @@ -0,0 +1,4 @@ +shippable/posix/group3 # runs in the distro test containers +shippable/generic/group1 # runs in the default test container +context/controller +needs/target/collection diff --git a/test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/galaxy.yml b/test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/galaxy.yml new file mode 100644 index 0000000000..53a7727982 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/galaxy.yml @@ -0,0 +1,6 @@ +namespace: ns +name: col +version: +readme: README.rst +authors: + - Ansible diff --git a/test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/plugins/lookup/deprecated.py b/test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/plugins/lookup/deprecated.py new file mode 100644 index 0000000000..b7908b6cbe --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/plugins/lookup/deprecated.py @@ -0,0 +1,22 @@ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +name: deprecated +short_description: lookup +description: Lookup. +author: + - Ansible Core Team +''' + +EXAMPLES = '''#''' +RETURN = '''#''' + +from ansible.plugins.lookup import LookupBase + + +class LookupModule(LookupBase): + def run(self, **kwargs): + return [] diff --git a/test/integration/targets/ansible-test-sanity-pylint/expected.txt b/test/integration/targets/ansible-test-sanity-pylint/expected.txt new file mode 100644 index 0000000000..df7bbc2069 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-pylint/expected.txt @@ -0,0 +1 @@ +plugins/lookup/deprecated.py:27:0: collection-deprecated-version: Deprecated version ('2.0.0') found in call to Display.deprecated or AnsibleModule.deprecate diff --git a/test/integration/targets/ansible-test-sanity-pylint/runme.sh b/test/integration/targets/ansible-test-sanity-pylint/runme.sh new file mode 100755 index 0000000000..72190bfaa0 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-pylint/runme.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -eu + +source ../collection/setup.sh + +# Create test scenarios at runtime that do not pass sanity tests. +# This avoids the need to create ignore entries for the tests. + +echo " +from ansible.utils.display import Display + +display = Display() +display.deprecated('', version='2.0.0', collection_name='ns.col')" >> plugins/lookup/deprecated.py + +# Verify deprecation checking works for normal releases and pre-releases. + +for version in 2.0.0 2.0.0-dev0; do + echo "Checking version: ${version}" + sed "s/^version:.*\$/version: ${version}/" < galaxy.yml > galaxy.yml.tmp + mv galaxy.yml.tmp galaxy.yml + ansible-test sanity --test pylint --color --failure-ok --lint "${@}" 1> actual-stdout.txt 2> actual-stderr.txt + diff -u "${TEST_DIR}/expected.txt" actual-stdout.txt + grep -f "${TEST_DIR}/expected.txt" actual-stderr.txt +done diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py index 79b8bf1569..821bcefbc4 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py @@ -202,7 +202,12 @@ class AnsibleDeprecatedChecker(BaseChecker): @property def collection_version(self) -> t.Optional[SemanticVersion]: """Return the collection version, or None if ansible-core is being tested.""" - return SemanticVersion(self.config.collection_version) if self.config.collection_version is not None else None + if self.config.collection_version is None: + return None + sem_ver = SemanticVersion(self.config.collection_version) + # Ignore pre-release for version comparison to catch issues before the final release is cut. + sem_ver.prerelease = () + return sem_ver @check_messages(*(MSGS.keys())) def visit_call(self, node): |