Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schedule --fixture option #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 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,17 @@ 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=('Sets a single fixture default on a cmdline. '
'Use with caution, hic sun leones. '
'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 +832,29 @@ 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] = {} # type: ignore[literal-required]
fixture_config = fixture_config[prefix] # type: ignore[literal-required]
fixture_name = suffix
# now we are at the lowest level
# Is it beneficial to parse the input as yaml?
# It enables us to define list and dicts but there might be drawbacks as well
value = yaml_parser().load(fixture_value)
fixture_config[fixture_name] = value # type: ignore[literal-required]
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
Loading