Code cleanup in ansible-test. (#74529)

* Fix get_available_python_versions calls.
* Make run_playbook vars optional.
* Use ansible_pipelining in inventory.
* Fix type hint.
* Fix order of conditional evaluation.
* Remove unused ibmi platform.
* Add changelog fragment.
pull/74531/head
Matt Clay 3 years ago committed by GitHub
parent ca507ff477
commit fb0d5609cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- ansible-test - Minor code cleanup.

@ -298,10 +298,13 @@ def get_collection_detail(args, python): # type: (EnvironmentConfig, str) -> Co
return detail
def run_playbook(args, inventory_path, playbook, run_playbook_vars): # type: (CommonConfig, str, str, t.Dict[str, t.Any]) -> None
def run_playbook(args, inventory_path, playbook, run_playbook_vars=None): # type: (CommonConfig, str, str, t.Optional[t.Dict[str, t.Any]]) -> None
"""Run the specified playbook using the given inventory file and playbook variables."""
playbook_path = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'playbooks', playbook)
command = ['ansible-playbook', '-i', inventory_path, playbook_path, '-e', json.dumps(run_playbook_vars)]
command = ['ansible-playbook', '-i', inventory_path, playbook_path]
if run_playbook_vars:
command.extend(['-e', json.dumps(run_playbook_vars)])
if args.verbosity:
command.append('-%s' % ('v' * args.verbosity))

@ -77,7 +77,6 @@ class AnsibleCoreCI:
),
ibmps=(
'aix',
'ibmi',
),
parallels=(
'macos',

@ -477,7 +477,7 @@ def delegate_remote(args, exclude, require):
# AIX cp and GNU cp provide different options, no way could be found to have a common
# pattern and achieve the same goal
cp_opts = '-hr' if remote.platform in ['aix', 'ibmi'] else '-a'
cp_opts = '-hr' if remote.platform == 'aix' else '-a'
try:
command = 'rm -rf {0} && mkdir {0} && cp {1} {2}/* {0}/ && chmod -R a+r {0}'.format(remote_temp_path, cp_opts, remote_results_root)

@ -52,10 +52,6 @@ from .test import (
TestTimeout,
)
from .executor import (
SUPPORTED_PYTHON_VERSIONS,
)
from .ci import (
get_ci_provider,
)
@ -115,7 +111,7 @@ def show_dump_env(args):
executable=sys.executable,
version=platform.python_version(),
),
interpreters=get_available_python_versions(SUPPORTED_PYTHON_VERSIONS),
interpreters=get_available_python_versions(),
)
if args.show:

@ -225,7 +225,7 @@ class ManagePosixCI:
self.become = ['sudo', '-in', 'PATH=/usr/local/bin:$PATH']
elif self.core_ci.platform == 'rhel':
self.become = ['sudo', '-in', 'bash', '-c']
elif self.core_ci.platform in ['aix', 'ibmi']:
elif self.core_ci.platform == 'aix':
self.become = []
if self.become is None:

@ -121,7 +121,7 @@ def command_sanity(args):
display.info(test.name)
continue
available_versions = sorted(get_available_python_versions(SUPPORTED_PYTHON_VERSIONS).keys())
available_versions = sorted(get_available_python_versions().keys())
if args.python:
# specific version selected

@ -248,7 +248,7 @@ def generate_ssh_inventory(ssh_connections): # type: (t.List[SshConnectionDetai
ansible_user=ssh.user,
ansible_ssh_private_key_file=os.path.abspath(ssh.identity_file),
ansible_connection='ssh',
ansible_ssh_pipelining='yes',
ansible_pipelining='yes',
ansible_python_interpreter=ssh.python_interpreter,
ansible_shell_type=ssh.shell_type,
ansible_ssh_extra_args='-o UserKnownHostsFile=/dev/null', # avoid changing the test environment

@ -129,7 +129,7 @@ def command_units(args):
test_sets = []
available_versions = sorted(get_available_python_versions(list(SUPPORTED_PYTHON_VERSIONS)).keys())
available_versions = sorted(get_available_python_versions().keys())
for version in SUPPORTED_PYTHON_VERSIONS:
# run all versions unless version given, in which case run only that version

@ -246,15 +246,15 @@ def get_ansible_version(): # type: () -> str
return ansible_version
def get_available_python_versions(versions): # type: (t.List[str]) -> t.Dict[str, str]
"""Return a dictionary indicating which of the requested Python versions are available."""
def get_available_python_versions(): # type: () -> t.Dict[str, str]
"""Return a dictionary indicating which supported Python versions are available."""
try:
return get_available_python_versions.result
except AttributeError:
pass
get_available_python_versions.result = dict((version, path) for version, path in
((version, find_python(version, required=False)) for version in versions) if path)
((version, find_python(version, required=False)) for version in SUPPORTED_PYTHON_VERSIONS) if path)
return get_available_python_versions.result

@ -53,7 +53,7 @@ NETWORK_COMPLETION = {} # type: t.Dict[str, t.Dict[str, str]]
class ShellScriptTemplate:
"""A simple substition template for shell scripts."""
def __init__(self, template): # type: (str) -> None
def __init__(self, template): # type: (t.Text) -> None
self.template = template
def substitute(self, **kwargs):
@ -427,7 +427,7 @@ def intercept_command(args, cmd, target_name, env, capture=False, data=None, cwd
env['ANSIBLE_TEST_PYTHON_VERSION'] = version
env['ANSIBLE_TEST_PYTHON_INTERPRETER'] = interpreter
if args.coverage and not disable_coverage:
if not disable_coverage and args.coverage:
# add the necessary environment variables to enable code coverage collection
env.update(get_coverage_environment(args, target_name, version, temp_path, module_coverage,
remote_temp_path=remote_temp_path))

@ -16,7 +16,6 @@ from .util import (
find_python,
SubprocessError,
get_available_python_versions,
SUPPORTED_PYTHON_VERSIONS,
ANSIBLE_TEST_DATA_ROOT,
display,
remove_tree,
@ -63,7 +62,7 @@ def create_virtual_environment(args, # type: EnvironmentConfig
display.info('Created Python %s virtual environment using "virtualenv": %s' % (version, path), verbosity=1)
return True
available_pythons = get_available_python_versions(SUPPORTED_PYTHON_VERSIONS)
available_pythons = get_available_python_versions()
for available_python_version, available_python_interpreter in sorted(available_pythons.items()):
virtualenv_version = get_virtualenv_version(args, available_python_interpreter)

Loading…
Cancel
Save