From f944bd2358763acfd07489c93f3e6e90de5c1d18 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 30 Jul 2019 23:29:28 -0700 Subject: [PATCH] Update ansible-test to properly skip unit tests. Unit tests will no longer run on "remote only" Python versions (2.6) for tests which are not "remote" (modules and module_utils). --- test/runner/lib/executor.py | 25 +++++++++++++++++-- test/runner/lib/provider/layout/__init__.py | 2 ++ test/runner/lib/provider/layout/ansible.py | 1 + test/runner/lib/provider/layout/collection.py | 3 ++- test/utils/shippable/units.sh | 9 ------- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index 87884b8ce20..aad1a971318 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -60,6 +60,7 @@ from lib.util import ( cmd_quote, ANSIBLE_ROOT, get_available_python_versions, + is_subdir, ) from lib.util_common import ( @@ -134,6 +135,10 @@ from lib.data import ( data_context, ) +REMOTE_ONLY_PYTHON_VERSIONS = ( + '2.6', +) + SUPPORTED_PYTHON_VERSIONS = ( '2.6', '2.7', @@ -1324,7 +1329,15 @@ def command_units(args): require = args.require + changes include = walk_internal_targets(walk_units_targets(), args.include, args.exclude, require) - if not include: + paths = [target.path for target in include] + remote_paths = [path for path in paths + if is_subdir(path, data_context().content.unit_module_path) + or is_subdir(path, data_context().content.unit_module_utils_path)] + + if not paths: + raise AllTargetsSkipped() + + if args.python and args.python in REMOTE_ONLY_PYTHON_VERSIONS and not remote_paths: raise AllTargetsSkipped() if args.delegate: @@ -1379,7 +1392,15 @@ def command_units(args): if args.verbosity: cmd.append('-' + ('v' * args.verbosity)) - cmd += [target.path for target in include] + if version in REMOTE_ONLY_PYTHON_VERSIONS: + test_paths = remote_paths + else: + test_paths = paths + + if not test_paths: + continue + + cmd.extend(test_paths) version_commands.append((version, cmd, env)) diff --git a/test/runner/lib/provider/layout/__init__.py b/test/runner/lib/provider/layout/__init__.py index 1b89fb6fa30..1a568743053 100644 --- a/test/runner/lib/provider/layout/__init__.py +++ b/test/runner/lib/provider/layout/__init__.py @@ -80,6 +80,7 @@ class ContentLayout(Layout): util_path=None, # type: t.Optional[str] unit_path=None, # type: t.Optional[str] unit_module_path=None, # type: t.Optional[str] + unit_module_utils_path=None, # type: t.Optional[str] integration_path=None, # type: t.Optional[str] ): # type: (...) -> None super(ContentLayout, self).__init__(root, paths) @@ -91,6 +92,7 @@ class ContentLayout(Layout): self.util_path = util_path self.unit_path = unit_path self.unit_module_path = unit_module_path + self.unit_module_utils_path = unit_module_utils_path self.integration_path = integration_path self.is_ansible = root == ANSIBLE_ROOT diff --git a/test/runner/lib/provider/layout/ansible.py b/test/runner/lib/provider/layout/ansible.py index 71bb0a2605e..8ff4a3d1f8c 100644 --- a/test/runner/lib/provider/layout/ansible.py +++ b/test/runner/lib/provider/layout/ansible.py @@ -41,5 +41,6 @@ class AnsibleLayout(LayoutProvider): util_path='test/utils', unit_path='test/units', unit_module_path='test/units/modules', + unit_module_utils_path='test/units/module_utils', integration_path='test/integration', ) diff --git a/test/runner/lib/provider/layout/collection.py b/test/runner/lib/provider/layout/collection.py index 1becae77090..fb0aa16e4a4 100644 --- a/test/runner/lib/provider/layout/collection.py +++ b/test/runner/lib/provider/layout/collection.py @@ -55,6 +55,7 @@ class CollectionLayout(LayoutProvider): ), util_path='test/util', unit_path='test/unit', - unit_module_path='test/units/plugins/modules', + unit_module_path='test/unit/plugins/modules', + unit_module_utils_path='test/unit/plugins/module_utils', integration_path='test/integration', ) diff --git a/test/utils/shippable/units.sh b/test/utils/shippable/units.sh index 9ebab415e58..27d678745c2 100755 --- a/test/utils/shippable/units.sh +++ b/test/utils/shippable/units.sh @@ -15,14 +15,5 @@ fi ansible-test env --timeout "${timeout}" --color -v -if [[ "${version}" = "2.6" ]]; then - # Python 2.6 is only supported for modules and module_utils. - # Eventually this logic will move into ansible-test itself. - targets=("test/units/(modules|module_utils)/") -else - targets=("test/units/") -fi - # shellcheck disable=SC2086 ansible-test units --color -v --docker default --python "${version}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ - "${targets[@]}" \