From 9b5c782a0b173e1939f6f3c07a62662ab7527a2a Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 14 Dec 2016 19:48:30 -0800 Subject: [PATCH] Use `docker pull` by default in ansible-test. --- test/runner/lib/delegation.py | 28 ++++++++++++++++++++++++++++ test/runner/lib/executor.py | 1 + test/runner/test.py | 17 ++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/test/runner/lib/delegation.py b/test/runner/lib/delegation.py index 8cd16426550..488e69e2f70 100644 --- a/test/runner/lib/delegation.py +++ b/test/runner/lib/delegation.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function import os import sys +import time import lib.pytar import lib.thread @@ -12,6 +13,7 @@ from lib.executor import ( SUPPORTED_PYTHON_VERSIONS, EnvironmentConfig, IntegrationConfig, + SubprocessError, ShellConfig, TestConfig, create_shell_command, @@ -28,6 +30,7 @@ from lib.manage_ci import ( from lib.util import ( ApplicationError, run_command, + display, ) BUFFER_SIZE = 256 * 256 @@ -99,6 +102,11 @@ def delegate_docker(args, exclude, require): test_image = args.docker privileged = args.docker_privileged + if util_image: + docker_pull(args, util_image) + + docker_pull(args, test_image) + util_id = None test_id = None @@ -195,6 +203,26 @@ def delegate_docker(args, exclude, require): capture=True) +def docker_pull(args, image): + """ + :type args: EnvironmentConfig + :type image: str + """ + if not args.docker_pull: + display.warning('Skipping docker pull for "%s". Image may be out-of-date.' % image) + return + + for _ in range(1, 10): + try: + run_command(args, ['docker', 'pull', image]) + return + except SubprocessError: + display.warning('Failed to pull docker image "%s". Waiting a few seconds before trying again.' % image) + time.sleep(3) + + raise ApplicationError('Failed to pull docker image "%s".' % image) + + def docker_put(args, container_id, src, dst): """ :type args: EnvironmentConfig diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index 80a8ce225ca..3610120951f 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -1103,6 +1103,7 @@ class EnvironmentConfig(CommonConfig): self.docker_privileged = args.docker_privileged if 'docker_privileged' in args else False # type: bool self.docker_util = docker_qualify_image(args.docker_util if 'docker_util' in args else None) # type: str | None + self.docker_pull = args.docker_pull if 'docker_pull' in args else False # type: bool self.tox_sitepackages = args.tox_sitepackages # type: bool diff --git a/test/runner/test.py b/test/runner/test.py index 810adff7c38..7f61d3a847e 100755 --- a/test/runner/test.py +++ b/test/runner/test.py @@ -224,6 +224,8 @@ def parse_args(): action='store_true', help='collect tests but do not execute them') + add_extra_docker_options(units, integration=False) + compiler = subparsers.add_parser('compile', parents=[test], help='compile tests') @@ -237,6 +239,8 @@ def parse_args(): choices=COMPILE_PYTHON_VERSIONS, help='python version: %s' % ', '.join(COMPILE_PYTHON_VERSIONS)) + add_extra_docker_options(compiler, integration=False) + sanity = subparsers.add_parser('sanity', parents=[test], help='sanity tests') @@ -266,6 +270,8 @@ def parse_args(): choices=SUPPORTED_PYTHON_VERSIONS, help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS)) + add_extra_docker_options(sanity, integration=False) + shell = subparsers.add_parser('shell', parents=[common], help='open an interactive shell') @@ -423,12 +429,21 @@ def add_environments(parser, tox_version=False, tox_only=False): default='prod') -def add_extra_docker_options(parser): +def add_extra_docker_options(parser, integration=True): """ :type parser: argparse.ArgumentParser + :type integration: bool """ docker = parser.add_argument_group(title='docker arguments') + docker.add_argument('--docker-no-pull', + action='store_false', + dest='docker_pull', + help='do not explicitly pull the latest docker images') + + if not integration: + return + docker.add_argument('--docker-util', metavar='IMAGE', default='httptester',