Add --list-targets and speed up --explain. (#26838)
* Add ansible-test --list-targets option. * Speed up ansible-test integration --explain.
This commit is contained in:
parent
5c8e19d630
commit
27033915cc
5 changed files with 44 additions and 20 deletions
|
@ -17,14 +17,14 @@ from lib.util import (
|
||||||
load_plugins,
|
load_plugins,
|
||||||
)
|
)
|
||||||
|
|
||||||
from lib.test import (
|
|
||||||
TestConfig,
|
|
||||||
)
|
|
||||||
|
|
||||||
from lib.target import (
|
from lib.target import (
|
||||||
TestTarget,
|
TestTarget,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from lib.config import (
|
||||||
|
IntegrationConfig,
|
||||||
|
)
|
||||||
|
|
||||||
PROVIDERS = {}
|
PROVIDERS = {}
|
||||||
ENVIRONMENTS = {}
|
ENVIRONMENTS = {}
|
||||||
|
|
||||||
|
@ -39,10 +39,13 @@ def initialize_cloud_plugins():
|
||||||
|
|
||||||
def get_cloud_platforms(args, targets=None):
|
def get_cloud_platforms(args, targets=None):
|
||||||
"""
|
"""
|
||||||
:type args: TestConfig
|
:type args: IntegrationConfig
|
||||||
:type targets: tuple[IntegrationTarget] | None
|
:type targets: tuple[IntegrationTarget] | None
|
||||||
:rtype: list[str]
|
:rtype: list[str]
|
||||||
"""
|
"""
|
||||||
|
if args.list_targets:
|
||||||
|
return []
|
||||||
|
|
||||||
if targets is None:
|
if targets is None:
|
||||||
cloud_platforms = set(args.metadata.cloud_config or [])
|
cloud_platforms = set(args.metadata.cloud_config or [])
|
||||||
else:
|
else:
|
||||||
|
@ -76,7 +79,7 @@ def get_cloud_platform(target):
|
||||||
|
|
||||||
def get_cloud_providers(args, targets=None):
|
def get_cloud_providers(args, targets=None):
|
||||||
"""
|
"""
|
||||||
:type args: TestConfig
|
:type args: IntegrationConfig
|
||||||
:type targets: tuple[IntegrationTarget] | None
|
:type targets: tuple[IntegrationTarget] | None
|
||||||
:rtype: list[CloudProvider]
|
:rtype: list[CloudProvider]
|
||||||
"""
|
"""
|
||||||
|
@ -85,7 +88,7 @@ def get_cloud_providers(args, targets=None):
|
||||||
|
|
||||||
def get_cloud_environment(args, target):
|
def get_cloud_environment(args, target):
|
||||||
"""
|
"""
|
||||||
:type args: TestConfig
|
:type args: IntegrationConfig
|
||||||
:type target: IntegrationTarget
|
:type target: IntegrationTarget
|
||||||
:rtype: CloudEnvironment
|
:rtype: CloudEnvironment
|
||||||
"""
|
"""
|
||||||
|
@ -99,7 +102,7 @@ def get_cloud_environment(args, target):
|
||||||
|
|
||||||
def cloud_filter(args, targets):
|
def cloud_filter(args, targets):
|
||||||
"""
|
"""
|
||||||
:type args: TestConfig
|
:type args: IntegrationConfig
|
||||||
:type targets: tuple[IntegrationTarget]
|
:type targets: tuple[IntegrationTarget]
|
||||||
:return: list[str]
|
:return: list[str]
|
||||||
"""
|
"""
|
||||||
|
@ -116,7 +119,7 @@ def cloud_filter(args, targets):
|
||||||
|
|
||||||
def cloud_init(args, targets):
|
def cloud_init(args, targets):
|
||||||
"""
|
"""
|
||||||
:type args: TestConfig
|
:type args: IntegrationConfig
|
||||||
:type targets: tuple[IntegrationTarget]
|
:type targets: tuple[IntegrationTarget]
|
||||||
"""
|
"""
|
||||||
if args.metadata.cloud_config is not None:
|
if args.metadata.cloud_config is not None:
|
||||||
|
@ -139,7 +142,7 @@ class CloudBase(object):
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
"""
|
"""
|
||||||
:type args: TestConfig
|
:type args: IntegrationConfig
|
||||||
"""
|
"""
|
||||||
self.args = args
|
self.args = args
|
||||||
self.platform = self.__module__.split('.')[2]
|
self.platform = self.__module__.split('.')[2]
|
||||||
|
@ -209,7 +212,7 @@ class CloudProvider(CloudBase):
|
||||||
|
|
||||||
def __init__(self, args, config_extension='.yml'):
|
def __init__(self, args, config_extension='.yml'):
|
||||||
"""
|
"""
|
||||||
:type args: TestConfig
|
:type args: IntegrationConfig
|
||||||
:type config_extension: str
|
:type config_extension: str
|
||||||
"""
|
"""
|
||||||
super(CloudProvider, self).__init__(args)
|
super(CloudProvider, self).__init__(args)
|
||||||
|
|
|
@ -143,10 +143,14 @@ class IntegrationConfig(TestConfig):
|
||||||
self.continue_on_error = args.continue_on_error # type: bool
|
self.continue_on_error = args.continue_on_error # type: bool
|
||||||
self.debug_strategy = args.debug_strategy # type: bool
|
self.debug_strategy = args.debug_strategy # type: bool
|
||||||
self.changed_all_target = args.changed_all_target # type: str
|
self.changed_all_target = args.changed_all_target # type: str
|
||||||
|
self.list_targets = args.list_targets # type: bool
|
||||||
self.tags = args.tags
|
self.tags = args.tags
|
||||||
self.skip_tags = args.skip_tags
|
self.skip_tags = args.skip_tags
|
||||||
self.diff = args.diff
|
self.diff = args.diff
|
||||||
|
|
||||||
|
if self.list_targets:
|
||||||
|
self.explain = True
|
||||||
|
|
||||||
|
|
||||||
class PosixIntegrationConfig(IntegrationConfig):
|
class PosixIntegrationConfig(IntegrationConfig):
|
||||||
"""Configuration for the posix integration command."""
|
"""Configuration for the posix integration command."""
|
||||||
|
|
|
@ -225,7 +225,7 @@ def delegate_docker(args, exclude, require):
|
||||||
'--env', 'HTTPTESTER=1',
|
'--env', 'HTTPTESTER=1',
|
||||||
]
|
]
|
||||||
|
|
||||||
if isinstance(args, TestConfig):
|
if isinstance(args, IntegrationConfig):
|
||||||
cloud_platforms = get_cloud_providers(args)
|
cloud_platforms = get_cloud_providers(args)
|
||||||
|
|
||||||
for cloud_platform in cloud_platforms:
|
for cloud_platform in cloud_platforms:
|
||||||
|
@ -305,7 +305,7 @@ def delegate_remote(args, exclude, require):
|
||||||
|
|
||||||
ssh_options = []
|
ssh_options = []
|
||||||
|
|
||||||
if isinstance(args, TestConfig):
|
if isinstance(args, IntegrationConfig):
|
||||||
cloud_platforms = get_cloud_providers(args)
|
cloud_platforms = get_cloud_providers(args)
|
||||||
|
|
||||||
for cloud_platform in cloud_platforms:
|
for cloud_platform in cloud_platforms:
|
||||||
|
|
|
@ -162,7 +162,7 @@ def install_command_requirements(args):
|
||||||
|
|
||||||
extras = []
|
extras = []
|
||||||
|
|
||||||
if isinstance(args, TestConfig):
|
if isinstance(args, IntegrationConfig):
|
||||||
extras += ['cloud.%s' % cp for cp in get_cloud_platforms(args)]
|
extras += ['cloud.%s' % cp for cp in get_cloud_platforms(args)]
|
||||||
|
|
||||||
cmd = generate_pip_install(args.command, packages, extras)
|
cmd = generate_pip_install(args.command, packages, extras)
|
||||||
|
@ -520,7 +520,7 @@ def command_integration_filtered(args, targets):
|
||||||
|
|
||||||
test_dir = os.path.expanduser('~/ansible_testing')
|
test_dir = os.path.expanduser('~/ansible_testing')
|
||||||
|
|
||||||
if any('needs/ssh/' in target.aliases for target in targets):
|
if not args.explain and any('needs/ssh/' in target.aliases for target in targets):
|
||||||
max_tries = 20
|
max_tries = 20
|
||||||
display.info('SSH service required for tests. Checking to make sure we can connect.')
|
display.info('SSH service required for tests. Checking to make sure we can connect.')
|
||||||
for i in range(1, max_tries + 1):
|
for i in range(1, max_tries + 1):
|
||||||
|
@ -544,12 +544,16 @@ def command_integration_filtered(args, targets):
|
||||||
if not found:
|
if not found:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if args.list_targets:
|
||||||
|
print(target.name)
|
||||||
|
continue
|
||||||
|
|
||||||
tries = 2 if args.retry_on_error else 1
|
tries = 2 if args.retry_on_error else 1
|
||||||
verbosity = args.verbosity
|
verbosity = args.verbosity
|
||||||
|
|
||||||
cloud_environment = get_cloud_environment(args, target)
|
cloud_environment = get_cloud_environment(args, target)
|
||||||
|
|
||||||
original_environment = EnvironmentDescription()
|
original_environment = EnvironmentDescription(args)
|
||||||
|
|
||||||
display.info('>>> Environment Description\n%s' % original_environment, verbosity=3)
|
display.info('>>> Environment Description\n%s' % original_environment, verbosity=3)
|
||||||
|
|
||||||
|
@ -1227,8 +1231,16 @@ def get_integration_remote_filter(args, targets):
|
||||||
|
|
||||||
class EnvironmentDescription(object):
|
class EnvironmentDescription(object):
|
||||||
"""Description of current running environment."""
|
"""Description of current running environment."""
|
||||||
def __init__(self):
|
def __init__(self, args):
|
||||||
"""Initialize snapshot of environment configuration."""
|
"""Initialize snapshot of environment configuration.
|
||||||
|
:type args: IntegrationConfig
|
||||||
|
"""
|
||||||
|
self.args = args
|
||||||
|
|
||||||
|
if self.args.explain:
|
||||||
|
self.data = {}
|
||||||
|
return
|
||||||
|
|
||||||
versions = ['']
|
versions = ['']
|
||||||
versions += SUPPORTED_PYTHON_VERSIONS
|
versions += SUPPORTED_PYTHON_VERSIONS
|
||||||
versions += list(set(v.split('.')[0] for v in SUPPORTED_PYTHON_VERSIONS))
|
versions += list(set(v.split('.')[0] for v in SUPPORTED_PYTHON_VERSIONS))
|
||||||
|
@ -1262,7 +1274,7 @@ class EnvironmentDescription(object):
|
||||||
:type throw: bool
|
:type throw: bool
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
current = EnvironmentDescription()
|
current = EnvironmentDescription(self.args)
|
||||||
|
|
||||||
original_json = str(self)
|
original_json = str(self)
|
||||||
current_json = str(current)
|
current_json = str(current)
|
||||||
|
|
|
@ -34,6 +34,7 @@ from lib.executor import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from lib.config import (
|
from lib.config import (
|
||||||
|
IntegrationConfig,
|
||||||
PosixIntegrationConfig,
|
PosixIntegrationConfig,
|
||||||
WindowsIntegrationConfig,
|
WindowsIntegrationConfig,
|
||||||
NetworkIntegrationConfig,
|
NetworkIntegrationConfig,
|
||||||
|
@ -81,7 +82,7 @@ def main():
|
||||||
config = args.config(args)
|
config = args.config(args)
|
||||||
display.verbosity = config.verbosity
|
display.verbosity = config.verbosity
|
||||||
display.color = config.color
|
display.color = config.color
|
||||||
display.info_stderr = isinstance(config, SanityConfig) and config.lint
|
display.info_stderr = (isinstance(config, SanityConfig) and config.lint) or (isinstance(config, IntegrationConfig) and config.list_targets)
|
||||||
check_startup()
|
check_startup()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -229,6 +230,10 @@ def parse_args():
|
||||||
default='all',
|
default='all',
|
||||||
help='target to run when all tests are needed')
|
help='target to run when all tests are needed')
|
||||||
|
|
||||||
|
integration.add_argument('--list-targets',
|
||||||
|
action='store_true',
|
||||||
|
help='list matching targets instead of running tests')
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(metavar='COMMAND')
|
subparsers = parser.add_subparsers(metavar='COMMAND')
|
||||||
subparsers.required = True # work-around for python 3 bug which makes subparsers optional
|
subparsers.required = True # work-around for python 3 bug which makes subparsers optional
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue