ansible-test - Add `--prime-venvs` option.

pull/75747/head
Matt Clay 3 years ago
parent 178a67fd40
commit 94410789d1

@ -0,0 +1,2 @@
minor_changes:
- ansible-test - Add ``--prime-venvs`` option to create virtual environments without running tests.

@ -110,4 +110,10 @@ def do_sanity(
help='exit successfully on failed tests after saving results',
)
sanity.add_argument(
'--prime-venvs',
action='store_true',
help='prepare virtual environments without running tests'
)
add_environments(parser, completer, ControllerMode.DELEGATED, TargetMode.SANITY) # sanity

@ -215,7 +215,7 @@ def command_sanity(args):
usable_targets = settings.filter_skipped_targets(usable_targets)
sanity_targets = SanityTargets(tuple(all_targets), tuple(usable_targets))
test_needed = bool(usable_targets or test.no_targets)
test_needed = bool(usable_targets or test.no_targets or args.prime_venvs)
result = None
if test_needed and version in args.host_settings.skipped_python_versions:
@ -252,13 +252,19 @@ def command_sanity(args):
if virtualenv_yaml is False:
display.warning(f'Sanity test "{test.name}" on Python {version} may be slow due to missing libyaml support in PyYAML.')
result = test.test(args, sanity_targets, virtualenv_python)
if args.prime_venvs:
result = SanitySkipped(test.name)
else:
result = test.test(args, sanity_targets, virtualenv_python)
else:
result = SanitySkipped(test.name, version)
result.reason = f'Skipping sanity test "{test.name}" on Python {version} due to missing virtual environment support.'
elif isinstance(test, SanityVersionNeutral):
# version neutral sanity tests handle their own requirements (if any)
result = test.test(args, sanity_targets)
if args.prime_venvs:
result = SanitySkipped(test.name)
else:
# version neutral sanity tests handle their own requirements (if any)
result = test.test(args, sanity_targets)
else:
raise Exception('Unsupported test type: %s' % type(test))
elif result:

@ -10,6 +10,7 @@ from . import (
SanityFailure,
SanitySuccess,
SanityTargets,
SanitySkipped,
TARGET_SANITY_ROOT,
)
@ -48,6 +49,9 @@ class CompileTest(SanityMultipleVersion):
return [target for target in targets if os.path.splitext(target.path)[1] == '.py' or is_subdir(target.path, 'bin')]
def test(self, args, targets, python): # type: (SanityConfig, SanityTargets, PythonConfig) -> TestResult
if args.prime_venvs:
return SanitySkipped(self.name, python_version=python.version)
settings = self.load_processor(args, python.version)
paths = [target.path for target in targets.include]

@ -109,13 +109,13 @@ class ImportTest(SanityMultipleVersion):
data = '\n'.join([path for path in paths if test(path)])
if not data:
if not data and not args.prime_venvs:
continue
virtualenv_python = create_sanity_virtualenv(args, python, f'{self.name}.{import_type}', ansible=controller, coverage=args.coverage, minimize=True)
if not virtualenv_python:
display.warning(f'Skipping sanity test "{self.name}" ({import_type}) on Python {python.version} due to missing virtual environment support.')
display.warning(f'Skipping sanity test "{self.name}" on Python {python.version} due to missing virtual environment support.')
return SanitySkipped(self.name, python.version)
virtualenv_yaml = check_sanity_virtualenv_yaml(virtualenv_python)
@ -123,6 +123,9 @@ class ImportTest(SanityMultipleVersion):
if virtualenv_yaml is False:
display.warning(f'Sanity test "{self.name}" ({import_type}) on Python {python.version} may be slow due to missing libyaml support in PyYAML.')
if args.prime_venvs:
continue
env = ansible_environment(args, color=False)
env.update(
@ -170,6 +173,9 @@ class ImportTest(SanityMultipleVersion):
column=int(r['column']),
) for r in parsed]
if args.prime_venvs:
return SanitySkipped(self.name, python_version=python.version)
results = settings.process_errors(messages, paths)
if results:

@ -259,7 +259,8 @@ class SanityConfig(TestConfig):
self.list_tests = args.list_tests # type: bool
self.allow_disabled = args.allow_disabled # type: bool
self.enable_optional_errors = args.enable_optional_errors # type: bool
self.keep_git = args.keep_git
self.keep_git = args.keep_git # type: bool
self.prime_venvs = args.prime_venvs # type: bool
self.info_stderr = self.lint

Loading…
Cancel
Save