diff --git a/test/runner/lib/ansible_util.py b/test/runner/lib/ansible_util.py index c17abcf3932..f7c2abb464d 100644 --- a/test/runner/lib/ansible_util.py +++ b/test/runner/lib/ansible_util.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, print_function +import json import os from lib.constants import ( @@ -10,14 +11,21 @@ from lib.constants import ( from lib.util import ( common_environment, + display, + find_python, + run_command, ApplicationError, ) from lib.config import ( IntegrationConfig, + EnvironmentConfig, ) +CHECK_YAML_VERSIONS = {} + + def ansible_environment(args, color=True, ansible_config=None): """ :type args: CommonConfig @@ -65,3 +73,28 @@ def ansible_environment(args, color=True, ansible_config=None): )) return env + + +def check_pyyaml(args, version): + """ + :type args: EnvironmentConfig + :type version: str + """ + if version in CHECK_YAML_VERSIONS: + return + + python = find_python(version) + stdout, _dummy = run_command(args, [python, 'test/runner/yamlcheck.py'], capture=True) + + if args.explain: + return + + CHECK_YAML_VERSIONS[version] = result = json.loads(stdout) + + yaml = result['yaml'] + cloader = result['cloader'] + + if not yaml: + display.warning('PyYAML is not installed for interpreter: %s' % python) + elif not cloader: + display.warning('PyYAML will be slow due to installation without libyaml support for interpreter: %s' % python) diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index c3944301134..619f1b554c5 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -74,6 +74,7 @@ from lib.docker_util import ( from lib.ansible_util import ( ansible_environment, + check_pyyaml, ) from lib.target import ( @@ -804,6 +805,8 @@ def command_integration_filtered(args, targets, all_targets, inventory_path, pre if setup_errors: raise ApplicationError('Found %d invalid setup aliases:\n%s' % (len(setup_errors), '\n'.join(setup_errors))) + check_pyyaml(args, args.python_version) + test_dir = os.path.expanduser('~/ansible_testing') if not args.explain and any('needs/ssh/' in target.aliases for target in targets): @@ -1347,6 +1350,8 @@ def command_units(args): sys.exit() for version, command, env in version_commands: + check_pyyaml(args, version) + display.info('Unit test with Python %s' % version) try: diff --git a/test/runner/lib/sanity/__init__.py b/test/runner/lib/sanity/__init__.py index 420eb7e1ee6..00836f90092 100644 --- a/test/runner/lib/sanity/__init__.py +++ b/test/runner/lib/sanity/__init__.py @@ -23,6 +23,7 @@ from lib.util import ( from lib.ansible_util import ( ansible_environment, + check_pyyaml, ) from lib.target import ( @@ -100,6 +101,8 @@ def command_sanity(args): if args.python and version and version != args.python_version: continue + check_pyyaml(args, version or args.python_version) + display.info('Sanity check using %s%s' % (test.name, ' with Python %s' % version if version else '')) options = '' diff --git a/test/runner/yamlcheck.py b/test/runner/yamlcheck.py new file mode 100755 index 00000000000..9e9ddd451a7 --- /dev/null +++ b/test/runner/yamlcheck.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +"""Show python and pip versions.""" + +import json + +try: + import yaml +except ImportError: + yaml = None + +try: + from yaml import CLoader +except ImportError: + CLoader = None + +print(json.dumps(dict( + yaml=bool(yaml), + cloader=bool(CLoader), +)))