summaryrefslogtreecommitdiffstats
path: root/test/lib/ansible_test/_internal/executor.py
diff options
context:
space:
mode:
authorMatt Clay <mclay@redhat.com>2020-06-10 18:39:25 +0200
committerGitHub <noreply@github.com>2020-06-10 18:39:25 +0200
commita5679d4dd1ad9c544937d98946f7bd6bf6fb2791 (patch)
tree10e1fd48dea3ae49e93787849504e6399bf6f2fd /test/lib/ansible_test/_internal/executor.py
parentFix ansible-test pip filter on Fedora 32. (diff)
downloadansible-a5679d4dd1ad9c544937d98946f7bd6bf6fb2791.tar.xz
ansible-a5679d4dd1ad9c544937d98946f7bd6bf6fb2791.zip
Additional ansible-test sanity adjustments. (#69974)
* Fix ansible-test check_pyyaml usage. * Avoid unnecessary pip commands. * Avoid pointless pip check. * Only install ansible-test requirements as needed.
Diffstat (limited to 'test/lib/ansible_test/_internal/executor.py')
-rw-r--r--test/lib/ansible_test/_internal/executor.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/test/lib/ansible_test/_internal/executor.py b/test/lib/ansible_test/_internal/executor.py
index 05614a4a28..c399cd9a9f 100644
--- a/test/lib/ansible_test/_internal/executor.py
+++ b/test/lib/ansible_test/_internal/executor.py
@@ -216,11 +216,12 @@ def get_cryptography_requirement(args, python_version): # type: (EnvironmentCon
return cryptography
-def install_command_requirements(args, python_version=None, context=None):
+def install_command_requirements(args, python_version=None, context=None, enable_pyyaml_check=False):
"""
:type args: EnvironmentConfig
:type python_version: str | None
:type context: str | None
+ :type enable_pyyaml_check: bool
"""
if not args.explain:
make_dirs(ResultType.COVERAGE.path)
@@ -251,11 +252,24 @@ def install_command_requirements(args, python_version=None, context=None):
pip = generate_pip_command(find_python(python_version))
- # make sure basic ansible-test requirements are met, including making sure that pip is recent enough to support constraints
- # virtualenvs created by older distributions may include very old pip versions, such as those created in the centos6 test container (pip 6.0.8)
- run_command(args, generate_pip_install(pip, 'ansible-test', use_constraints=False))
+ # skip packages which have aleady been installed for python_version
+
+ try:
+ package_cache = install_command_requirements.package_cache
+ except AttributeError:
+ package_cache = install_command_requirements.package_cache = {}
+
+ installed_packages = package_cache.setdefault(python_version, set())
+ skip_packages = [package for package in packages if package in installed_packages]
+
+ for package in skip_packages:
+ packages.remove(package)
+
+ installed_packages.update(packages)
if args.command != 'sanity':
+ install_ansible_test_requirements(args, pip)
+
# make sure setuptools is available before trying to install cryptography
# the installed version of setuptools affects the version of cryptography to install
run_command(args, generate_pip_install(pip, '', packages=['setuptools']))
@@ -276,10 +290,14 @@ def install_command_requirements(args, python_version=None, context=None):
commands = [cmd for cmd in commands if cmd]
+ if not commands:
+ return # no need to detect changes or run pip check since we are not making any changes
+
# only look for changes when more than one requirements file is needed
detect_pip_changes = len(commands) > 1
# first pass to install requirements, changes expected unless environment is already set up
+ install_ansible_test_requirements(args, pip)
changes = run_pip_commands(args, pip, commands, detect_pip_changes)
if changes:
@@ -300,6 +318,27 @@ def install_command_requirements(args, python_version=None, context=None):
else:
raise
+ if enable_pyyaml_check:
+ # pyyaml may have been one of the requirements that was installed, so perform an optional check for it
+ check_pyyaml(args, python_version, required=False)
+
+
+def install_ansible_test_requirements(args, pip): # type: (EnvironmentConfig, t.List[str]) -> None
+ """Install requirements for ansible-test for the given pip if not already installed."""
+ try:
+ installed = install_command_requirements.installed
+ except AttributeError:
+ installed = install_command_requirements.installed = set()
+
+ if tuple(pip) in installed:
+ return
+
+ # make sure basic ansible-test requirements are met, including making sure that pip is recent enough to support constraints
+ # virtualenvs created by older distributions may include very old pip versions, such as those created in the centos6 test container (pip 6.0.8)
+ run_command(args, generate_pip_install(pip, 'ansible-test', use_constraints=False))
+
+ installed.add(tuple(pip))
+
def run_pip_commands(args, pip, commands, detect_pip_changes=False):
"""