plugins: support for ostree specific options

OStree compose requests need special options, like the `ref` the
`parent` and the `url`. Add support for those options to all three
plugins:
  The command line plugin now takes `--ostree-{parent,ref,url}`
  and passes it to koji via the existing options dictionary.

  The JSON schemata in the hub plugin was adjusted to allow these
  new options.

  Finally the builder plugin will look for the new `ostree` dict
  inside the options, create an `OSTreeOptions` object from it,
  and attach it to each image request.

NB: since the ostree options are per image request and are thus
architecture dependent we support a "$arch" substition in the
`parent` and `ref` options that will be resolved by the plugin;
this allows to builds arch specific commits for with a single
compose request.

Add the respective unit tests.
This commit is contained in:
Christian Kellner 2022-02-14 10:02:11 +00:00 committed by Achilleas Koutsou
parent ce21817676
commit 78ed04dbd6
5 changed files with 189 additions and 2 deletions

View file

@ -909,3 +909,54 @@ class TestBuilderPlugin(PluginTest):
res = handler.handler(*args)
assert res, "invalid compose result"
@httpretty.activate
def test_ostree_compose(self):
# Check we properly handle ostree compose requests
session = self.mock_session()
handler = self.make_handler(session=session)
arches = ["x86_64", "s390x"]
repos = ["http://1.repo", "https://2.repo"]
args = ["name", "version", "distro",
["image_type"],
"fedora-candidate",
arches,
{"repo": repos,
"ostree": {
"parent": "osbuild/$arch/p",
"ref": "osbuild/$arch/r",
"url": "https://osbuild.org/repo"
}}]
url = self.plugin.DEFAULT_COMPOSER_URL
composer = MockComposer(url, architectures=arches)
composer.httpretty_regsiter()
res = handler.handler(*args)
assert res, "invalid compose result"
compose_id = res["composer"]["id"]
compose = composer.composes.get(compose_id)
self.assertIsNotNone(compose)
ireqs = compose["request"]["image_requests"]
# Check we got all the requested architectures
ireq_arches = [i["architecture"] for i in ireqs]
diff = set(arches) ^ set(ireq_arches)
self.assertEqual(diff, set())
for ir in ireqs:
assert "ostree" in ir
ostree = ir["ostree"]
for key in ("parent", "ref", "url"):
assert key in ostree
assert ostree["url"] == "https://osbuild.org/repo"
ireq_parents = [i["ostree"]["parent"] for i in ireqs]
diff = set(f"osbuild/{a}/p" for a in arches) ^ set(ireq_parents)
self.assertEqual(diff, set())
ireq_refs = [i["ostree"]["ref"] for i in ireqs]
diff = set(f"osbuild/{a}/r" for a in arches) ^ set(ireq_refs)
self.assertEqual(diff, set())

View file

@ -125,6 +125,63 @@ class TestCliPlugin(PluginTest):
r = self.plugin.handle_osbuild_image(options, session, argv)
self.assertEqual(r, 0)
def test_ostree_options(self):
# Check we properly handle ostree specific options
argv = [
# the required positional arguments
"name", "version", "distro", "target", "arch1",
# optional keyword arguments
"--repo", "https://first.repo",
"--repo", "https://second.repo",
"--release", "20200202.n2",
"--ostree-parent", "ostree/$arch/staging",
"--ostree-ref", "ostree/$arch/production",
"--ostree-url", "https://osbuild.org/repo",
]
expected_args = ["name", "version", "distro",
['guest-image'], # the default image type
"target",
['arch1']]
expected_opts = {
"release": "20200202.n2",
"repo": ["https://first.repo", "https://second.repo"],
"ostree": {
"parent": "ostree/$arch/staging",
"ref": "ostree/$arch/production",
"url": "https://osbuild.org/repo",
}
}
task_result = {"compose_id": "42", "build_id": 23}
task_id = 1
koji_lib = self.mock_koji_lib()
options = self.mock_options()
session = flexmock()
self.mock_session_add_valid_tag(session)
session.should_receive("osbuildImage") \
.with_args(*expected_args, opts=expected_opts) \
.and_return(task_id) \
.once()
session.should_receive("logout") \
.with_args() \
.once()
session.should_receive("getTaskResult") \
.with_args(task_id) \
.and_return(task_result) \
.once()
setattr(self.plugin, "kl", koji_lib)
r = self.plugin.handle_osbuild_image(options, session, argv)
self.assertEqual(r, 0)
def test_target_check(self):
# unknown build target
session = flexmock()