Skip to content

Commit

Permalink
Add schedule --fixture option
Browse files Browse the repository at this point in the history
Allows to define fixture from cmd line.
Example:
newa ... schedule --fixture testingfarm.cli_args="something" --fixture
environment.FOO=bar ...
  • Loading branch information
kkaarreell committed Dec 11, 2024
1 parent e19d04b commit c4fbd17
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion newa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
eval_test,
get_url_basename,
render_template,
yaml_parser,
)

JIRA_NONE_ID = '_NO_ISSUE'
Expand Down Expand Up @@ -802,8 +803,15 @@ def _jira_fake_id_generator() -> Generator[str, int, None]:
help=('Restrics system architectures to use when scheduling. '
'Can be specified multiple times. Example: --arch x86_64'),
)
@click.option('--fixture',
'fixtures',
default=[],
multiple=True,
help=('Define single fixture value on a cmdline. Can be specified multiple times. '
'Example: --fixture testingfarm.cli_args="--repository-file URL"'),
)
@click.pass_obj
def cmd_schedule(ctx: CLIContext, arch: list[str]) -> None:
def cmd_schedule(ctx: CLIContext, arch: list[str], fixtures: list[str]) -> None:
ctx.enter_command('schedule')

for jira_job in ctx.load_jira_jobs('jira-'):
Expand All @@ -822,6 +830,30 @@ def cmd_schedule(ctx: CLIContext, arch: list[str]) -> None:
initial_config = RawRecipeConfigDimension(compose=compose,
environment=ctx.cli_environment,
context=ctx.cli_context)
ctx.logger.debug(f'Initial config: {initial_config})')
if fixtures:
for fixture in fixtures:
r = re.fullmatch(r'([^\s=]+)=([^=]*)', fixture)
if not r:
raise Exception(
f"Fixture {fixture} does not having expected format 'name=value'")
fixture_name, fixture_value = r.groups()
fixture_config = initial_config
# descent through keys to the lowest level
while '.' in fixture_name:
prefix, suffix = fixture_name.split('.', 1)
if prefix not in fixture_config:
fixture_config[prefix] = {}
fixture_config = fixture_config[prefix]
fixture_name = suffix
# now we are at the lowest level
value = yaml_parser().load(fixture_value)
if value is None:
del fixture_config[fixture_name]
else:
fixture_config[fixture_name] = value
ctx.logger.debug(f'Initial config modified through --fixture: {initial_config})')

# when testing erratum, add special context erratum=XXXX
if jira_job.erratum:
initial_config['context'].update({'erratum': str(jira_job.erratum.id)})
Expand Down

0 comments on commit c4fbd17

Please sign in to comment.