From 805a1083a22c0ff1061fafd35a1f0dda951fa55a Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Thu, 1 Sep 2022 16:41:17 +0200 Subject: [PATCH] osbuild: accept only a single image type in the configuration Modify the osbuild configuration schema to accept only an array with a single value as the `image_types`, in addition to a single string. The single string was supported by the schema also before, but this fact was not mentioned in the documentation, nor it was supported by the `koji-osbuild` plugin of version lower than `9`. Update the documentation accordingly. Add unit test for invalid configuration containing more than one image type. Signed-off-by: Tomas Hozza --- doc/configuration.rst | 4 +++- pungi/checks.py | 16 +++++++++++++++- tests/test_osbuild_phase.py | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index d91d37d8..5d9947b1 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1594,7 +1594,9 @@ OSBuild Composer for building images * ``name`` -- name of the Koji package * ``distro`` -- image for which distribution should be build TODO examples - * ``image_types`` -- a list of image types to build (e.g. ``qcow2``) + * ``image_types`` -- a list with a single image type string or just a + string representing the image type to build (e.g. ``qcow2``). In any + case, only a single image type can be provided as an argument. Optional keys: diff --git a/pungi/checks.py b/pungi/checks.py index 80d4e506..a014c6be 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -1171,7 +1171,21 @@ def make_schema(): "version": {"type": "string"}, "distro": {"type": "string"}, "target": {"type": "string"}, - "image_types": {"$ref": "#/definitions/strings"}, + # Only a single image_type can be specified + # https://github.com/osbuild/koji-osbuild/commit/c7252650814f82281ee57b598cb2ad970b580451 + # https://github.com/osbuild/koji-osbuild/commit/f21a2de39b145eb94f3d49cb4d8775a33ba56752 + "image_types": { + "oneOf": [ + { + "type": "array", + "items": {"type": "string"}, + "description": "Deprecated variant", + "minItems": 1, + "maxItems": 1, + }, + {"type": "string"}, + ] + }, "arches": {"$ref": "#/definitions/list_of_strings"}, "release": {"type": "string"}, "repo": {"$ref": "#/definitions/list_of_strings"}, diff --git a/tests/test_osbuild_phase.py b/tests/test_osbuild_phase.py index b3f5078a..b740a82a 100644 --- a/tests/test_osbuild_phase.py +++ b/tests/test_osbuild_phase.py @@ -8,6 +8,7 @@ import koji as orig_koji from tests import helpers from pungi.phases import osbuild +from pungi.checks import validate class OSBuildPhaseTest(helpers.PungiTestCase): @@ -105,6 +106,24 @@ class OSBuildPhaseTest(helpers.PungiTestCase): phase = osbuild.OSBuildPhase(compose) self.assertTrue(phase.skip()) + def test_fail_multiple_image_types(self): + cfg = { + "name": "test-image", + "distro": "rhel-8", + # more than one image type is not allowed + "image_types": ["qcow2", "rhel-ec2"], + } + compose = helpers.DummyCompose( + self.topdir, + { + "osbuild": {"^Everything$": [cfg]}, + "osbuild_target": "image-target", + "osbuild_version": "1", + "osbuild_release": "2", + }, + ) + self.assertNotEqual(validate(compose.conf), ([], [])) + class RunOSBuildThreadTest(helpers.PungiTestCase): def setUp(self):