ansible-test - Fix sanity traceback with `-e` opt (#81271)

Also remove redundant warning about missing programs.

Includes integration tests to verify `-e` does not traceback.
pull/81273/head
Matt Clay 1 year ago committed by GitHub
parent 39ef570e16
commit 3f7bf0bcd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- ansible-test - Fix several possible tracebacks when using the ``-e`` option with sanity tests.
- ansible-test - Remove redundant warning about missing programs before attempting to execute them.

@ -1,5 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eux
ansible-test sanity --color --allow-disabled -e "${@}"
set +x
source ../collection/setup.sh source ../collection/setup.sh
set -x set -x

@ -263,7 +263,7 @@ def command_sanity(args: SanityConfig) -> None:
virtualenv_python = create_sanity_virtualenv(args, test_profile.python, test.name) virtualenv_python = create_sanity_virtualenv(args, test_profile.python, test.name)
if virtualenv_python: if virtualenv_python:
virtualenv_yaml = check_sanity_virtualenv_yaml(virtualenv_python) virtualenv_yaml = args.explain or check_sanity_virtualenv_yaml(virtualenv_python)
if test.require_libyaml and not virtualenv_yaml: if test.require_libyaml and not virtualenv_yaml:
result = SanitySkipped(test.name) result = SanitySkipped(test.name)
@ -1179,20 +1179,23 @@ def create_sanity_virtualenv(
run_pip(args, virtualenv_python, commands, None) # create_sanity_virtualenv() run_pip(args, virtualenv_python, commands, None) # create_sanity_virtualenv()
write_text_file(meta_install, virtualenv_install) if not args.explain:
write_text_file(meta_install, virtualenv_install)
# false positive: pylint: disable=no-member # false positive: pylint: disable=no-member
if any(isinstance(command, PipInstall) and command.has_package('pyyaml') for command in commands): if any(isinstance(command, PipInstall) and command.has_package('pyyaml') for command in commands):
virtualenv_yaml = yamlcheck(virtualenv_python) virtualenv_yaml = yamlcheck(virtualenv_python, args.explain)
else: else:
virtualenv_yaml = None virtualenv_yaml = None
write_json_file(meta_yaml, virtualenv_yaml) if not args.explain:
write_json_file(meta_yaml, virtualenv_yaml)
created_venvs.append(f'{label}-{python.version}') created_venvs.append(f'{label}-{python.version}')
# touch the marker to keep track of when the virtualenv was last used if not args.explain:
pathlib.Path(virtualenv_marker).touch() # touch the marker to keep track of when the virtualenv was last used
pathlib.Path(virtualenv_marker).touch()
return virtualenv_python return virtualenv_python

@ -113,6 +113,9 @@ class AnsibleDocTest(SanitySingleVersion):
summary = 'Output on stderr from ansible-doc is considered an error.\n\n%s' % SubprocessError(cmd, stderr=stderr) summary = 'Output on stderr from ansible-doc is considered an error.\n\n%s' % SubprocessError(cmd, stderr=stderr)
return SanityFailure(self.name, summary=summary) return SanityFailure(self.name, summary=summary)
if args.explain:
continue
plugin_list_json = json.loads(stdout) plugin_list_json = json.loads(stdout)
doc_targets[doc_type] = [] doc_targets[doc_type] = []
for plugin_name, plugin_value in sorted(plugin_list_json.items()): for plugin_name, plugin_value in sorted(plugin_list_json.items()):

@ -146,7 +146,7 @@ class ImportTest(SanityMultipleVersion):
display.warning(f'Skipping sanity test "{self.name}" 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) return SanitySkipped(self.name, python.version)
virtualenv_yaml = check_sanity_virtualenv_yaml(virtualenv_python) virtualenv_yaml = args.explain or check_sanity_virtualenv_yaml(virtualenv_python)
if virtualenv_yaml is False: 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.') display.warning(f'Sanity test "{self.name}" ({import_type}) on Python {python.version} may be slow due to missing libyaml support in PyYAML.')

@ -168,6 +168,9 @@ class MypyTest(SanityMultipleVersion):
# However, it will also report issues on those files, which is not the desired behavior. # However, it will also report issues on those files, which is not the desired behavior.
messages = [message for message in messages if message.path in paths_set] messages = [message for message in messages if message.path in paths_set]
if args.explain:
return SanitySuccess(self.name, python_version=python.version)
results = settings.process_errors(messages, paths) results = settings.process_errors(messages, paths)
if results: if results:
@ -250,7 +253,7 @@ class MypyTest(SanityMultipleVersion):
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+):((?P<column>[0-9]+):)? (?P<level>[^:]+): (?P<message>.*)$' pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+):((?P<column>[0-9]+):)? (?P<level>[^:]+): (?P<message>.*)$'
parsed = parse_to_list_of_dict(pattern, stdout) parsed = parse_to_list_of_dict(pattern, stdout or '')
messages = [SanityMessage( messages = [SanityMessage(
level=r['level'], level=r['level'],

@ -433,7 +433,7 @@ def raw_command(
display.info(f'{description}: {escaped_cmd}', verbosity=cmd_verbosity, truncate=True) display.info(f'{description}: {escaped_cmd}', verbosity=cmd_verbosity, truncate=True)
display.info('Working directory: %s' % cwd, verbosity=2) display.info('Working directory: %s' % cwd, verbosity=2)
program = find_executable(cmd[0], cwd=cwd, path=env['PATH'], required='warning') program = find_executable(cmd[0], cwd=cwd, path=env['PATH'], required=False)
if program: if program:
display.info('Program found: %s' % program, verbosity=2) display.info('Program found: %s' % program, verbosity=2)

@ -498,9 +498,14 @@ def run_command(
) )
def yamlcheck(python: PythonConfig) -> t.Optional[bool]: def yamlcheck(python: PythonConfig, explain: bool = False) -> t.Optional[bool]:
"""Return True if PyYAML has libyaml support, False if it does not and None if it was not found.""" """Return True if PyYAML has libyaml support, False if it does not and None if it was not found."""
result = json.loads(raw_command([python.path, os.path.join(ANSIBLE_TEST_TARGET_TOOLS_ROOT, 'yamlcheck.py')], capture=True)[0]) stdout = raw_command([python.path, os.path.join(ANSIBLE_TEST_TARGET_TOOLS_ROOT, 'yamlcheck.py')], capture=True, explain=explain)[0]
if explain:
return None
result = json.loads(stdout)
if not result['yaml']: if not result['yaml']:
return None return None

Loading…
Cancel
Save