2016-11-30 05:21:53 +00:00
|
|
|
"""Delegate test execution to another environment."""
|
|
|
|
|
|
|
|
from __future__ import absolute_import, print_function
|
|
|
|
|
|
|
|
import os
|
2017-05-11 05:25:02 +00:00
|
|
|
import re
|
2016-11-30 05:21:53 +00:00
|
|
|
import sys
|
2017-03-15 19:17:42 +00:00
|
|
|
import tempfile
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
import lib.pytar
|
|
|
|
import lib.thread
|
|
|
|
|
|
|
|
from lib.executor import (
|
|
|
|
SUPPORTED_PYTHON_VERSIONS,
|
2018-05-09 16:24:39 +00:00
|
|
|
HTTPTESTER_HOSTS,
|
2016-11-30 05:21:53 +00:00
|
|
|
create_shell_command,
|
2018-05-09 16:24:39 +00:00
|
|
|
run_httptester,
|
|
|
|
start_httptester,
|
2016-11-30 05:21:53 +00:00
|
|
|
)
|
|
|
|
|
2017-07-06 23:14:44 +00:00
|
|
|
from lib.config import (
|
2017-03-08 08:47:21 +00:00
|
|
|
TestConfig,
|
2017-07-06 23:14:44 +00:00
|
|
|
EnvironmentConfig,
|
|
|
|
IntegrationConfig,
|
|
|
|
ShellConfig,
|
|
|
|
SanityConfig,
|
|
|
|
UnitsConfig,
|
2017-03-08 08:47:21 +00:00
|
|
|
)
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
from lib.core_ci import (
|
|
|
|
AnsibleCoreCI,
|
|
|
|
)
|
|
|
|
|
|
|
|
from lib.manage_ci import (
|
|
|
|
ManagePosixCI,
|
2018-10-13 17:44:11 +00:00
|
|
|
ManageWindowsCI,
|
2016-11-30 05:21:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
from lib.util import (
|
|
|
|
ApplicationError,
|
|
|
|
run_command,
|
2017-05-18 17:37:53 +00:00
|
|
|
common_environment,
|
|
|
|
pass_vars,
|
2018-05-09 16:24:39 +00:00
|
|
|
display,
|
2016-11-30 05:21:53 +00:00
|
|
|
)
|
|
|
|
|
2017-05-05 08:23:00 +00:00
|
|
|
from lib.docker_util import (
|
|
|
|
docker_exec,
|
|
|
|
docker_get,
|
|
|
|
docker_pull,
|
|
|
|
docker_put,
|
|
|
|
docker_rm,
|
|
|
|
docker_run,
|
2018-05-09 16:24:39 +00:00
|
|
|
docker_available,
|
2018-10-13 17:44:11 +00:00
|
|
|
docker_network_disconnect,
|
|
|
|
get_docker_networks,
|
2017-05-05 08:23:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
from lib.cloud import (
|
|
|
|
get_cloud_providers,
|
|
|
|
)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
from lib.target import (
|
|
|
|
IntegrationTarget,
|
|
|
|
)
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
def delegate(args, exclude, require, integration_targets):
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
:type args: EnvironmentConfig
|
|
|
|
:type exclude: list[str]
|
|
|
|
:type require: list[str]
|
2018-05-09 16:24:39 +00:00
|
|
|
:type integration_targets: tuple[IntegrationTarget]
|
2017-03-15 19:17:42 +00:00
|
|
|
:rtype: bool
|
|
|
|
"""
|
|
|
|
if isinstance(args, TestConfig):
|
|
|
|
with tempfile.NamedTemporaryFile(prefix='metadata-', suffix='.json', dir=os.getcwd()) as metadata_fd:
|
|
|
|
args.metadata_path = os.path.basename(metadata_fd.name)
|
|
|
|
args.metadata.to_file(args.metadata_path)
|
|
|
|
|
|
|
|
try:
|
2018-05-09 16:24:39 +00:00
|
|
|
return delegate_command(args, exclude, require, integration_targets)
|
2017-03-15 19:17:42 +00:00
|
|
|
finally:
|
|
|
|
args.metadata_path = None
|
|
|
|
else:
|
2018-05-09 16:24:39 +00:00
|
|
|
return delegate_command(args, exclude, require, integration_targets)
|
2017-03-15 19:17:42 +00:00
|
|
|
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
def delegate_command(args, exclude, require, integration_targets):
|
2017-03-15 19:17:42 +00:00
|
|
|
"""
|
|
|
|
:type args: EnvironmentConfig
|
|
|
|
:type exclude: list[str]
|
|
|
|
:type require: list[str]
|
2018-05-09 16:24:39 +00:00
|
|
|
:type integration_targets: tuple[IntegrationTarget]
|
2017-03-15 19:17:42 +00:00
|
|
|
:rtype: bool
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
if args.tox:
|
2018-05-09 16:24:39 +00:00
|
|
|
delegate_tox(args, exclude, require, integration_targets)
|
2016-11-30 05:21:53 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
if args.docker:
|
2018-05-09 16:24:39 +00:00
|
|
|
delegate_docker(args, exclude, require, integration_targets)
|
2016-11-30 05:21:53 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
if args.remote:
|
2018-05-09 16:24:39 +00:00
|
|
|
delegate_remote(args, exclude, require, integration_targets)
|
2016-11-30 05:21:53 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
def delegate_tox(args, exclude, require, integration_targets):
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
:type args: EnvironmentConfig
|
|
|
|
:type exclude: list[str]
|
|
|
|
:type require: list[str]
|
2018-05-09 16:24:39 +00:00
|
|
|
:type integration_targets: tuple[IntegrationTarget]
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
if args.python:
|
2018-10-14 06:55:15 +00:00
|
|
|
versions = (args.python_version,)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2017-10-26 07:21:46 +00:00
|
|
|
if args.python_version not in SUPPORTED_PYTHON_VERSIONS:
|
|
|
|
raise ApplicationError('tox does not support Python version %s' % args.python_version)
|
2016-11-30 05:21:53 +00:00
|
|
|
else:
|
|
|
|
versions = SUPPORTED_PYTHON_VERSIONS
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
if args.httptester:
|
|
|
|
needs_httptester = sorted(target.name for target in integration_targets if 'needs/httptester/' in target.aliases)
|
|
|
|
|
|
|
|
if needs_httptester:
|
|
|
|
display.warning('Use --docker or --remote to enable httptester for tests marked "needs/httptester": %s' % ', '.join(needs_httptester))
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
options = {
|
|
|
|
'--tox': args.tox_args,
|
2016-12-14 00:25:16 +00:00
|
|
|
'--tox-sitepackages': 0,
|
2016-11-30 05:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for version in versions:
|
2016-12-14 00:25:16 +00:00
|
|
|
tox = ['tox', '-c', 'test/runner/tox.ini', '-e', 'py' + version.replace('.', '')]
|
|
|
|
|
|
|
|
if args.tox_sitepackages:
|
|
|
|
tox.append('--sitepackages')
|
|
|
|
|
|
|
|
tox.append('--')
|
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
cmd = generate_command(args, os.path.abspath('bin/ansible-test'), options, exclude, require)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
if not args.python:
|
|
|
|
cmd += ['--python', version]
|
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
if isinstance(args, TestConfig):
|
|
|
|
if args.coverage and not args.coverage_label:
|
|
|
|
cmd += ['--coverage-label', 'tox-%s' % version]
|
|
|
|
|
2017-05-18 17:37:53 +00:00
|
|
|
env = common_environment()
|
|
|
|
|
|
|
|
# temporary solution to permit ansible-test delegated to tox to provision remote resources
|
|
|
|
optional = (
|
|
|
|
'SHIPPABLE',
|
|
|
|
'SHIPPABLE_BUILD_ID',
|
|
|
|
'SHIPPABLE_JOB_NUMBER',
|
|
|
|
)
|
|
|
|
|
|
|
|
env.update(pass_vars(required=[], optional=optional))
|
|
|
|
|
|
|
|
run_command(args, tox + cmd, env=env)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
def delegate_docker(args, exclude, require, integration_targets):
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
:type args: EnvironmentConfig
|
|
|
|
:type exclude: list[str]
|
|
|
|
:type require: list[str]
|
2018-05-09 16:24:39 +00:00
|
|
|
:type integration_targets: tuple[IntegrationTarget]
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
test_image = args.docker
|
|
|
|
privileged = args.docker_privileged
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
if isinstance(args, ShellConfig):
|
|
|
|
use_httptester = args.httptester
|
|
|
|
else:
|
|
|
|
use_httptester = args.httptester and any('needs/httptester/' in target.aliases for target in integration_targets)
|
|
|
|
|
|
|
|
if use_httptester:
|
|
|
|
docker_pull(args, args.httptester)
|
2016-12-15 03:48:30 +00:00
|
|
|
|
|
|
|
docker_pull(args, test_image)
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
httptester_id = None
|
2016-11-30 05:21:53 +00:00
|
|
|
test_id = None
|
|
|
|
|
|
|
|
options = {
|
|
|
|
'--docker': 1,
|
|
|
|
'--docker-privileged': 0,
|
|
|
|
'--docker-util': 1,
|
|
|
|
}
|
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
cmd = generate_command(args, '/root/ansible/bin/ansible-test', options, exclude, require)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
if isinstance(args, TestConfig):
|
|
|
|
if args.coverage and not args.coverage_label:
|
2018-08-17 04:16:15 +00:00
|
|
|
image_label = args.docker_raw
|
2017-05-11 05:25:02 +00:00
|
|
|
image_label = re.sub('[^a-zA-Z0-9]+', '-', image_label)
|
|
|
|
cmd += ['--coverage-label', 'docker-%s' % image_label]
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
if isinstance(args, IntegrationConfig):
|
|
|
|
if not args.allow_destructive:
|
|
|
|
cmd.append('--allow-destructive')
|
|
|
|
|
2017-01-04 19:24:56 +00:00
|
|
|
cmd_options = []
|
|
|
|
|
2017-07-07 19:37:08 +00:00
|
|
|
if isinstance(args, ShellConfig) or (isinstance(args, IntegrationConfig) and args.debug_strategy):
|
2017-01-04 19:24:56 +00:00
|
|
|
cmd_options.append('-it')
|
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
with tempfile.NamedTemporaryFile(prefix='ansible-source-', suffix='.tgz') as local_source_fd:
|
|
|
|
try:
|
|
|
|
if not args.explain:
|
2017-10-26 07:21:46 +00:00
|
|
|
if args.docker_keep_git:
|
|
|
|
tar_filter = lib.pytar.AllowGitTarFilter()
|
|
|
|
else:
|
|
|
|
tar_filter = lib.pytar.DefaultTarFilter()
|
|
|
|
|
|
|
|
lib.pytar.create_tarfile(local_source_fd.name, '.', tar_filter)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
if use_httptester:
|
|
|
|
httptester_id = run_httptester(args)
|
2016-11-30 05:21:53 +00:00
|
|
|
else:
|
2018-05-09 16:24:39 +00:00
|
|
|
httptester_id = None
|
2017-05-11 05:25:02 +00:00
|
|
|
|
|
|
|
test_options = [
|
|
|
|
'--detach',
|
|
|
|
'--volume', '/sys/fs/cgroup:/sys/fs/cgroup:ro',
|
|
|
|
'--privileged=%s' % str(privileged).lower(),
|
2016-11-30 05:21:53 +00:00
|
|
|
]
|
|
|
|
|
2018-05-01 22:47:24 +00:00
|
|
|
if args.docker_memory:
|
|
|
|
test_options.extend([
|
|
|
|
'--memory=%d' % args.docker_memory,
|
|
|
|
'--memory-swap=%d' % args.docker_memory,
|
|
|
|
])
|
|
|
|
|
2017-06-30 21:50:09 +00:00
|
|
|
docker_socket = '/var/run/docker.sock'
|
|
|
|
|
2018-08-30 18:36:57 +00:00
|
|
|
if args.docker_seccomp != 'default':
|
|
|
|
test_options += ['--security-opt', 'seccomp=%s' % args.docker_seccomp]
|
|
|
|
|
2017-06-30 21:50:09 +00:00
|
|
|
if os.path.exists(docker_socket):
|
|
|
|
test_options += ['--volume', '%s:%s' % (docker_socket, docker_socket)]
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
if httptester_id:
|
|
|
|
test_options += ['--env', 'HTTPTESTER=1']
|
|
|
|
|
|
|
|
for host in HTTPTESTER_HOSTS:
|
|
|
|
test_options += ['--link', '%s:%s' % (httptester_id, host)]
|
2017-05-05 08:23:00 +00:00
|
|
|
|
2017-07-15 02:11:25 +00:00
|
|
|
if isinstance(args, IntegrationConfig):
|
2017-05-11 05:25:02 +00:00
|
|
|
cloud_platforms = get_cloud_providers(args)
|
2017-05-05 08:23:00 +00:00
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
for cloud_platform in cloud_platforms:
|
|
|
|
test_options += cloud_platform.get_docker_run_options()
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
test_id, _ = docker_run(args, test_image, options=test_options)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
if args.explain:
|
|
|
|
test_id = 'test_id'
|
|
|
|
else:
|
|
|
|
test_id = test_id.strip()
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
# write temporary files to /root since /tmp isn't ready immediately on container start
|
|
|
|
docker_put(args, test_id, 'test/runner/setup/docker.sh', '/root/docker.sh')
|
|
|
|
docker_exec(args, test_id, ['/bin/bash', '/root/docker.sh'])
|
|
|
|
docker_put(args, test_id, local_source_fd.name, '/root/ansible.tgz')
|
|
|
|
docker_exec(args, test_id, ['mkdir', '/root/ansible'])
|
|
|
|
docker_exec(args, test_id, ['tar', 'oxzf', '/root/ansible.tgz', '-C', '/root/ansible'])
|
2017-04-27 03:21:11 +00:00
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
# docker images are only expected to have a single python version available
|
|
|
|
if isinstance(args, UnitsConfig) and not args.python:
|
|
|
|
cmd += ['--python', 'default']
|
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
# run unit tests unprivileged to prevent stray writes to the source tree
|
|
|
|
# also disconnect from the network once requirements have been installed
|
|
|
|
if isinstance(args, UnitsConfig):
|
|
|
|
writable_dirs = [
|
|
|
|
'/root/ansible/.pytest_cache',
|
|
|
|
]
|
|
|
|
|
|
|
|
docker_exec(args, test_id, ['mkdir', '-p'] + writable_dirs)
|
|
|
|
docker_exec(args, test_id, ['chmod', '777'] + writable_dirs)
|
|
|
|
|
|
|
|
docker_exec(args, test_id, ['find', '/root/ansible/test/results/', '-type', 'd', '-exec', 'chmod', '777', '{}', '+'])
|
|
|
|
|
|
|
|
docker_exec(args, test_id, ['chmod', '755', '/root'])
|
|
|
|
docker_exec(args, test_id, ['chmod', '644', '/root/ansible/%s' % args.metadata_path])
|
|
|
|
|
|
|
|
docker_exec(args, test_id, ['useradd', 'pytest', '--create-home'])
|
|
|
|
|
|
|
|
docker_exec(args, test_id, cmd + ['--requirements-mode', 'only'], options=cmd_options)
|
|
|
|
|
|
|
|
networks = get_docker_networks(args, test_id)
|
|
|
|
|
|
|
|
for network in networks:
|
|
|
|
docker_network_disconnect(args, test_id, network)
|
|
|
|
|
|
|
|
cmd += ['--requirements-mode', 'skip']
|
|
|
|
|
|
|
|
cmd_options += ['--user', 'pytest']
|
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
try:
|
|
|
|
docker_exec(args, test_id, cmd, options=cmd_options)
|
|
|
|
finally:
|
|
|
|
with tempfile.NamedTemporaryFile(prefix='ansible-result-', suffix='.tgz') as local_result_fd:
|
|
|
|
docker_exec(args, test_id, ['tar', 'czf', '/root/results.tgz', '-C', '/root/ansible/test', 'results'])
|
|
|
|
docker_get(args, test_id, '/root/results.tgz', local_result_fd.name)
|
|
|
|
run_command(args, ['tar', 'oxzf', local_result_fd.name, '-C', 'test'])
|
2016-11-30 05:21:53 +00:00
|
|
|
finally:
|
2018-05-09 16:24:39 +00:00
|
|
|
if httptester_id:
|
|
|
|
docker_rm(args, httptester_id)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2017-05-11 05:25:02 +00:00
|
|
|
if test_id:
|
|
|
|
docker_rm(args, test_id)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
def delegate_remote(args, exclude, require, integration_targets):
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
:type args: EnvironmentConfig
|
|
|
|
:type exclude: list[str]
|
|
|
|
:type require: list[str]
|
2018-05-09 16:24:39 +00:00
|
|
|
:type integration_targets: tuple[IntegrationTarget]
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
parts = args.remote.split('/', 1)
|
|
|
|
|
|
|
|
platform = parts[0]
|
|
|
|
version = parts[1]
|
|
|
|
|
2017-11-29 08:46:08 +00:00
|
|
|
core_ci = AnsibleCoreCI(args, platform, version, stage=args.remote_stage, provider=args.remote_provider)
|
2017-05-11 13:21:11 +00:00
|
|
|
success = False
|
2018-12-04 21:35:00 +00:00
|
|
|
raw = False
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
if isinstance(args, ShellConfig):
|
|
|
|
use_httptester = args.httptester
|
2018-12-04 21:35:00 +00:00
|
|
|
raw = args.raw
|
2018-05-09 16:24:39 +00:00
|
|
|
else:
|
|
|
|
use_httptester = args.httptester and any('needs/httptester/' in target.aliases for target in integration_targets)
|
|
|
|
|
|
|
|
if use_httptester and not docker_available():
|
|
|
|
display.warning('Assuming --disable-httptester since `docker` is not available.')
|
|
|
|
use_httptester = False
|
|
|
|
|
|
|
|
httptester_id = None
|
|
|
|
ssh_options = []
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
try:
|
|
|
|
core_ci.start()
|
2018-05-09 16:24:39 +00:00
|
|
|
|
|
|
|
if use_httptester:
|
|
|
|
httptester_id, ssh_options = start_httptester(args)
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
core_ci.wait()
|
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
if platform == 'windows':
|
|
|
|
# Windows doesn't need the ansible-test fluff, just run the SSH command
|
|
|
|
manage = ManageWindowsCI(core_ci)
|
|
|
|
cmd = ['powershell.exe']
|
2018-12-04 21:35:00 +00:00
|
|
|
elif raw:
|
|
|
|
manage = ManagePosixCI(core_ci)
|
|
|
|
cmd = create_shell_command(['bash'])
|
2018-10-13 17:44:11 +00:00
|
|
|
else:
|
|
|
|
options = {
|
|
|
|
'--remote': 1,
|
|
|
|
}
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
cmd = generate_command(args, 'ansible/bin/ansible-test', options, exclude, require)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
if httptester_id:
|
|
|
|
cmd += ['--inject-httptester']
|
2018-05-09 16:24:39 +00:00
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
if isinstance(args, TestConfig):
|
|
|
|
if args.coverage and not args.coverage_label:
|
|
|
|
cmd += ['--coverage-label', 'remote-%s-%s' % (platform, version)]
|
2017-05-11 05:25:02 +00:00
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
if isinstance(args, IntegrationConfig):
|
|
|
|
if not args.allow_destructive:
|
|
|
|
cmd.append('--allow-destructive')
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
# remote instances are only expected to have a single python version available
|
|
|
|
if isinstance(args, UnitsConfig) and not args.python:
|
|
|
|
cmd += ['--python', 'default']
|
2017-04-27 03:21:11 +00:00
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
manage = ManagePosixCI(core_ci)
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
manage.setup()
|
2018-12-04 21:35:00 +00:00
|
|
|
|
2017-07-15 02:11:25 +00:00
|
|
|
if isinstance(args, IntegrationConfig):
|
2017-05-05 12:01:27 +00:00
|
|
|
cloud_platforms = get_cloud_providers(args)
|
2017-05-05 08:23:00 +00:00
|
|
|
|
2017-05-05 12:01:27 +00:00
|
|
|
for cloud_platform in cloud_platforms:
|
|
|
|
ssh_options += cloud_platform.get_remote_ssh_options()
|
2017-05-05 08:23:00 +00:00
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
try:
|
2017-05-05 08:23:00 +00:00
|
|
|
manage.ssh(cmd, ssh_options)
|
2017-05-11 13:21:11 +00:00
|
|
|
success = True
|
2016-11-30 05:21:53 +00:00
|
|
|
finally:
|
2018-12-04 21:35:00 +00:00
|
|
|
download = False
|
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
if platform != 'windows':
|
2018-12-04 21:35:00 +00:00
|
|
|
download = True
|
|
|
|
|
|
|
|
if isinstance(args, ShellConfig):
|
|
|
|
if args.raw:
|
|
|
|
download = False
|
|
|
|
|
|
|
|
if download:
|
2018-10-13 17:44:11 +00:00
|
|
|
manage.ssh('rm -rf /tmp/results && cp -a ansible/test/results /tmp/results && chmod -R a+r /tmp/results')
|
|
|
|
manage.download('/tmp/results', 'test')
|
2016-11-30 05:21:53 +00:00
|
|
|
finally:
|
2017-05-11 13:21:11 +00:00
|
|
|
if args.remote_terminate == 'always' or (args.remote_terminate == 'success' and success):
|
|
|
|
core_ci.stop()
|
2016-11-30 05:21:53 +00:00
|
|
|
|
2018-05-09 16:24:39 +00:00
|
|
|
if httptester_id:
|
|
|
|
docker_rm(args, httptester_id)
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
def generate_command(args, path, options, exclude, require):
|
|
|
|
"""
|
|
|
|
:type args: EnvironmentConfig
|
|
|
|
:type path: str
|
|
|
|
:type options: dict[str, int]
|
|
|
|
:type exclude: list[str]
|
|
|
|
:type require: list[str]
|
2017-02-14 02:49:36 +00:00
|
|
|
:rtype: list[str]
|
2016-11-30 05:21:53 +00:00
|
|
|
"""
|
|
|
|
options['--color'] = 1
|
|
|
|
|
|
|
|
cmd = [path]
|
|
|
|
cmd += list(filter_options(args, sys.argv[1:], options, exclude, require))
|
|
|
|
cmd += ['--color', 'yes' if args.color else 'no']
|
|
|
|
|
|
|
|
if args.requirements:
|
|
|
|
cmd += ['--requirements']
|
|
|
|
|
|
|
|
if isinstance(args, ShellConfig):
|
|
|
|
cmd = create_shell_command(cmd)
|
2017-02-20 21:24:14 +00:00
|
|
|
elif isinstance(args, SanityConfig):
|
|
|
|
if args.base_branch:
|
|
|
|
cmd += ['--base-branch', args.base_branch]
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def filter_options(args, argv, options, exclude, require):
|
|
|
|
"""
|
|
|
|
:type args: EnvironmentConfig
|
|
|
|
:type argv: list[str]
|
|
|
|
:type options: dict[str, int]
|
|
|
|
:type exclude: list[str]
|
|
|
|
:type require: list[str]
|
|
|
|
:rtype: collections.Iterable[str]
|
|
|
|
"""
|
|
|
|
options = options.copy()
|
|
|
|
|
|
|
|
options['--requirements'] = 0
|
2018-05-01 22:47:24 +00:00
|
|
|
options['--truncate'] = 1
|
|
|
|
options['--redact'] = 0
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
if isinstance(args, TestConfig):
|
|
|
|
options.update({
|
|
|
|
'--changed': 0,
|
|
|
|
'--tracked': 0,
|
|
|
|
'--untracked': 0,
|
|
|
|
'--ignore-committed': 0,
|
|
|
|
'--ignore-staged': 0,
|
|
|
|
'--ignore-unstaged': 0,
|
|
|
|
'--changed-from': 1,
|
|
|
|
'--changed-path': 1,
|
2017-03-15 19:17:42 +00:00
|
|
|
'--metadata': 1,
|
2018-10-13 17:44:11 +00:00
|
|
|
'--exclude': 1,
|
|
|
|
'--require': 1,
|
2016-11-30 05:21:53 +00:00
|
|
|
})
|
2017-02-20 21:24:14 +00:00
|
|
|
elif isinstance(args, SanityConfig):
|
|
|
|
options.update({
|
|
|
|
'--base-branch': 1,
|
|
|
|
})
|
2016-11-30 05:21:53 +00:00
|
|
|
|
|
|
|
remaining = 0
|
|
|
|
|
|
|
|
for arg in argv:
|
|
|
|
if not arg.startswith('-') and remaining:
|
|
|
|
remaining -= 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
remaining = 0
|
|
|
|
|
|
|
|
parts = arg.split('=', 1)
|
|
|
|
key = parts[0]
|
|
|
|
|
|
|
|
if key in options:
|
|
|
|
remaining = options[key] - len(parts) + 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
yield arg
|
|
|
|
|
2018-10-13 17:44:11 +00:00
|
|
|
for arg in args.delegate_args:
|
|
|
|
yield arg
|
|
|
|
|
2016-11-30 05:21:53 +00:00
|
|
|
for target in exclude:
|
|
|
|
yield '--exclude'
|
|
|
|
yield target
|
|
|
|
|
|
|
|
for target in require:
|
|
|
|
yield '--require'
|
|
|
|
yield target
|
2017-03-15 19:17:42 +00:00
|
|
|
|
2017-03-20 22:31:57 +00:00
|
|
|
if isinstance(args, TestConfig):
|
|
|
|
if args.metadata_path:
|
|
|
|
yield '--metadata'
|
|
|
|
yield args.metadata_path
|
2018-05-01 22:47:24 +00:00
|
|
|
|
|
|
|
yield '--truncate'
|
|
|
|
yield '%d' % args.truncate
|
|
|
|
|
|
|
|
if args.redact:
|
|
|
|
yield '--redact'
|