Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup in ansible-test. #74529

Merged
merged 7 commits into from May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/ansible-test-code-cleanup.yml
@@ -0,0 +1,2 @@
minor_changes:
- ansible-test - Minor code cleanup.
7 changes: 5 additions & 2 deletions test/lib/ansible_test/_internal/ansible_util.py
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion test/lib/ansible_test/_internal/core_ci.py
Expand Up @@ -77,7 +77,6 @@ class AnsibleCoreCI:
),
ibmps=(
'aix',
'ibmi',
),
parallels=(
'macos',
Expand Down
2 changes: 1 addition & 1 deletion test/lib/ansible_test/_internal/delegation.py
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions test/lib/ansible_test/_internal/env.py
Expand Up @@ -52,10 +52,6 @@
TestTimeout,
)

from .executor import (
SUPPORTED_PYTHON_VERSIONS,
)

from .ci import (
get_ci_provider,
)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/lib/ansible_test/_internal/manage_ci.py
Expand Up @@ -225,7 +225,7 @@ def __init__(self, core_ci):
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:
Expand Down
2 changes: 1 addition & 1 deletion test/lib/ansible_test/_internal/sanity/__init__.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/lib/ansible_test/_internal/ssh.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/lib/ansible_test/_internal/units/__init__.py
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/lib/ansible_test/_internal/util.py
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/lib/ansible_test/_internal/util_common.py
Expand Up @@ -53,7 +53,7 @@

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):
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions test/lib/ansible_test/_internal/venv.py
Expand Up @@ -16,7 +16,6 @@
find_python,
SubprocessError,
get_available_python_versions,
SUPPORTED_PYTHON_VERSIONS,
ANSIBLE_TEST_DATA_ROOT,
display,
remove_tree,
Expand Down Expand Up @@ -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)
Expand Down