From f64e79be41f0fcd19d0ff693fc8ee804b21cf82c Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 27 Feb 2023 22:23:40 +0100 Subject: [PATCH] sanity tests - ignore pre-release versions for deprecation comparisons (#79185) --- .../fragments/20221021-deprecated-sanity.yml | 2 ++ .../ansible-test-sanity-pylint/aliases | 4 +++ .../ansible_collections/ns/col/galaxy.yml | 6 +++++ .../ns/col/plugins/lookup/deprecated.py | 22 ++++++++++++++++ .../ansible-test-sanity-pylint/expected.txt | 1 + .../ansible-test-sanity-pylint/runme.sh | 25 +++++++++++++++++++ .../sanity/pylint/plugins/deprecated.py | 7 +++++- 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/20221021-deprecated-sanity.yml create mode 100644 test/integration/targets/ansible-test-sanity-pylint/aliases create mode 100644 test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/galaxy.yml create mode 100644 test/integration/targets/ansible-test-sanity-pylint/ansible_collections/ns/col/plugins/lookup/deprecated.py create mode 100644 test/integration/targets/ansible-test-sanity-pylint/expected.txt create mode 100755 test/integration/targets/ansible-test-sanity-pylint/runme.sh diff --git a/changelogs/fragments/20221021-deprecated-sanity.yml b/changelogs/fragments/20221021-deprecated-sanity.yml new file mode 100644 index 00000000000..5973fb3b01f --- /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 00000000000..7741d444515 --- /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 00000000000..53a7727982d --- /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 00000000000..b7908b6cbe5 --- /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 00000000000..df7bbc20698 --- /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 00000000000..72190bfaa0f --- /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 79b8bf1569f..821bcefbc43 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):