sanity tests - ignore pre-release versions for deprecation comparisons (#79185)

pull/80106/head
Mark Chappell 2 years ago committed by GitHub
parent 39fd899d83
commit f64e79be41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- sanity tests - updates the collection-deprecated-version tests to ignore the ``prerelease`` component of the collection version ().

@ -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

@ -0,0 +1,6 @@
namespace: ns
name: col
version:
readme: README.rst
authors:
- Ansible

@ -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 []

@ -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

@ -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

@ -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):

Loading…
Cancel
Save