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,
|
||||
)
|
||||
|
||||
from lib.test import (
|
||||
TestConfig,
|
||||
)
|
||||
|
||||
from lib.target import (
|
||||
TestTarget,
|
||||
)
|
||||
|
||||
from lib.config import (
|
||||
IntegrationConfig,
|
||||
)
|
||||
|
||||
PROVIDERS = {}
|
||||
ENVIRONMENTS = {}
|
||||
|
||||
|
@ -39,10 +39,13 @@ def initialize_cloud_plugins():
|
|||
|
||||
def get_cloud_platforms(args, targets=None):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
:type args: IntegrationConfig
|
||||
:type targets: tuple[IntegrationTarget] | None
|
||||
:rtype: list[str]
|
||||
"""
|
||||
if args.list_targets:
|
||||
return []
|
||||
|
||||
if targets is None:
|
||||
cloud_platforms = set(args.metadata.cloud_config or [])
|
||||
else:
|
||||
|
@ -76,7 +79,7 @@ def get_cloud_platform(target):
|
|||
|
||||
def get_cloud_providers(args, targets=None):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
:type args: IntegrationConfig
|
||||
:type targets: tuple[IntegrationTarget] | None
|
||||
:rtype: list[CloudProvider]
|
||||
"""
|
||||
|
@ -85,7 +88,7 @@ def get_cloud_providers(args, targets=None):
|
|||
|
||||
def get_cloud_environment(args, target):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
:type args: IntegrationConfig
|
||||
:type target: IntegrationTarget
|
||||
:rtype: CloudEnvironment
|
||||
"""
|
||||
|
@ -99,7 +102,7 @@ def get_cloud_environment(args, target):
|
|||
|
||||
def cloud_filter(args, targets):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
:type args: IntegrationConfig
|
||||
:type targets: tuple[IntegrationTarget]
|
||||
:return: list[str]
|
||||
"""
|
||||
|
@ -116,7 +119,7 @@ def cloud_filter(args, targets):
|
|||
|
||||
def cloud_init(args, targets):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
:type args: IntegrationConfig
|
||||
:type targets: tuple[IntegrationTarget]
|
||||
"""
|
||||
if args.metadata.cloud_config is not None:
|
||||
|
@ -139,7 +142,7 @@ class CloudBase(object):
|
|||
|
||||
def __init__(self, args):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
:type args: IntegrationConfig
|
||||
"""
|
||||
self.args = args
|
||||
self.platform = self.__module__.split('.')[2]
|
||||
|
@ -209,7 +212,7 @@ class CloudProvider(CloudBase):
|
|||
|
||||
def __init__(self, args, config_extension='.yml'):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
:type args: IntegrationConfig
|
||||
:type config_extension: str
|
||||
"""
|
||||
super(CloudProvider, self).__init__(args)
|
||||
|
|
|
@ -143,10 +143,14 @@ class IntegrationConfig(TestConfig):
|
|||
self.continue_on_error = args.continue_on_error # type: bool
|
||||
self.debug_strategy = args.debug_strategy # type: bool
|
||||
self.changed_all_target = args.changed_all_target # type: str
|
||||
self.list_targets = args.list_targets # type: bool
|
||||
self.tags = args.tags
|
||||
self.skip_tags = args.skip_tags
|
||||
self.diff = args.diff
|
||||
|
||||
if self.list_targets:
|
||||
self.explain = True
|
||||
|
||||
|
||||
class PosixIntegrationConfig(IntegrationConfig):
|
||||
"""Configuration for the posix integration command."""
|
||||
|
|
|
@ -225,7 +225,7 @@ def delegate_docker(args, exclude, require):
|
|||
'--env', 'HTTPTESTER=1',
|
||||
]
|
||||
|
||||
if isinstance(args, TestConfig):
|
||||
if isinstance(args, IntegrationConfig):
|
||||
cloud_platforms = get_cloud_providers(args)
|
||||
|
||||
for cloud_platform in cloud_platforms:
|
||||
|
@ -305,7 +305,7 @@ def delegate_remote(args, exclude, require):
|
|||
|
||||
ssh_options = []
|
||||
|
||||
if isinstance(args, TestConfig):
|
||||
if isinstance(args, IntegrationConfig):
|
||||
cloud_platforms = get_cloud_providers(args)
|
||||
|
||||
for cloud_platform in cloud_platforms:
|
||||
|
|
|
@ -162,7 +162,7 @@ def install_command_requirements(args):
|
|||
|
||||
extras = []
|
||||
|
||||
if isinstance(args, TestConfig):
|
||||
if isinstance(args, IntegrationConfig):
|
||||
extras += ['cloud.%s' % cp for cp in get_cloud_platforms(args)]
|
||||
|
||||
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')
|
||||
|
||||
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
|
||||
display.info('SSH service required for tests. Checking to make sure we can connect.')
|
||||
for i in range(1, max_tries + 1):
|
||||
|
@ -544,12 +544,16 @@ def command_integration_filtered(args, targets):
|
|||
if not found:
|
||||
continue
|
||||
|
||||
if args.list_targets:
|
||||
print(target.name)
|
||||
continue
|
||||
|
||||
tries = 2 if args.retry_on_error else 1
|
||||
verbosity = args.verbosity
|
||||
|
||||
cloud_environment = get_cloud_environment(args, target)
|
||||
|
||||
original_environment = EnvironmentDescription()
|
||||
original_environment = EnvironmentDescription(args)
|
||||
|
||||
display.info('>>> Environment Description\n%s' % original_environment, verbosity=3)
|
||||
|
||||
|
@ -1227,8 +1231,16 @@ def get_integration_remote_filter(args, targets):
|
|||
|
||||
class EnvironmentDescription(object):
|
||||
"""Description of current running environment."""
|
||||
def __init__(self):
|
||||
"""Initialize snapshot of environment configuration."""
|
||||
def __init__(self, args):
|
||||
"""Initialize snapshot of environment configuration.
|
||||
:type args: IntegrationConfig
|
||||
"""
|
||||
self.args = args
|
||||
|
||||
if self.args.explain:
|
||||
self.data = {}
|
||||
return
|
||||
|
||||
versions = ['']
|
||||
versions += 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
|
||||
:rtype: bool
|
||||
"""
|
||||
current = EnvironmentDescription()
|
||||
current = EnvironmentDescription(self.args)
|
||||
|
||||
original_json = str(self)
|
||||
current_json = str(current)
|
||||
|
|
|
@ -34,6 +34,7 @@ from lib.executor import (
|
|||
)
|
||||
|
||||
from lib.config import (
|
||||
IntegrationConfig,
|
||||
PosixIntegrationConfig,
|
||||
WindowsIntegrationConfig,
|
||||
NetworkIntegrationConfig,
|
||||
|
@ -81,7 +82,7 @@ def main():
|
|||
config = args.config(args)
|
||||
display.verbosity = config.verbosity
|
||||
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()
|
||||
|
||||
try:
|
||||
|
@ -229,6 +230,10 @@ def parse_args():
|
|||
default='all',
|
||||
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.required = True # work-around for python 3 bug which makes subparsers optional
|
||||
|
||||
|
|
Loading…
Reference in a new issue