ansible-test - Fix handling of args after `--` (#78328)

pull/78332/head
Matt Clay 2 years ago committed by GitHub
parent 399e34ddd6
commit 0012263c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible-test - Delegation now properly handles arguments given after ``--`` on the command line.

@ -269,8 +269,8 @@ class IntegrationConfig(TestConfig):
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
self.no_temp_workdir = args.no_temp_workdir self.no_temp_workdir = args.no_temp_workdir # type: bool
self.no_temp_unicode = args.no_temp_unicode self.no_temp_unicode = args.no_temp_unicode # type: bool
if self.list_targets: if self.list_targets:
self.explain = True self.explain = True

@ -15,7 +15,6 @@ from .config import (
CommonConfig, CommonConfig,
EnvironmentConfig, EnvironmentConfig,
IntegrationConfig, IntegrationConfig,
SanityConfig,
ShellConfig, ShellConfig,
TestConfig, TestConfig,
UnitsConfig, UnitsConfig,
@ -248,11 +247,6 @@ def generate_command(
require, # type: t.List[str] require, # type: t.List[str]
): # type: (...) -> t.List[str] ): # type: (...) -> t.List[str]
"""Generate the command necessary to delegate ansible-test.""" """Generate the command necessary to delegate ansible-test."""
options = {
'--color': 1,
'--docker-no-pull': 0,
}
cmd = [os.path.join(ansible_bin_path, 'ansible-test')] cmd = [os.path.join(ansible_bin_path, 'ansible-test')]
cmd = [python.path] + cmd cmd = [python.path] + cmd
@ -288,16 +282,7 @@ def generate_command(
cmd = ['/usr/bin/env'] + env_args + cmd cmd = ['/usr/bin/env'] + env_args + cmd
cmd += list(filter_options(args, args.host_settings.filtered_args, options, exclude, require)) cmd += list(filter_options(args, args.host_settings.filtered_args, exclude, require))
cmd += ['--color', 'yes' if args.color else 'no']
if isinstance(args, SanityConfig):
base_branch = args.base_branch or get_ci_provider().get_base_branch()
if base_branch:
cmd += ['--base-branch', base_branch]
cmd.extend(['--host-path', args.host_path])
return cmd return cmd
@ -305,66 +290,55 @@ def generate_command(
def filter_options( def filter_options(
args, # type: EnvironmentConfig args, # type: EnvironmentConfig
argv, # type: t.List[str] argv, # type: t.List[str]
options, # type: t.Dict[str, int]
exclude, # type: t.List[str] exclude, # type: t.List[str]
require, # type: t.List[str] require, # type: t.List[str]
): # type: (...) -> t.Iterable[str] ): # type: (...) -> t.Iterable[str]
"""Return an iterable that filters out unwanted CLI options and injects new ones as requested.""" """Return an iterable that filters out unwanted CLI options and injects new ones as requested."""
options = options.copy() replace: list[tuple[str, int, t.Optional[t.Union[bool, str, list[str]]]]] = [
('--docker-no-pull', 0, False),
options['--truncate'] = 1 ('--truncate', 1, str(args.truncate)),
options['--redact'] = 0 ('--color', 1, 'yes' if args.color else 'no'),
options['--no-redact'] = 0 ('--redact', 0, False),
('--no-redact', 0, not args.redact),
('--host-path', 1, args.host_path),
]
if isinstance(args, TestConfig): if isinstance(args, TestConfig):
options.update({ replace.extend([
'--changed': 0, ('--changed', 0, False),
'--tracked': 0, ('--tracked', 0, False),
'--untracked': 0, ('--untracked', 0, False),
'--ignore-committed': 0, ('--ignore-committed', 0, False),
'--ignore-staged': 0, ('--ignore-staged', 0, False),
'--ignore-unstaged': 0, ('--ignore-unstaged', 0, False),
'--changed-from': 1, ('--changed-from', 1, False),
'--changed-path': 1, ('--changed-path', 1, False),
'--metadata': 1, ('--metadata', 1, args.metadata_path),
'--exclude': 1, ('--exclude', 1, exclude),
'--require': 1, ('--require', 1, require),
}) ('--base-branch', 1, args.base_branch or get_ci_provider().get_base_branch()),
elif isinstance(args, SanityConfig): ])
options.update({
'--base-branch': 1, pass_through_args: list[str] = []
})
for arg in filter_args(argv, {option: count for option, count, replacement in replace}):
if isinstance(args, IntegrationConfig): if arg == '--' or pass_through_args:
options.update({ pass_through_args.append(arg)
'--no-temp-unicode': 0, continue
})
for arg in filter_args(argv, options):
yield arg
for arg in args.delegate_args:
yield arg yield arg
for target in exclude: for option, _count, replacement in replace:
yield '--exclude' if not replacement:
yield target continue
for target in require:
yield '--require'
yield target
if isinstance(args, TestConfig):
if args.metadata_path:
yield '--metadata'
yield args.metadata_path
yield '--truncate'
yield '%d' % args.truncate
if not args.redact: if isinstance(replacement, bool):
yield '--no-redact' yield option
elif isinstance(replacement, str):
yield from [option, replacement]
elif isinstance(replacement, list):
for item in replacement:
yield from [option, item]
if isinstance(args, IntegrationConfig): yield from args.delegate_args
if args.no_temp_unicode: yield from pass_through_args
yield '--no-temp-unicode'

Loading…
Cancel
Save