2016-11-30 06:21:53 +01:00
|
|
|
"""Test runner for all Ansible tests."""
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2019-02-18 22:28:25 +01:00
|
|
|
# This import should occur as early as possible.
|
|
|
|
# It must occur before subprocess has been imported anywhere in the current process.
|
2019-08-06 23:43:29 +02:00
|
|
|
from .init import (
|
2019-02-18 22:28:25 +01:00
|
|
|
CURRENT_RLIMIT_NOFILE,
|
|
|
|
)
|
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
from . import types as t
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .util import (
|
2016-11-30 06:21:53 +01:00
|
|
|
ApplicationError,
|
|
|
|
display,
|
|
|
|
raw_command,
|
2018-03-14 19:35:59 +01:00
|
|
|
generate_pip_command,
|
2018-09-20 08:20:27 +02:00
|
|
|
read_lines_without_comments,
|
2019-02-18 22:28:25 +01:00
|
|
|
MAXFD,
|
2019-08-06 02:40:00 +02:00
|
|
|
ANSIBLE_TEST_DATA_ROOT,
|
2016-11-30 06:21:53 +01:00
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .delegation import (
|
2019-03-28 00:40:27 +01:00
|
|
|
check_delegation_args,
|
2016-11-30 06:21:53 +01:00
|
|
|
delegate,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .executor import (
|
2016-11-30 06:21:53 +01:00
|
|
|
command_posix_integration,
|
|
|
|
command_network_integration,
|
|
|
|
command_windows_integration,
|
|
|
|
command_shell,
|
|
|
|
SUPPORTED_PYTHON_VERSIONS,
|
2017-07-07 01:14:44 +02:00
|
|
|
ApplicationWarning,
|
|
|
|
Delegate,
|
|
|
|
generate_pip_install,
|
|
|
|
check_startup,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .config import (
|
2016-11-30 06:21:53 +01:00
|
|
|
PosixIntegrationConfig,
|
|
|
|
WindowsIntegrationConfig,
|
|
|
|
NetworkIntegrationConfig,
|
|
|
|
SanityConfig,
|
|
|
|
UnitsConfig,
|
|
|
|
ShellConfig,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .env import (
|
2018-12-21 07:08:57 +01:00
|
|
|
EnvConfig,
|
|
|
|
command_env,
|
2019-03-05 20:58:13 +01:00
|
|
|
configure_timeout,
|
2018-12-21 07:08:57 +01:00
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .sanity import (
|
2017-03-02 21:36:46 +01:00
|
|
|
command_sanity,
|
|
|
|
sanity_init,
|
|
|
|
sanity_get_tests,
|
|
|
|
)
|
|
|
|
|
2019-08-09 18:38:19 +02:00
|
|
|
from .units import (
|
|
|
|
command_units,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .target import (
|
2016-11-30 06:21:53 +01:00
|
|
|
find_target_completion,
|
|
|
|
walk_posix_integration_targets,
|
|
|
|
walk_network_integration_targets,
|
|
|
|
walk_windows_integration_targets,
|
|
|
|
walk_units_targets,
|
|
|
|
walk_sanity_targets,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .core_ci import (
|
2017-01-19 01:31:34 +01:00
|
|
|
AWS_ENDPOINTS,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .cloud import (
|
2017-05-05 10:23:00 +02:00
|
|
|
initialize_cloud_plugins,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .data import (
|
2019-07-23 04:24:48 +02:00
|
|
|
data_context,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .util_common import (
|
2020-06-10 00:40:56 +02:00
|
|
|
get_docker_completion,
|
|
|
|
get_network_completion,
|
|
|
|
get_remote_completion,
|
2019-07-23 04:24:48 +02:00
|
|
|
CommonConfig,
|
|
|
|
)
|
|
|
|
|
2020-01-30 22:21:33 +01:00
|
|
|
from .coverage.combine import (
|
2019-08-05 23:56:38 +02:00
|
|
|
command_coverage_combine,
|
2020-01-30 22:21:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from .coverage.erase import (
|
2019-08-05 23:56:38 +02:00
|
|
|
command_coverage_erase,
|
2020-01-30 22:21:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from .coverage.html import (
|
2019-08-05 23:56:38 +02:00
|
|
|
command_coverage_html,
|
2020-01-30 22:21:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from .coverage.report import (
|
2019-08-05 23:56:38 +02:00
|
|
|
command_coverage_report,
|
2020-01-30 22:21:33 +01:00
|
|
|
CoverageReportConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
from .coverage.xml import (
|
2019-08-05 23:56:38 +02:00
|
|
|
command_coverage_xml,
|
2020-01-30 22:21:33 +01:00
|
|
|
)
|
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
from .coverage.analyze.targets.generate import (
|
|
|
|
command_coverage_analyze_targets_generate,
|
|
|
|
CoverageAnalyzeTargetsGenerateConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
from .coverage.analyze.targets.expand import (
|
|
|
|
command_coverage_analyze_targets_expand,
|
|
|
|
CoverageAnalyzeTargetsExpandConfig,
|
|
|
|
)
|
|
|
|
|
2020-03-11 20:02:39 +01:00
|
|
|
from .coverage.analyze.targets.filter import (
|
|
|
|
command_coverage_analyze_targets_filter,
|
|
|
|
CoverageAnalyzeTargetsFilterConfig,
|
|
|
|
)
|
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
from .coverage.analyze.targets.combine import (
|
|
|
|
command_coverage_analyze_targets_combine,
|
|
|
|
CoverageAnalyzeTargetsCombineConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
from .coverage.analyze.targets.missing import (
|
|
|
|
command_coverage_analyze_targets_missing,
|
|
|
|
CoverageAnalyzeTargetsMissingConfig,
|
|
|
|
)
|
|
|
|
|
2020-01-30 22:21:33 +01:00
|
|
|
from .coverage import (
|
2019-08-05 23:56:38 +02:00
|
|
|
COVERAGE_GROUPS,
|
|
|
|
CoverageConfig,
|
|
|
|
)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
if t.TYPE_CHECKING:
|
|
|
|
import argparse as argparse_module
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Main program function."""
|
|
|
|
try:
|
2019-07-23 04:24:48 +02:00
|
|
|
os.chdir(data_context().content.root)
|
2017-05-05 10:23:00 +02:00
|
|
|
initialize_cloud_plugins()
|
2017-03-02 21:36:46 +01:00
|
|
|
sanity_init()
|
2016-11-30 06:21:53 +01:00
|
|
|
args = parse_args()
|
2019-07-23 04:24:48 +02:00
|
|
|
config = args.config(args) # type: CommonConfig
|
2016-11-30 06:21:53 +01:00
|
|
|
display.verbosity = config.verbosity
|
2018-02-16 07:56:05 +01:00
|
|
|
display.truncate = config.truncate
|
2018-02-19 22:32:07 +01:00
|
|
|
display.redact = config.redact
|
2016-11-30 06:21:53 +01:00
|
|
|
display.color = config.color
|
2020-02-06 07:16:15 +01:00
|
|
|
display.info_stderr = config.info_stderr
|
2017-01-24 19:31:39 +01:00
|
|
|
check_startup()
|
2019-03-28 00:40:27 +01:00
|
|
|
check_delegation_args(config)
|
2019-03-05 20:58:13 +01:00
|
|
|
configure_timeout(config)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2019-02-18 22:28:25 +01:00
|
|
|
display.info('RLIMIT_NOFILE: %s' % (CURRENT_RLIMIT_NOFILE,), verbosity=2)
|
|
|
|
display.info('MAXFD: %d' % MAXFD, verbosity=2)
|
2018-10-09 04:18:49 +02:00
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
try:
|
|
|
|
args.func(config)
|
2019-07-23 04:24:48 +02:00
|
|
|
delegate_args = None
|
2016-11-30 06:21:53 +01:00
|
|
|
except Delegate as ex:
|
2019-07-23 04:24:48 +02:00
|
|
|
# save delegation args for use once we exit the exception handler
|
|
|
|
delegate_args = (ex.exclude, ex.require, ex.integration_targets)
|
|
|
|
|
|
|
|
if delegate_args:
|
2020-02-06 07:16:15 +01:00
|
|
|
# noinspection PyTypeChecker
|
2019-07-23 04:24:48 +02:00
|
|
|
delegate(config, *delegate_args)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
display.review_warnings()
|
|
|
|
except ApplicationWarning as ex:
|
2018-10-02 21:21:36 +02:00
|
|
|
display.warning(u'%s' % ex)
|
2020-05-16 02:09:54 +02:00
|
|
|
sys.exit(0)
|
2016-11-30 06:21:53 +01:00
|
|
|
except ApplicationError as ex:
|
2018-10-02 21:21:36 +02:00
|
|
|
display.error(u'%s' % ex)
|
2020-05-16 02:09:54 +02:00
|
|
|
sys.exit(1)
|
2016-11-30 06:21:53 +01:00
|
|
|
except KeyboardInterrupt:
|
2020-05-16 02:09:54 +02:00
|
|
|
sys.exit(2)
|
2016-11-30 06:21:53 +01:00
|
|
|
except IOError as ex:
|
|
|
|
if ex.errno == errno.EPIPE:
|
2020-05-16 02:09:54 +02:00
|
|
|
sys.exit(3)
|
2016-11-30 06:21:53 +01:00
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
"""Parse command line arguments."""
|
|
|
|
try:
|
|
|
|
import argparse
|
|
|
|
except ImportError:
|
|
|
|
if '--requirements' not in sys.argv:
|
|
|
|
raise
|
2020-03-29 06:33:13 +02:00
|
|
|
# install argparse without using constraints since pip may be too old to support them
|
|
|
|
# not using the ansible-test requirements file since this install is for sys.executable rather than the delegated python (which may be different)
|
|
|
|
# argparse has no special requirements, so upgrading pip is not required here
|
2020-06-09 22:38:36 +02:00
|
|
|
raw_command(generate_pip_install(generate_pip_command(sys.executable), '', packages=['argparse'], use_constraints=False))
|
2016-11-30 06:21:53 +01:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
try:
|
|
|
|
import argcomplete
|
|
|
|
except ImportError:
|
|
|
|
argcomplete = None
|
|
|
|
|
|
|
|
if argcomplete:
|
|
|
|
epilog = 'Tab completion available using the "argcomplete" python package.'
|
|
|
|
else:
|
|
|
|
epilog = 'Install the "argcomplete" python package to enable tab completion.'
|
|
|
|
|
2020-02-21 00:27:08 +01:00
|
|
|
def key_value_type(value): # type: (str) -> t.Tuple[str, str]
|
|
|
|
"""Wrapper around key_value."""
|
|
|
|
return key_value(argparse, value)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
parser = argparse.ArgumentParser(epilog=epilog)
|
|
|
|
|
|
|
|
common = argparse.ArgumentParser(add_help=False)
|
|
|
|
|
|
|
|
common.add_argument('-e', '--explain',
|
|
|
|
action='store_true',
|
|
|
|
help='explain commands that would be executed')
|
|
|
|
|
|
|
|
common.add_argument('-v', '--verbose',
|
|
|
|
dest='verbosity',
|
|
|
|
action='count',
|
|
|
|
default=0,
|
|
|
|
help='display more output')
|
|
|
|
|
|
|
|
common.add_argument('--color',
|
|
|
|
metavar='COLOR',
|
|
|
|
nargs='?',
|
|
|
|
help='generate color output: %(choices)s',
|
|
|
|
choices=('yes', 'no', 'auto'),
|
|
|
|
const='yes',
|
|
|
|
default='auto')
|
|
|
|
|
2017-02-01 20:15:08 +01:00
|
|
|
common.add_argument('--debug',
|
|
|
|
action='store_true',
|
|
|
|
help='run ansible commands in debug mode')
|
|
|
|
|
2019-07-11 22:03:49 +02:00
|
|
|
# noinspection PyTypeChecker
|
2018-02-16 07:56:05 +01:00
|
|
|
common.add_argument('--truncate',
|
|
|
|
dest='truncate',
|
|
|
|
metavar='COLUMNS',
|
|
|
|
type=int,
|
|
|
|
default=display.columns,
|
|
|
|
help='truncate some long output (0=disabled) (default: auto)')
|
|
|
|
|
2018-02-19 22:32:07 +01:00
|
|
|
common.add_argument('--redact',
|
|
|
|
dest='redact',
|
|
|
|
action='store_true',
|
2019-09-17 07:40:58 +02:00
|
|
|
default=True,
|
2018-02-19 22:32:07 +01:00
|
|
|
help='redact sensitive values in output')
|
|
|
|
|
2019-09-17 07:40:58 +02:00
|
|
|
common.add_argument('--no-redact',
|
|
|
|
dest='redact',
|
|
|
|
action='store_false',
|
|
|
|
default=False,
|
|
|
|
help='show sensitive values in output')
|
|
|
|
|
2019-06-05 06:59:56 +02:00
|
|
|
common.add_argument('--check-python',
|
|
|
|
choices=SUPPORTED_PYTHON_VERSIONS,
|
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
test = argparse.ArgumentParser(add_help=False, parents=[common])
|
|
|
|
|
|
|
|
test.add_argument('include',
|
|
|
|
metavar='TARGET',
|
|
|
|
nargs='*',
|
|
|
|
help='test the specified target').completer = complete_target
|
|
|
|
|
2018-10-02 21:26:14 +02:00
|
|
|
test.add_argument('--include',
|
|
|
|
metavar='TARGET',
|
|
|
|
action='append',
|
|
|
|
help='include the specified target').completer = complete_target
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
test.add_argument('--exclude',
|
|
|
|
metavar='TARGET',
|
|
|
|
action='append',
|
|
|
|
help='exclude the specified target').completer = complete_target
|
|
|
|
|
|
|
|
test.add_argument('--require',
|
|
|
|
metavar='TARGET',
|
|
|
|
action='append',
|
|
|
|
help='require the specified target').completer = complete_target
|
|
|
|
|
|
|
|
test.add_argument('--coverage',
|
|
|
|
action='store_true',
|
|
|
|
help='analyze code coverage when running tests')
|
|
|
|
|
2017-05-11 07:25:02 +02:00
|
|
|
test.add_argument('--coverage-label',
|
|
|
|
default='',
|
|
|
|
help='label to include in coverage output file names')
|
|
|
|
|
2019-03-11 23:13:09 +01:00
|
|
|
test.add_argument('--coverage-check',
|
|
|
|
action='store_true',
|
|
|
|
help='only verify code coverage can be enabled')
|
|
|
|
|
2017-03-15 20:17:42 +01:00
|
|
|
test.add_argument('--metadata',
|
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
|
2020-05-18 22:18:31 +02:00
|
|
|
test.add_argument('--base-branch',
|
|
|
|
help='base branch used for change detection')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
add_changes(test, argparse)
|
|
|
|
add_environments(test)
|
|
|
|
|
|
|
|
integration = argparse.ArgumentParser(add_help=False, parents=[test])
|
|
|
|
|
|
|
|
integration.add_argument('--python',
|
|
|
|
metavar='VERSION',
|
2017-06-30 23:53:32 +02:00
|
|
|
choices=SUPPORTED_PYTHON_VERSIONS + ('default',),
|
2016-11-30 06:21:53 +01:00
|
|
|
help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS))
|
|
|
|
|
|
|
|
integration.add_argument('--start-at',
|
|
|
|
metavar='TARGET',
|
|
|
|
help='start at the specified target').completer = complete_target
|
|
|
|
|
|
|
|
integration.add_argument('--start-at-task',
|
|
|
|
metavar='TASK',
|
|
|
|
help='start at the specified task')
|
|
|
|
|
2017-05-25 16:47:52 +02:00
|
|
|
integration.add_argument('--tags',
|
|
|
|
metavar='TAGS',
|
|
|
|
help='only run plays and tasks tagged with these values')
|
|
|
|
|
|
|
|
integration.add_argument('--skip-tags',
|
|
|
|
metavar='TAGS',
|
|
|
|
help='only run plays and tasks whose tags do not match these values')
|
|
|
|
|
2017-06-30 20:43:34 +02:00
|
|
|
integration.add_argument('--diff',
|
|
|
|
action='store_true',
|
|
|
|
help='show diff output')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
integration.add_argument('--allow-destructive',
|
|
|
|
action='store_true',
|
2019-09-26 20:28:06 +02:00
|
|
|
help='allow destructive tests')
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2018-04-04 03:53:53 +02:00
|
|
|
integration.add_argument('--allow-root',
|
|
|
|
action='store_true',
|
|
|
|
help='allow tests requiring root when not root')
|
|
|
|
|
2018-04-13 01:15:28 +02:00
|
|
|
integration.add_argument('--allow-disabled',
|
|
|
|
action='store_true',
|
|
|
|
help='allow tests which have been marked as disabled')
|
|
|
|
|
|
|
|
integration.add_argument('--allow-unstable',
|
|
|
|
action='store_true',
|
|
|
|
help='allow tests which have been marked as unstable')
|
|
|
|
|
|
|
|
integration.add_argument('--allow-unstable-changed',
|
|
|
|
action='store_true',
|
|
|
|
help='allow tests which have been marked as unstable when focused changes are detected')
|
|
|
|
|
|
|
|
integration.add_argument('--allow-unsupported',
|
|
|
|
action='store_true',
|
|
|
|
help='allow tests which have been marked as unsupported')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
integration.add_argument('--retry-on-error',
|
|
|
|
action='store_true',
|
|
|
|
help='retry failed test with increased verbosity')
|
2017-07-07 21:37:08 +02:00
|
|
|
|
2017-07-15 01:52:11 +02:00
|
|
|
integration.add_argument('--continue-on-error',
|
|
|
|
action='store_true',
|
|
|
|
help='continue after failed test')
|
|
|
|
|
2017-07-07 21:37:08 +02:00
|
|
|
integration.add_argument('--debug-strategy',
|
|
|
|
action='store_true',
|
|
|
|
help='run test playbooks using the debug strategy')
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2017-07-15 01:51:32 +02:00
|
|
|
integration.add_argument('--changed-all-target',
|
|
|
|
metavar='TARGET',
|
|
|
|
default='all',
|
|
|
|
help='target to run when all tests are needed')
|
|
|
|
|
2018-10-02 21:26:14 +02:00
|
|
|
integration.add_argument('--changed-all-mode',
|
|
|
|
metavar='MODE',
|
|
|
|
choices=('default', 'include', 'exclude'),
|
|
|
|
help='include/exclude behavior with --changed-all-target: %(choices)s')
|
|
|
|
|
2017-07-15 04:11:25 +02:00
|
|
|
integration.add_argument('--list-targets',
|
|
|
|
action='store_true',
|
|
|
|
help='list matching targets instead of running tests')
|
|
|
|
|
2019-01-10 23:43:21 +01:00
|
|
|
integration.add_argument('--no-temp-workdir',
|
|
|
|
action='store_true',
|
|
|
|
help='do not run tests from a temporary directory (use only for verifying broken tests)')
|
|
|
|
|
|
|
|
integration.add_argument('--no-temp-unicode',
|
|
|
|
action='store_true',
|
|
|
|
help='avoid unicode characters in temporary directory (use only for verifying broken tests)')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
subparsers = parser.add_subparsers(metavar='COMMAND')
|
|
|
|
subparsers.required = True # work-around for python 3 bug which makes subparsers optional
|
|
|
|
|
|
|
|
posix_integration = subparsers.add_parser('integration',
|
|
|
|
parents=[integration],
|
|
|
|
help='posix integration tests')
|
|
|
|
|
|
|
|
posix_integration.set_defaults(func=command_posix_integration,
|
|
|
|
targets=walk_posix_integration_targets,
|
|
|
|
config=PosixIntegrationConfig)
|
|
|
|
|
|
|
|
add_extra_docker_options(posix_integration)
|
2018-05-09 18:24:39 +02:00
|
|
|
add_httptester_options(posix_integration, argparse)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
network_integration = subparsers.add_parser('network-integration',
|
|
|
|
parents=[integration],
|
|
|
|
help='network integration tests')
|
|
|
|
|
|
|
|
network_integration.set_defaults(func=command_network_integration,
|
|
|
|
targets=walk_network_integration_targets,
|
|
|
|
config=NetworkIntegrationConfig)
|
|
|
|
|
2017-10-20 17:48:01 +02:00
|
|
|
add_extra_docker_options(network_integration, integration=False)
|
|
|
|
|
2017-01-08 08:36:35 +01:00
|
|
|
network_integration.add_argument('--platform',
|
|
|
|
metavar='PLATFORM',
|
|
|
|
action='append',
|
|
|
|
help='network platform/version').completer = complete_network_platform
|
|
|
|
|
2020-02-21 00:27:08 +01:00
|
|
|
network_integration.add_argument('--platform-collection',
|
|
|
|
type=key_value_type,
|
|
|
|
metavar='PLATFORM=COLLECTION',
|
|
|
|
action='append',
|
|
|
|
help='collection used to test platform').completer = complete_network_platform_collection
|
|
|
|
|
|
|
|
network_integration.add_argument('--platform-connection',
|
|
|
|
type=key_value_type,
|
|
|
|
metavar='PLATFORM=CONNECTION',
|
|
|
|
action='append',
|
|
|
|
help='connection used to test platform').completer = complete_network_platform_connection
|
|
|
|
|
2017-07-15 01:52:11 +02:00
|
|
|
network_integration.add_argument('--inventory',
|
|
|
|
metavar='PATH',
|
|
|
|
help='path to inventory used for tests')
|
|
|
|
|
2018-02-15 00:40:35 +01:00
|
|
|
network_integration.add_argument('--testcase',
|
|
|
|
metavar='TESTCASE',
|
|
|
|
help='limit a test to a specified testcase').completer = complete_network_testcase
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
windows_integration = subparsers.add_parser('windows-integration',
|
|
|
|
parents=[integration],
|
|
|
|
help='windows integration tests')
|
|
|
|
|
|
|
|
windows_integration.set_defaults(func=command_windows_integration,
|
|
|
|
targets=walk_windows_integration_targets,
|
|
|
|
config=WindowsIntegrationConfig)
|
|
|
|
|
2017-10-20 17:48:01 +02:00
|
|
|
add_extra_docker_options(windows_integration, integration=False)
|
2018-10-13 00:20:00 +02:00
|
|
|
add_httptester_options(windows_integration, argparse)
|
2017-10-20 17:48:01 +02:00
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
windows_integration.add_argument('--windows',
|
|
|
|
metavar='VERSION',
|
|
|
|
action='append',
|
2016-12-22 18:57:17 +01:00
|
|
|
help='windows version').completer = complete_windows
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2019-08-21 21:12:37 +02:00
|
|
|
windows_integration.add_argument('--inventory',
|
|
|
|
metavar='PATH',
|
|
|
|
help='path to inventory used for tests')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
units = subparsers.add_parser('units',
|
|
|
|
parents=[test],
|
|
|
|
help='unit tests')
|
|
|
|
|
|
|
|
units.set_defaults(func=command_units,
|
|
|
|
targets=walk_units_targets,
|
|
|
|
config=UnitsConfig)
|
|
|
|
|
|
|
|
units.add_argument('--python',
|
|
|
|
metavar='VERSION',
|
2017-04-27 05:21:11 +02:00
|
|
|
choices=SUPPORTED_PYTHON_VERSIONS + ('default',),
|
2016-11-30 06:21:53 +01:00
|
|
|
help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS))
|
|
|
|
|
|
|
|
units.add_argument('--collect-only',
|
|
|
|
action='store_true',
|
|
|
|
help='collect tests but do not execute them')
|
|
|
|
|
2019-07-11 23:38:50 +02:00
|
|
|
# noinspection PyTypeChecker
|
|
|
|
units.add_argument('--num-workers',
|
|
|
|
type=int,
|
|
|
|
help='number of workers to use (default: auto)')
|
|
|
|
|
2018-09-18 17:37:14 +02:00
|
|
|
units.add_argument('--requirements-mode',
|
|
|
|
choices=('only', 'skip'),
|
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
|
2016-12-15 04:48:30 +01:00
|
|
|
add_extra_docker_options(units, integration=False)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
sanity = subparsers.add_parser('sanity',
|
|
|
|
parents=[test],
|
|
|
|
help='sanity tests')
|
|
|
|
|
|
|
|
sanity.set_defaults(func=command_sanity,
|
|
|
|
targets=walk_sanity_targets,
|
|
|
|
config=SanityConfig)
|
|
|
|
|
|
|
|
sanity.add_argument('--test',
|
|
|
|
metavar='TEST',
|
|
|
|
action='append',
|
2017-03-02 21:36:46 +01:00
|
|
|
choices=[test.name for test in sanity_get_tests()],
|
|
|
|
help='tests to run').completer = complete_sanity_test
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
sanity.add_argument('--skip-test',
|
|
|
|
metavar='TEST',
|
|
|
|
action='append',
|
2017-03-02 21:36:46 +01:00
|
|
|
choices=[test.name for test in sanity_get_tests()],
|
|
|
|
help='tests to skip').completer = complete_sanity_test
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2018-05-10 01:47:24 +02:00
|
|
|
sanity.add_argument('--allow-disabled',
|
|
|
|
action='store_true',
|
|
|
|
help='allow tests to run which are disabled by default')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
sanity.add_argument('--list-tests',
|
|
|
|
action='store_true',
|
|
|
|
help='list available tests')
|
|
|
|
|
|
|
|
sanity.add_argument('--python',
|
|
|
|
metavar='VERSION',
|
2017-06-30 23:53:32 +02:00
|
|
|
choices=SUPPORTED_PYTHON_VERSIONS + ('default',),
|
2016-11-30 06:21:53 +01:00
|
|
|
help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS))
|
|
|
|
|
2020-05-13 22:58:09 +02:00
|
|
|
sanity.add_argument('--enable-optional-errors',
|
|
|
|
action='store_true',
|
|
|
|
help='enable optional errors')
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
add_lint(sanity)
|
2016-12-15 04:48:30 +01:00
|
|
|
add_extra_docker_options(sanity, integration=False)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
shell = subparsers.add_parser('shell',
|
|
|
|
parents=[common],
|
|
|
|
help='open an interactive shell')
|
|
|
|
|
2019-03-28 00:40:27 +01:00
|
|
|
shell.add_argument('--python',
|
|
|
|
metavar='VERSION',
|
|
|
|
choices=SUPPORTED_PYTHON_VERSIONS + ('default',),
|
|
|
|
help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS))
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
shell.set_defaults(func=command_shell,
|
|
|
|
config=ShellConfig)
|
|
|
|
|
2018-11-16 23:50:01 +01:00
|
|
|
shell.add_argument('--raw',
|
|
|
|
action='store_true',
|
|
|
|
help='direct to shell with no setup')
|
|
|
|
|
2019-09-26 20:28:06 +02:00
|
|
|
add_environments(shell)
|
2016-11-30 06:21:53 +01:00
|
|
|
add_extra_docker_options(shell)
|
2018-05-09 18:24:39 +02:00
|
|
|
add_httptester_options(shell, argparse)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
coverage_common = argparse.ArgumentParser(add_help=False, parents=[common])
|
|
|
|
|
2019-09-26 20:28:06 +02:00
|
|
|
add_environments(coverage_common, isolated_delegation=False)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
coverage = subparsers.add_parser('coverage',
|
|
|
|
help='code coverage management and reporting')
|
|
|
|
|
|
|
|
coverage_subparsers = coverage.add_subparsers(metavar='COMMAND')
|
|
|
|
coverage_subparsers.required = True # work-around for python 3 bug which makes subparsers optional
|
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
add_coverage_analyze(coverage_subparsers, coverage_common)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
coverage_combine = coverage_subparsers.add_parser('combine',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='combine coverage data and rewrite remote paths')
|
|
|
|
|
2019-08-05 23:56:38 +02:00
|
|
|
coverage_combine.set_defaults(func=command_coverage_combine,
|
|
|
|
config=CoverageConfig)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2017-05-15 11:42:11 +02:00
|
|
|
add_extra_coverage_options(coverage_combine)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
coverage_erase = coverage_subparsers.add_parser('erase',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='erase coverage data files')
|
|
|
|
|
2019-08-05 23:56:38 +02:00
|
|
|
coverage_erase.set_defaults(func=command_coverage_erase,
|
|
|
|
config=CoverageConfig)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
coverage_report = coverage_subparsers.add_parser('report',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='generate console coverage report')
|
|
|
|
|
2019-08-05 23:56:38 +02:00
|
|
|
coverage_report.set_defaults(func=command_coverage_report,
|
|
|
|
config=CoverageReportConfig)
|
2017-07-05 19:24:56 +02:00
|
|
|
|
|
|
|
coverage_report.add_argument('--show-missing',
|
|
|
|
action='store_true',
|
|
|
|
help='show line numbers of statements not executed')
|
2018-03-29 01:42:57 +02:00
|
|
|
coverage_report.add_argument('--include',
|
|
|
|
metavar='PAT1,PAT2,...',
|
|
|
|
help='include only files whose paths match one of these '
|
|
|
|
'patterns. Accepts shell-style wildcards, which must be '
|
|
|
|
'quoted.')
|
|
|
|
coverage_report.add_argument('--omit',
|
|
|
|
metavar='PAT1,PAT2,...',
|
|
|
|
help='omit files whose paths match one of these patterns. '
|
|
|
|
'Accepts shell-style wildcards, which must be quoted.')
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2017-05-15 11:42:11 +02:00
|
|
|
add_extra_coverage_options(coverage_report)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
coverage_html = coverage_subparsers.add_parser('html',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='generate html coverage report')
|
|
|
|
|
2019-08-05 23:56:38 +02:00
|
|
|
coverage_html.set_defaults(func=command_coverage_html,
|
|
|
|
config=CoverageConfig)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2017-05-15 11:42:11 +02:00
|
|
|
add_extra_coverage_options(coverage_html)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
coverage_xml = coverage_subparsers.add_parser('xml',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='generate xml coverage report')
|
|
|
|
|
2019-08-05 23:56:38 +02:00
|
|
|
coverage_xml.set_defaults(func=command_coverage_xml,
|
|
|
|
config=CoverageConfig)
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2017-05-15 11:42:11 +02:00
|
|
|
add_extra_coverage_options(coverage_xml)
|
|
|
|
|
2018-12-21 07:08:57 +01:00
|
|
|
env = subparsers.add_parser('env',
|
|
|
|
parents=[common],
|
|
|
|
help='show information about the test environment')
|
|
|
|
|
|
|
|
env.set_defaults(func=command_env,
|
|
|
|
config=EnvConfig)
|
|
|
|
|
|
|
|
env.add_argument('--show',
|
|
|
|
action='store_true',
|
|
|
|
help='show environment on stdout')
|
|
|
|
|
|
|
|
env.add_argument('--dump',
|
|
|
|
action='store_true',
|
|
|
|
help='dump environment to disk')
|
|
|
|
|
2020-04-08 10:15:49 +02:00
|
|
|
env.add_argument('--list-files',
|
|
|
|
action='store_true',
|
|
|
|
help='list files on stdout')
|
|
|
|
|
2019-07-11 22:03:49 +02:00
|
|
|
# noinspection PyTypeChecker
|
2019-03-05 20:58:13 +01:00
|
|
|
env.add_argument('--timeout',
|
|
|
|
type=int,
|
|
|
|
metavar='MINUTES',
|
|
|
|
help='timeout for future ansible-test commands (0 clears)')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
if argcomplete:
|
|
|
|
argcomplete.autocomplete(parser, always_complete_options=False, validator=lambda i, k: True)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.explain and not args.verbosity:
|
|
|
|
args.verbosity = 1
|
|
|
|
|
|
|
|
if args.color == 'yes':
|
|
|
|
args.color = True
|
|
|
|
elif args.color == 'no':
|
|
|
|
args.color = False
|
|
|
|
else:
|
|
|
|
args.color = sys.stdout.isatty()
|
|
|
|
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
2020-02-21 00:27:08 +01:00
|
|
|
def key_value(argparse, value): # type: (argparse_module, str) -> t.Tuple[str, str]
|
|
|
|
"""Type parsing and validation for argparse key/value pairs separated by an '=' character."""
|
|
|
|
parts = value.split('=')
|
|
|
|
|
|
|
|
if len(parts) != 2:
|
|
|
|
raise argparse.ArgumentTypeError('"%s" must be in the format "key=value"' % value)
|
|
|
|
|
2020-05-16 02:09:54 +02:00
|
|
|
return parts[0], parts[1]
|
2020-02-21 00:27:08 +01:00
|
|
|
|
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
# noinspection PyProtectedMember
|
|
|
|
def add_coverage_analyze(coverage_subparsers, coverage_common): # type: (argparse_module._SubParsersAction, argparse_module.ArgumentParser) -> None
|
|
|
|
"""Add the `coverage analyze` subcommand."""
|
|
|
|
analyze = coverage_subparsers.add_parser(
|
|
|
|
'analyze',
|
|
|
|
help='analyze collected coverage data',
|
|
|
|
)
|
|
|
|
|
|
|
|
analyze_subparsers = analyze.add_subparsers(metavar='COMMAND')
|
|
|
|
analyze_subparsers.required = True # work-around for python 3 bug which makes subparsers optional
|
|
|
|
|
|
|
|
targets = analyze_subparsers.add_parser(
|
|
|
|
'targets',
|
|
|
|
help='analyze integration test target coverage',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_subparsers = targets.add_subparsers(metavar='COMMAND')
|
|
|
|
targets_subparsers.required = True # work-around for python 3 bug which makes subparsers optional
|
|
|
|
|
|
|
|
targets_generate = targets_subparsers.add_parser(
|
|
|
|
'generate',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='aggregate coverage by integration test target',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_generate.set_defaults(
|
|
|
|
func=command_coverage_analyze_targets_generate,
|
|
|
|
config=CoverageAnalyzeTargetsGenerateConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_generate.add_argument(
|
|
|
|
'input_dir',
|
|
|
|
nargs='?',
|
|
|
|
help='directory to read coverage from',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_generate.add_argument(
|
|
|
|
'output_file',
|
|
|
|
help='output file for aggregated coverage',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_expand = targets_subparsers.add_parser(
|
|
|
|
'expand',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='expand target names from integers in aggregated coverage',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_expand.set_defaults(
|
|
|
|
func=command_coverage_analyze_targets_expand,
|
|
|
|
config=CoverageAnalyzeTargetsExpandConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_expand.add_argument(
|
|
|
|
'input_file',
|
|
|
|
help='input file to read aggregated coverage from',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_expand.add_argument(
|
|
|
|
'output_file',
|
|
|
|
help='output file to write expanded coverage to',
|
|
|
|
)
|
|
|
|
|
2020-03-11 20:02:39 +01:00
|
|
|
targets_filter = targets_subparsers.add_parser(
|
|
|
|
'filter',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='filter aggregated coverage data',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_filter.set_defaults(
|
|
|
|
func=command_coverage_analyze_targets_filter,
|
|
|
|
config=CoverageAnalyzeTargetsFilterConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_filter.add_argument(
|
|
|
|
'input_file',
|
|
|
|
help='input file to read aggregated coverage from',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_filter.add_argument(
|
|
|
|
'output_file',
|
|
|
|
help='output file to write expanded coverage to',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_filter.add_argument(
|
|
|
|
'--include-target',
|
|
|
|
dest='include_targets',
|
|
|
|
action='append',
|
|
|
|
help='include the specified targets',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_filter.add_argument(
|
|
|
|
'--exclude-target',
|
|
|
|
dest='exclude_targets',
|
|
|
|
action='append',
|
|
|
|
help='exclude the specified targets',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_filter.add_argument(
|
|
|
|
'--include-path',
|
|
|
|
help='include paths matching the given regex',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_filter.add_argument(
|
|
|
|
'--exclude-path',
|
|
|
|
help='exclude paths matching the given regex',
|
|
|
|
)
|
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
targets_combine = targets_subparsers.add_parser(
|
|
|
|
'combine',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='combine multiple aggregated coverage files',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_combine.set_defaults(
|
|
|
|
func=command_coverage_analyze_targets_combine,
|
|
|
|
config=CoverageAnalyzeTargetsCombineConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_combine.add_argument(
|
|
|
|
'input_file',
|
|
|
|
nargs='+',
|
|
|
|
help='input file to read aggregated coverage from',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_combine.add_argument(
|
|
|
|
'output_file',
|
|
|
|
help='output file to write aggregated coverage to',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_missing = targets_subparsers.add_parser(
|
|
|
|
'missing',
|
|
|
|
parents=[coverage_common],
|
|
|
|
help='identify coverage in one file missing in another',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_missing.set_defaults(
|
|
|
|
func=command_coverage_analyze_targets_missing,
|
|
|
|
config=CoverageAnalyzeTargetsMissingConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_missing.add_argument(
|
|
|
|
'from_file',
|
|
|
|
help='input file containing aggregated coverage',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_missing.add_argument(
|
|
|
|
'to_file',
|
|
|
|
help='input file containing aggregated coverage',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_missing.add_argument(
|
|
|
|
'output_file',
|
|
|
|
help='output file to write aggregated coverage to',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_missing.add_argument(
|
|
|
|
'--only-gaps',
|
|
|
|
action='store_true',
|
|
|
|
help='report only arcs/lines not hit by any target',
|
|
|
|
)
|
|
|
|
|
|
|
|
targets_missing.add_argument(
|
|
|
|
'--only-exists',
|
|
|
|
action='store_true',
|
|
|
|
help='limit results to files that exist',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
def add_lint(parser):
|
|
|
|
"""
|
|
|
|
:type parser: argparse.ArgumentParser
|
|
|
|
"""
|
|
|
|
parser.add_argument('--lint',
|
|
|
|
action='store_true',
|
|
|
|
help='write lint output to stdout, everything else stderr')
|
|
|
|
|
|
|
|
parser.add_argument('--junit',
|
|
|
|
action='store_true',
|
|
|
|
help='write test failures to junit xml files')
|
|
|
|
|
2017-03-15 00:32:21 +01:00
|
|
|
parser.add_argument('--failure-ok',
|
|
|
|
action='store_true',
|
|
|
|
help='exit successfully on failed tests after saving results')
|
|
|
|
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
def add_changes(parser, argparse):
|
|
|
|
"""
|
|
|
|
:type parser: argparse.ArgumentParser
|
|
|
|
:type argparse: argparse
|
|
|
|
"""
|
|
|
|
parser.add_argument('--changed', action='store_true', help='limit targets based on changes')
|
|
|
|
|
|
|
|
changes = parser.add_argument_group(title='change detection arguments')
|
|
|
|
|
|
|
|
changes.add_argument('--tracked', action='store_true', help=argparse.SUPPRESS)
|
|
|
|
changes.add_argument('--untracked', action='store_true', help='include untracked files')
|
|
|
|
changes.add_argument('--ignore-committed', dest='committed', action='store_false', help='exclude committed files')
|
|
|
|
changes.add_argument('--ignore-staged', dest='staged', action='store_false', help='exclude staged files')
|
|
|
|
changes.add_argument('--ignore-unstaged', dest='unstaged', action='store_false', help='exclude unstaged files')
|
|
|
|
|
|
|
|
changes.add_argument('--changed-from', metavar='PATH', help=argparse.SUPPRESS)
|
|
|
|
changes.add_argument('--changed-path', metavar='PATH', action='append', help=argparse.SUPPRESS)
|
|
|
|
|
|
|
|
|
2019-09-26 20:28:06 +02:00
|
|
|
def add_environments(parser, isolated_delegation=True):
|
2016-11-30 06:21:53 +01:00
|
|
|
"""
|
|
|
|
:type parser: argparse.ArgumentParser
|
2019-09-26 20:28:06 +02:00
|
|
|
:type isolated_delegation: bool
|
2016-11-30 06:21:53 +01:00
|
|
|
"""
|
|
|
|
parser.add_argument('--requirements',
|
|
|
|
action='store_true',
|
|
|
|
help='install command requirements')
|
|
|
|
|
2019-03-28 00:40:27 +01:00
|
|
|
parser.add_argument('--python-interpreter',
|
|
|
|
metavar='PATH',
|
|
|
|
default=None,
|
|
|
|
help='path to the docker or remote python interpreter')
|
|
|
|
|
2020-01-28 02:19:42 +01:00
|
|
|
parser.add_argument('--no-pip-check',
|
|
|
|
dest='pip_check',
|
|
|
|
default=True,
|
|
|
|
action='store_false',
|
|
|
|
help='do not run "pip check" to verify requirements')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
environments = parser.add_mutually_exclusive_group()
|
|
|
|
|
|
|
|
environments.add_argument('--local',
|
|
|
|
action='store_true',
|
|
|
|
help='run from the local environment')
|
|
|
|
|
2019-08-28 18:10:17 +02:00
|
|
|
environments.add_argument('--venv',
|
|
|
|
action='store_true',
|
|
|
|
help='run from ansible-test managed virtual environments')
|
|
|
|
|
2019-12-06 18:25:19 +01:00
|
|
|
venv = parser.add_argument_group(title='venv arguments')
|
|
|
|
|
|
|
|
venv.add_argument('--venv-system-site-packages',
|
|
|
|
action='store_true',
|
|
|
|
help='enable system site packages')
|
|
|
|
|
2019-09-26 20:28:06 +02:00
|
|
|
if not isolated_delegation:
|
2016-11-30 06:21:53 +01:00
|
|
|
environments.set_defaults(
|
|
|
|
docker=None,
|
|
|
|
remote=None,
|
|
|
|
remote_stage=None,
|
2017-11-29 09:46:08 +01:00
|
|
|
remote_provider=None,
|
2017-01-19 01:31:34 +01:00
|
|
|
remote_aws_region=None,
|
2017-05-11 15:21:11 +02:00
|
|
|
remote_terminate=None,
|
2019-03-28 00:40:27 +01:00
|
|
|
python_interpreter=None,
|
2016-11-30 06:21:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
environments.add_argument('--docker',
|
|
|
|
metavar='IMAGE',
|
|
|
|
nargs='?',
|
|
|
|
default=None,
|
2017-11-22 22:59:39 +01:00
|
|
|
const='default',
|
2016-12-22 18:57:17 +01:00
|
|
|
help='run from a docker container').completer = complete_docker
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
environments.add_argument('--remote',
|
|
|
|
metavar='PLATFORM',
|
|
|
|
default=None,
|
2018-08-13 01:27:59 +02:00
|
|
|
help='run from a remote instance').completer = complete_remote_shell if parser.prog.endswith(' shell') else complete_remote
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
remote = parser.add_argument_group(title='remote arguments')
|
|
|
|
|
|
|
|
remote.add_argument('--remote-stage',
|
|
|
|
metavar='STAGE',
|
|
|
|
help='remote stage to use: %(choices)s',
|
|
|
|
choices=['prod', 'dev'],
|
|
|
|
default='prod')
|
|
|
|
|
2017-11-29 09:46:08 +01:00
|
|
|
remote.add_argument('--remote-provider',
|
|
|
|
metavar='PROVIDER',
|
|
|
|
help='remote provider to use: %(choices)s',
|
2020-04-16 01:22:17 +02:00
|
|
|
choices=['default', 'aws', 'azure', 'parallels', 'ibmvpc', 'ibmps'],
|
2017-11-29 09:46:08 +01:00
|
|
|
default='default')
|
|
|
|
|
2017-01-19 01:31:34 +01:00
|
|
|
remote.add_argument('--remote-aws-region',
|
|
|
|
metavar='REGION',
|
|
|
|
help='remote aws region to use: %(choices)s (default: auto)',
|
|
|
|
choices=sorted(AWS_ENDPOINTS),
|
|
|
|
default=None)
|
|
|
|
|
2017-05-11 15:21:11 +02:00
|
|
|
remote.add_argument('--remote-terminate',
|
|
|
|
metavar='WHEN',
|
|
|
|
help='terminate remote instance: %(choices)s (default: %(default)s)',
|
|
|
|
choices=['never', 'always', 'success'],
|
|
|
|
default='never')
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
|
2017-05-15 11:42:11 +02:00
|
|
|
def add_extra_coverage_options(parser):
|
|
|
|
"""
|
|
|
|
:type parser: argparse.ArgumentParser
|
|
|
|
"""
|
|
|
|
parser.add_argument('--group-by',
|
|
|
|
metavar='GROUP',
|
|
|
|
action='append',
|
2019-08-05 23:56:38 +02:00
|
|
|
choices=COVERAGE_GROUPS,
|
|
|
|
help='group output by: %s' % ', '.join(COVERAGE_GROUPS))
|
2017-05-15 11:42:11 +02:00
|
|
|
|
2017-05-15 18:51:49 +02:00
|
|
|
parser.add_argument('--all',
|
|
|
|
action='store_true',
|
2019-08-27 23:03:23 +02:00
|
|
|
help='include all python/powershell source files')
|
2017-05-15 18:51:49 +02:00
|
|
|
|
|
|
|
parser.add_argument('--stub',
|
|
|
|
action='store_true',
|
2019-08-27 23:03:23 +02:00
|
|
|
help='generate empty report of all python/powershell source files')
|
2017-05-15 18:51:49 +02:00
|
|
|
|
2017-05-15 11:42:11 +02:00
|
|
|
|
2018-05-09 18:24:39 +02:00
|
|
|
def add_httptester_options(parser, argparse):
|
|
|
|
"""
|
|
|
|
:type parser: argparse.ArgumentParser
|
|
|
|
:type argparse: argparse
|
|
|
|
"""
|
|
|
|
group = parser.add_mutually_exclusive_group()
|
|
|
|
|
|
|
|
group.add_argument('--httptester',
|
|
|
|
metavar='IMAGE',
|
|
|
|
default='quay.io/ansible/http-test-container:1.0.0',
|
|
|
|
help='docker image to use for the httptester container')
|
|
|
|
|
|
|
|
group.add_argument('--disable-httptester',
|
|
|
|
dest='httptester',
|
|
|
|
action='store_const',
|
|
|
|
const='',
|
|
|
|
help='do not use the httptester container')
|
|
|
|
|
|
|
|
parser.add_argument('--inject-httptester',
|
|
|
|
action='store_true',
|
|
|
|
help=argparse.SUPPRESS) # internal use only
|
|
|
|
|
|
|
|
|
2016-12-15 04:48:30 +01:00
|
|
|
def add_extra_docker_options(parser, integration=True):
|
2016-11-30 06:21:53 +01:00
|
|
|
"""
|
|
|
|
:type parser: argparse.ArgumentParser
|
2016-12-15 04:48:30 +01:00
|
|
|
:type integration: bool
|
2016-11-30 06:21:53 +01:00
|
|
|
"""
|
|
|
|
docker = parser.add_argument_group(title='docker arguments')
|
|
|
|
|
2016-12-15 04:48:30 +01:00
|
|
|
docker.add_argument('--docker-no-pull',
|
|
|
|
action='store_false',
|
|
|
|
dest='docker_pull',
|
|
|
|
help='do not explicitly pull the latest docker images')
|
|
|
|
|
2019-07-23 04:24:48 +02:00
|
|
|
if data_context().content.is_ansible:
|
|
|
|
docker.add_argument('--docker-keep-git',
|
|
|
|
action='store_true',
|
|
|
|
help='transfer git related files into the docker container')
|
|
|
|
else:
|
|
|
|
docker.set_defaults(
|
|
|
|
docker_keep_git=False,
|
|
|
|
)
|
2017-10-26 09:21:46 +02:00
|
|
|
|
2018-08-30 20:36:57 +02:00
|
|
|
docker.add_argument('--docker-seccomp',
|
|
|
|
metavar='SC',
|
|
|
|
choices=('default', 'unconfined'),
|
|
|
|
default=None,
|
|
|
|
help='set seccomp confinement for the test container: %(choices)s')
|
|
|
|
|
2020-04-07 03:38:29 +02:00
|
|
|
docker.add_argument('--docker-terminate',
|
|
|
|
metavar='WHEN',
|
|
|
|
help='terminate docker container: %(choices)s (default: %(default)s)',
|
|
|
|
choices=['never', 'always', 'success'],
|
|
|
|
default='always')
|
|
|
|
|
2016-12-15 04:48:30 +01:00
|
|
|
if not integration:
|
|
|
|
return
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
docker.add_argument('--docker-privileged',
|
|
|
|
action='store_true',
|
|
|
|
help='run docker container in privileged mode')
|
|
|
|
|
2019-07-11 22:03:49 +02:00
|
|
|
# noinspection PyTypeChecker
|
2018-03-26 23:45:50 +02:00
|
|
|
docker.add_argument('--docker-memory',
|
|
|
|
help='memory limit for docker in bytes', type=int)
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
def complete_target(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
return find_target_completion(parsed_args.targets, prefix)
|
|
|
|
|
|
|
|
|
2020-02-04 20:21:53 +01:00
|
|
|
# noinspection PyUnusedLocal
|
2016-12-22 18:57:17 +01:00
|
|
|
def complete_remote(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
del parsed_args
|
|
|
|
|
2019-03-28 00:40:27 +01:00
|
|
|
images = sorted(get_remote_completion().keys())
|
2016-12-22 18:57:17 +01:00
|
|
|
|
|
|
|
return [i for i in images if i.startswith(prefix)]
|
|
|
|
|
|
|
|
|
2020-02-04 20:21:53 +01:00
|
|
|
# noinspection PyUnusedLocal
|
2018-08-13 01:27:59 +02:00
|
|
|
def complete_remote_shell(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
del parsed_args
|
|
|
|
|
2019-03-28 00:40:27 +01:00
|
|
|
images = sorted(get_remote_completion().keys())
|
2018-08-13 01:27:59 +02:00
|
|
|
|
|
|
|
# 2008 doesn't support SSH so we do not add to the list of valid images
|
2019-08-06 02:40:00 +02:00
|
|
|
windows_completion_path = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'completion', 'windows.txt')
|
|
|
|
images.extend(["windows/%s" % i for i in read_lines_without_comments(windows_completion_path, remove_blank_lines=True) if i != '2008'])
|
2018-08-13 01:27:59 +02:00
|
|
|
|
|
|
|
return [i for i in images if i.startswith(prefix)]
|
|
|
|
|
|
|
|
|
2020-02-04 20:21:53 +01:00
|
|
|
# noinspection PyUnusedLocal
|
2016-12-22 18:57:17 +01:00
|
|
|
def complete_docker(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
del parsed_args
|
|
|
|
|
2017-10-26 09:21:46 +02:00
|
|
|
images = sorted(get_docker_completion().keys())
|
2016-12-22 18:57:17 +01:00
|
|
|
|
|
|
|
return [i for i in images if i.startswith(prefix)]
|
|
|
|
|
|
|
|
|
|
|
|
def complete_windows(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
2019-08-06 02:40:00 +02:00
|
|
|
images = read_lines_without_comments(os.path.join(ANSIBLE_TEST_DATA_ROOT, 'completion', 'windows.txt'), remove_blank_lines=True)
|
2016-12-22 18:57:17 +01:00
|
|
|
|
|
|
|
return [i for i in images if i.startswith(prefix) and (not parsed_args.windows or i not in parsed_args.windows)]
|
|
|
|
|
|
|
|
|
2017-01-08 08:36:35 +01:00
|
|
|
def complete_network_platform(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
2020-02-21 00:27:08 +01:00
|
|
|
images = sorted(get_network_completion())
|
2017-01-08 08:36:35 +01:00
|
|
|
|
|
|
|
return [i for i in images if i.startswith(prefix) and (not parsed_args.platform or i not in parsed_args.platform)]
|
|
|
|
|
|
|
|
|
2020-02-21 00:27:08 +01:00
|
|
|
def complete_network_platform_collection(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
left = prefix.split('=')[0]
|
|
|
|
images = sorted(set(image.split('/')[0] for image in get_network_completion()))
|
|
|
|
|
|
|
|
return [i + '=' for i in images if i.startswith(left) and (not parsed_args.platform_collection or i not in [x[0] for x in parsed_args.platform_collection])]
|
|
|
|
|
|
|
|
|
|
|
|
def complete_network_platform_connection(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
left = prefix.split('=')[0]
|
|
|
|
images = sorted(set(image.split('/')[0] for image in get_network_completion()))
|
|
|
|
|
|
|
|
return [i + '=' for i in images if i.startswith(left) and (not parsed_args.platform_connection or i not in [x[0] for x in parsed_args.platform_connection])]
|
|
|
|
|
|
|
|
|
2018-02-15 00:40:35 +01:00
|
|
|
def complete_network_testcase(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
testcases = []
|
|
|
|
|
|
|
|
# since testcases are module specific, don't autocomplete if more than one
|
|
|
|
# module is specidied
|
|
|
|
if len(parsed_args.include) != 1:
|
|
|
|
return []
|
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
test_dir = os.path.join(data_context().content.integration_targets_path, parsed_args.include[0], 'tests')
|
2019-07-23 04:24:48 +02:00
|
|
|
connection_dirs = data_context().content.get_dirs(test_dir)
|
2018-02-15 00:40:35 +01:00
|
|
|
|
2019-07-16 05:49:41 +02:00
|
|
|
for connection_dir in connection_dirs:
|
2019-07-23 04:24:48 +02:00
|
|
|
for testcase in [os.path.basename(path) for path in data_context().content.get_files(connection_dir)]:
|
2019-07-16 05:49:41 +02:00
|
|
|
if testcase.startswith(prefix):
|
|
|
|
testcases.append(testcase.split('.')[0])
|
2018-02-15 00:40:35 +01:00
|
|
|
|
|
|
|
return testcases
|
|
|
|
|
|
|
|
|
2020-02-04 20:21:53 +01:00
|
|
|
# noinspection PyUnusedLocal
|
2017-03-02 21:36:46 +01:00
|
|
|
def complete_sanity_test(prefix, parsed_args, **_):
|
|
|
|
"""
|
|
|
|
:type prefix: unicode
|
|
|
|
:type parsed_args: any
|
|
|
|
:rtype: list[str]
|
|
|
|
"""
|
|
|
|
del parsed_args
|
|
|
|
|
2020-02-06 07:16:15 +01:00
|
|
|
tests = sorted(test.name for test in sanity_get_tests())
|
2017-03-02 21:36:46 +01:00
|
|
|
|
|
|
|
return [i for i in tests if i.startswith(prefix)]
|