Add PyYAML check for libyaml support.

pull/57439/head
Matt Clay 6 years ago
parent d758d5bab1
commit 817ec5ab48

@ -2,6 +2,7 @@
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import json
import os import os
from lib.constants import ( from lib.constants import (
@ -10,14 +11,21 @@ from lib.constants import (
from lib.util import ( from lib.util import (
common_environment, common_environment,
display,
find_python,
run_command,
ApplicationError, ApplicationError,
) )
from lib.config import ( from lib.config import (
IntegrationConfig, IntegrationConfig,
EnvironmentConfig,
) )
CHECK_YAML_VERSIONS = {}
def ansible_environment(args, color=True, ansible_config=None): def ansible_environment(args, color=True, ansible_config=None):
""" """
:type args: CommonConfig :type args: CommonConfig
@ -65,3 +73,28 @@ def ansible_environment(args, color=True, ansible_config=None):
)) ))
return env 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)

@ -74,6 +74,7 @@ from lib.docker_util import (
from lib.ansible_util import ( from lib.ansible_util import (
ansible_environment, ansible_environment,
check_pyyaml,
) )
from lib.target import ( from lib.target import (
@ -804,6 +805,8 @@ def command_integration_filtered(args, targets, all_targets, inventory_path, pre
if setup_errors: if setup_errors:
raise ApplicationError('Found %d invalid setup aliases:\n%s' % (len(setup_errors), '\n'.join(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') test_dir = os.path.expanduser('~/ansible_testing')
if not args.explain and any('needs/ssh/' in target.aliases for target in targets): 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() sys.exit()
for version, command, env in version_commands: for version, command, env in version_commands:
check_pyyaml(args, version)
display.info('Unit test with Python %s' % version) display.info('Unit test with Python %s' % version)
try: try:

@ -23,6 +23,7 @@ from lib.util import (
from lib.ansible_util import ( from lib.ansible_util import (
ansible_environment, ansible_environment,
check_pyyaml,
) )
from lib.target import ( from lib.target import (
@ -100,6 +101,8 @@ def command_sanity(args):
if args.python and version and version != args.python_version: if args.python and version and version != args.python_version:
continue 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 '')) display.info('Sanity check using %s%s' % (test.name, ' with Python %s' % version if version else ''))
options = '' options = ''

@ -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),
)))
Loading…
Cancel
Save