Skip to content

Commit

Permalink
CLI: don't assume default channel
Browse files Browse the repository at this point in the history
Default channel is server configuration, CLI tool shouldn't change it

Signed-off-by: Martin Basti <mbasti@redhat.com>
  • Loading branch information
MartinBasti committed Oct 7, 2022
1 parent 5b3e8af commit f73890b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
23 changes: 12 additions & 11 deletions koji_containerbuild/plugins/cli_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
from koji_cli.lib import _, activate_session, parse_arches, \
OptionParser, watch_tasks, _running_in_bg

# matches hub's buildContainer parameter channel
DEFAULT_CHANNEL = 'container'


def print_value(value, level, indent, suffix=''):
offset = ' ' * level * indent
Expand Down Expand Up @@ -96,8 +93,8 @@ def parse_arguments(options, args, flatpak):
parser.add_option("--git-branch", metavar="GIT_BRANCH",
help=_("Git branch"))
parser.add_option("--channel-override",
help=_("Use a non-standard channel [default: %default]"),
default=DEFAULT_CHANNEL)
help=_("Use a non-standard channel"),
default=None)
parser.add_option("--signing-intent",
help=_("Signing intent of the ODCS composes [default: %default]."
" Cannot be used with --compose-id"),
Expand Down Expand Up @@ -192,8 +189,8 @@ def parse_source_arguments(options, args):
parser.add_option("--background", action="store_true",
help=_("Run the build at a lower priority"))
parser.add_option("--channel-override",
help=_("Use a non-standard channel [default: %default]"),
default=DEFAULT_CHANNEL)
help=_("Use a non-standard channel"),
default=None)
parser.add_option("--signing-intent",
help=_("Signing intent of the ODCS composes [default: %default]."),
default=None, dest='signing_intent')
Expand Down Expand Up @@ -253,13 +250,17 @@ def handle_build(options, session, args, flatpak=False, sourcebuild=False):
# relative to koji.PRIO_DEFAULT
priority = 5

kwargs = {
'priority': priority,
}
if build_opts.channel_override:
kwargs['channel'] = build_opts.channel_override

if sourcebuild:
task_id = session.buildSourceContainer(target, opts, priority=priority,
channel=build_opts.channel_override)
task_id = session.buildSourceContainer(target, opts, **kwargs)
else:
source = args[1]
task_id = session.buildContainer(source, target, opts, priority=priority,
channel=build_opts.channel_override)
task_id = session.buildContainer(source, target, opts, **kwargs)

if not build_opts.quiet:
print("Created task: %s" % task_id)
Expand Down
11 changes: 4 additions & 7 deletions tests/test_cli_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def mock_session(target,
task_success=True,
task_result=None,
priority=None,
channel=cli_containerbuild.DEFAULT_CHANNEL,
running_in_background=False):
"""
Mock a session for the purposes of cli_containerbuild.handle_build()
Expand Down Expand Up @@ -79,12 +78,12 @@ def logout():
(session
.should_receive('buildContainer')
.with_args(source, target, dict,
priority=priority, channel=channel)
priority=priority)
.and_return(task_id))
(session
.should_receive('buildSourceContainer')
.with_args(target, dict,
priority=priority, channel=channel)
priority=priority)
.and_return(task_id))
(session
.should_receive('getTaskResult')
Expand Down Expand Up @@ -279,14 +278,13 @@ def test_cli_container_args(self, tmpdir, scratch, wait, quiet,

build_opts, parsed_args, opts, _ = parse_arguments(options, test_args, flatpak=flatpak)
expected_quiet = quiet or options.quiet
expected_channel = channel_override or 'container'

assert build_opts.scratch == scratch
assert build_opts.wait == wait
assert build_opts.quiet == expected_quiet
assert build_opts.yum_repourls == repo_url
assert build_opts.git_branch == git_branch
assert build_opts.channel_override == expected_channel
assert build_opts.channel_override == channel_override
assert build_opts.release == release
assert build_opts.compose_ids == compose_ids
assert build_opts.signing_intent == signing_intent
Expand Down Expand Up @@ -362,14 +360,13 @@ def test_cli_source_args(self, wait, quiet, channel_override,

build_opts, parsed_args, opts, _ = parse_source_arguments(options, test_args)
expected_quiet = quiet or options.quiet
expected_channel = channel_override or 'container'

assert build_opts.scratch == scratch
assert build_opts.wait == wait
assert build_opts.quiet == expected_quiet
assert build_opts.koji_build_id == koji_build_id
assert build_opts.koji_build_nvr == koji_build_nvr
assert build_opts.channel_override == expected_channel
assert build_opts.channel_override == channel_override
assert build_opts.signing_intent == signing_intent

assert parsed_args == expected_args
Expand Down

0 comments on commit f73890b

Please sign in to comment.