Use docker pull by default in ansible-test.

This commit is contained in:
Matt Clay 2016-12-14 19:48:30 -08:00
parent 80c559bdef
commit 9b5c782a0b
3 changed files with 45 additions and 1 deletions

View file

@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function
import os import os
import sys import sys
import time
import lib.pytar import lib.pytar
import lib.thread import lib.thread
@ -12,6 +13,7 @@ from lib.executor import (
SUPPORTED_PYTHON_VERSIONS, SUPPORTED_PYTHON_VERSIONS,
EnvironmentConfig, EnvironmentConfig,
IntegrationConfig, IntegrationConfig,
SubprocessError,
ShellConfig, ShellConfig,
TestConfig, TestConfig,
create_shell_command, create_shell_command,
@ -28,6 +30,7 @@ from lib.manage_ci import (
from lib.util import ( from lib.util import (
ApplicationError, ApplicationError,
run_command, run_command,
display,
) )
BUFFER_SIZE = 256 * 256 BUFFER_SIZE = 256 * 256
@ -99,6 +102,11 @@ def delegate_docker(args, exclude, require):
test_image = args.docker test_image = args.docker
privileged = args.docker_privileged privileged = args.docker_privileged
if util_image:
docker_pull(args, util_image)
docker_pull(args, test_image)
util_id = None util_id = None
test_id = None test_id = None
@ -195,6 +203,26 @@ def delegate_docker(args, exclude, require):
capture=True) 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): def docker_put(args, container_id, src, dst):
""" """
:type args: EnvironmentConfig :type args: EnvironmentConfig

View file

@ -1103,6 +1103,7 @@ class EnvironmentConfig(CommonConfig):
self.docker_privileged = args.docker_privileged if 'docker_privileged' in args else False # type: bool 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_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 self.tox_sitepackages = args.tox_sitepackages # type: bool

View file

@ -224,6 +224,8 @@ def parse_args():
action='store_true', action='store_true',
help='collect tests but do not execute them') help='collect tests but do not execute them')
add_extra_docker_options(units, integration=False)
compiler = subparsers.add_parser('compile', compiler = subparsers.add_parser('compile',
parents=[test], parents=[test],
help='compile tests') help='compile tests')
@ -237,6 +239,8 @@ def parse_args():
choices=COMPILE_PYTHON_VERSIONS, choices=COMPILE_PYTHON_VERSIONS,
help='python version: %s' % ', '.join(COMPILE_PYTHON_VERSIONS)) help='python version: %s' % ', '.join(COMPILE_PYTHON_VERSIONS))
add_extra_docker_options(compiler, integration=False)
sanity = subparsers.add_parser('sanity', sanity = subparsers.add_parser('sanity',
parents=[test], parents=[test],
help='sanity tests') help='sanity tests')
@ -266,6 +270,8 @@ def parse_args():
choices=SUPPORTED_PYTHON_VERSIONS, choices=SUPPORTED_PYTHON_VERSIONS,
help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS)) help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS))
add_extra_docker_options(sanity, integration=False)
shell = subparsers.add_parser('shell', shell = subparsers.add_parser('shell',
parents=[common], parents=[common],
help='open an interactive shell') help='open an interactive shell')
@ -423,12 +429,21 @@ def add_environments(parser, tox_version=False, tox_only=False):
default='prod') default='prod')
def add_extra_docker_options(parser): def add_extra_docker_options(parser, integration=True):
""" """
:type parser: argparse.ArgumentParser :type parser: argparse.ArgumentParser
:type integration: bool
""" """
docker = parser.add_argument_group(title='docker arguments') 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', docker.add_argument('--docker-util',
metavar='IMAGE', metavar='IMAGE',
default='httptester', default='httptester',