plugins: ability to skip the tagging

Add a new command line option `--skip-tag` that will skip tagging
after a successful build. The help text is copied from the same
option of other sub-commands in the koji client. The hub plugin's
jsonschema was updated accordingly, and the builder plugin will
skip the tag if the option was requested.
Tests were added or augmented for all three plugins to test the
new option.
This commit is contained in:
Christian Kellner 2020-11-05 14:07:35 +01:00
parent a21c732ce0
commit d7bfaee189
6 changed files with 44 additions and 4 deletions

View file

@ -416,7 +416,9 @@ class OSBuildImage(BaseTaskHandler):
if not status.is_success:
raise koji.BuildError(f"Compose failed (id: {cid})")
self.tag_build(target_info["dest_tag"], bid)
# Build was successful, tag it
if not opts.get('skip_tag'):
self.tag_build(target_info["dest_tag"], bid)
result = {
"composer": {

View file

@ -30,6 +30,8 @@ def parse_args(argv):
parser.add_option("--image-type", metavar="TYPE",
help='Request an image-type [default: qcow2]',
type=str, action="append", default=[])
parser.add_option("--skip-tag", action="store_true",
help=_("Do not attempt to tag package"))
parser.add_option("--wait", action="store_true",
help=_("Wait on the image creation, even if running in the background"))
@ -78,6 +80,9 @@ def handle_osbuild_image(options, session, argv):
if args.repo:
opts["repo"] = args.repo
if args.skip_tag:
opts["skip_tag"] = True
# Do some early checks to be able to give quick feedback
check_target(session, target)

View file

@ -64,6 +64,10 @@ OSBUILD_IMAGE_SCHEMA = {
"release": {
"type": "string",
"description": "Release override"
},
"skip_tag": {
"type": "boolean",
"description": "Omit tagging the result"
}
}
}

View file

@ -536,9 +536,35 @@ class TestBuilderPlugin(PluginTest):
assert res, "invalid compose result"
self.uploads.assert_upload("compose-request.json")
with self.assertRaises(AssertionError):
self.uploads.assert_upload("x86_64-image_type.log.json")
@httpretty.activate
def test_skip_tag(self):
# Simulate a successful compose, where the tagging
# should be skipped
session = self.mock_session()
handler = self.make_handler(session=session)
url = self.plugin.DEFAULT_COMPOSER_URL
composer = MockComposer(url)
composer.httpretty_regsiter()
args = ["name", "version", "distro",
["image_type"],
"fedora-candidate",
composer.architectures,
{"skip_tag": True}]
res = handler.handler(*args)
assert res, "invalid compose result"
self.uploads.assert_upload("compose-request.json")
# build must *not* have been tagged
self.assertEqual(len(session.host.tags), 0)
@httpretty.activate
def test_cli_compose_success(self):
# Check the basic usage of the plugin as a stand-alone client

View file

@ -83,7 +83,8 @@ class TestCliPlugin(PluginTest):
# optional keyword arguments
"--repo", "https://first.repo",
"--repo", "https://second.repo",
"--release", "20200202.n2"
"--release", "20200202.n2",
"--skip-tag"
]
expected_args = ["name", "version", "distro",
@ -93,7 +94,8 @@ class TestCliPlugin(PluginTest):
expected_opts = {
"release": "20200202.n2",
"repo": ["https://first.repo", "https://second.repo"]
"repo": ["https://first.repo", "https://second.repo"],
"skip_tag": True
}
task_result = {"compose_id": "42", "build_id": 23}

View file

@ -43,7 +43,8 @@ class TestHubPlugin(PluginTest):
context = self.mock_koji_context()
opts = {"repo": ["repo1", "repo2"],
"release": "1.2.3"}
"release": "1.2.3",
"skip_tag": True}
args = ["name", "version", "distro",
["image_type"],
"target",