Set ansible-test min controller Python to 3.8. (#74395)

- Version neutral sanity tests now require Python 3.8 or later.
- Unit tests for controller-only code now require Python 3.8 or later.
This commit is contained in:
Matt Clay 2021-04-23 00:26:19 -07:00 committed by GitHub
parent f541c0af23
commit 6cfe36fa1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 24 deletions

View file

@ -0,0 +1,3 @@
major_changes:
- ansible-test - Version neutral sanity tests now require Python 3.8 or later.
- ansible-test - Unit tests for controller-only code now require Python 3.8 or later.

View file

@ -7,8 +7,8 @@ cd "${WORK_DIR}/ansible_collections/ns/col"
# rename the sanity ignore file to match the current ansible version and update import ignores with the python version
ansible_version="$(python -c 'import ansible.release; print(".".join(ansible.release.__version__.split(".")[:2]))')"
if [ "${ANSIBLE_TEST_PYTHON_VERSION}" == "2.6" ]; then
# Non-module/module_utils plugins are not checked on this remote-only Python versions
if [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^2\. ]] || [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^3\.[567] ]]; then
# Non-module/module_utils plugins are not checked on these remote-only Python versions
sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" | grep -v 'plugins/[^m].* import' > "tests/sanity/ignore-${ansible_version}.txt"
else
sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" > "tests/sanity/ignore-${ansible_version}.txt"

View file

@ -7,8 +7,8 @@ cd "${WORK_DIR}/ansible_collections/ns/col"
# rename the sanity ignore file to match the current ansible version and update import ignores with the python version
ansible_version="$(python -c 'import ansible.release; print(".".join(ansible.release.__version__.split(".")[:2]))')"
if [ "${ANSIBLE_TEST_PYTHON_VERSION}" == "2.6" ]; then
# Non-module/module_utils plugins are not checked on this remote-only Python versions
if [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^2\. ]] || [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^3\.[567] ]]; then
# Non-module/module_utils plugins are not checked on these remote-only Python versions
sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" | grep -v 'plugins/[^m].* import' > "tests/sanity/ignore-${ansible_version}.txt"
else
sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" > "tests/sanity/ignore-${ansible_version}.txt"

View file

@ -31,6 +31,8 @@ from ..util import (
paths_to_dirs,
get_ansible_version,
str_to_version,
SUPPORTED_PYTHON_VERSIONS,
CONTROLLER_PYTHON_VERSIONS,
)
from ..util_common import (
@ -54,7 +56,6 @@ from ..executor import (
AllTargetsSkipped,
Delegate,
install_command_requirements,
SUPPORTED_PYTHON_VERSIONS,
)
from ..config import (
@ -659,7 +660,7 @@ class SanityTest(ABC):
@property
def supported_python_versions(self): # type: () -> t.Optional[t.Tuple[str, ...]]
"""A tuple of supported Python versions or None if the test does not depend on specific Python versions."""
return tuple(python_version for python_version in SUPPORTED_PYTHON_VERSIONS if str_to_version(python_version) >= (3, 6))
return CONTROLLER_PYTHON_VERSIONS
def filter_targets(self, targets): # type: (t.List[TestTarget]) -> t.List[TestTarget] # pylint: disable=unused-argument
"""Return the given list of test targets, filtered to include only those relevant for the test."""

View file

@ -87,6 +87,10 @@ class ImportTest(SanityMultipleVersion):
:type python_version: str
:rtype: TestResult
"""
settings = self.load_processor(args, python_version)
paths = [target.path for target in targets.include]
capture_pip = args.verbosity < 2
python = find_python(python_version)
@ -97,10 +101,6 @@ class ImportTest(SanityMultipleVersion):
pip = generate_pip_command(python)
run_command(args, generate_pip_install(pip, '', packages=['virtualenv']), capture=capture_pip)
settings = self.load_processor(args, python_version)
paths = [target.path for target in targets.include]
env = ansible_environment(args, color=False)
temp_root = os.path.join(ResultType.TMP.path, 'sanity', 'import')

View file

@ -17,9 +17,10 @@ from ..util import (
is_subdir,
SubprocessError,
SUPPORTED_PYTHON_VERSIONS,
CONTROLLER_MIN_PYTHON_VERSION,
CONTROLLER_PYTHON_VERSIONS,
REMOTE_ONLY_PYTHON_VERSIONS,
ANSIBLE_LIB_ROOT,
str_to_version,
version_to_str,
)
from ..util_common import (
@ -91,15 +92,13 @@ def command_units(args):
TestContext.controller: controller_paths,
}
# temporary definition of "remote" python versions until the full split controller/remote implementation is in place
controller_min_python_version = (3, 8)
remote_only_python_versions = tuple(version for version in SUPPORTED_PYTHON_VERSIONS if str_to_version(version) < controller_min_python_version)
if not paths:
raise AllTargetsSkipped()
if args.python and args.python in remote_only_python_versions and not remote_paths:
raise AllTargetsSkipped()
if args.python and args.python in REMOTE_ONLY_PYTHON_VERSIONS:
if not remote_paths:
display.warning('Python %s is only supported by module and module_utils unit tests, but none were selected.' % args.python)
raise AllTargetsSkipped()
if args.delegate:
raise Delegate(require=changes, exclude=args.exclude)
@ -116,8 +115,9 @@ def command_units(args):
test_candidates = []
for test_context, paths in test_context_paths.items():
if test_context == TestContext.controller and version in remote_only_python_versions:
continue
if test_context == TestContext.controller:
if version not in CONTROLLER_PYTHON_VERSIONS:
continue
if not paths:
continue
@ -126,7 +126,7 @@ def command_units(args):
env.update(
PYTHONPATH=get_units_ansible_python_path(args, test_context),
ANSIBLE_CONTROLLER_MIN_PYTHON_VERSION=version_to_str(controller_min_python_version),
ANSIBLE_CONTROLLER_MIN_PYTHON_VERSION=CONTROLLER_MIN_PYTHON_VERSION,
)
test_candidates.append((test_context, version, paths, env))

View file

@ -113,9 +113,7 @@ MODE_FILE_WRITE = MODE_FILE | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH
MODE_DIRECTORY = MODE_READ | stat.S_IWUSR | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
MODE_DIRECTORY_WRITE = MODE_DIRECTORY | stat.S_IWGRP | stat.S_IWOTH
REMOTE_ONLY_PYTHON_VERSIONS = (
'2.6',
)
CONTROLLER_MIN_PYTHON_VERSION = '3.8'
SUPPORTED_PYTHON_VERSIONS = (
'2.6',
@ -904,3 +902,6 @@ def get_host_ip():
display = Display() # pylint: disable=locally-disabled, invalid-name
CONTROLLER_PYTHON_VERSIONS = tuple(version for version in SUPPORTED_PYTHON_VERSIONS if str_to_version(version) >= str_to_version(CONTROLLER_MIN_PYTHON_VERSION))
REMOTE_ONLY_PYTHON_VERSIONS = tuple(version for version in SUPPORTED_PYTHON_VERSIONS if str_to_version(version) < str_to_version(CONTROLLER_MIN_PYTHON_VERSION))