From 9d02f87c9920275cf9820afd88cd3bea9d50b053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 4 Nov 2021 09:01:28 +0100 Subject: [PATCH] Stop trying to validate non-existent metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a compose doesn't build any images, it won't produce any metadata file for them, and thus it makes no sense to validate it. Signed-off-by: Lubomír Sedlář Fixes: https://pagure.io/pungi/issue/1565 --- pungi/phases/test.py | 6 +- .../compose/metadata/images.json | 58 +++++++++++++++++++ tests/test_test_phase.py | 30 +++++++++- 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/invalid-image-metadata/compose/metadata/images.json diff --git a/pungi/phases/test.py b/pungi/phases/test.py index b4e87ab1..099af558 100644 --- a/pungi/phases/test.py +++ b/pungi/phases/test.py @@ -53,9 +53,9 @@ def check_image_metadata(compose): Often caused by isos with duplicate metadata. Accessing the `images` attribute will raise an exception if there's a problem """ - - compose = productmd.compose.Compose(compose.paths.compose.topdir()) - return compose.images + if compose.im.images: + compose = productmd.compose.Compose(compose.paths.compose.topdir()) + return compose.images def check_sanity(compose, variant, arch, image): diff --git a/tests/fixtures/invalid-image-metadata/compose/metadata/images.json b/tests/fixtures/invalid-image-metadata/compose/metadata/images.json new file mode 100644 index 00000000..025d329e --- /dev/null +++ b/tests/fixtures/invalid-image-metadata/compose/metadata/images.json @@ -0,0 +1,58 @@ +{ + "header": { + "type": "productmd.images", + "version": "1.2" + }, + "payload": { + "compose": { + "date": "20181001", + "id": "Mixed-1.0-20181001.n.0", + "respin": 0, + "type": "nightly" + }, + "images": { + "Server": { + "x86_64": [ + { + "arch": "x86_64", + "bootable": false, + "checksums": { + "md5": "c7977d67f6522bce7fb04c0818a3c744", + "sha1": "c7d65673b2eb477016f9e09f321935bace545515", + "sha256": "6d9cfc9be59cba96763dcca5d1b5759127d2f7920055b663dbcf29474bc368de" + }, + "disc_count": 1, + "disc_number": 1, + "format": "iso", + "implant_md5": "340b7dc15b9c74b8576b81c3b33fc3f2", + "mtime": 1636012560, + "path": "Server-Gluster/x86_64/iso/Gluster-2.3-DP-1-20211104.t.4-Server-x86_64-dvd1.iso", + "size": 419840, + "subvariant": "Server-Gluster", + "type": "dvd", + "volume_id": "Gluster-2.3 DP-1 Server.x86_64" + }, + { + "arch": "x86_64", + "bootable": false, + "checksums": { + "md5": "a7977d67f6522bce7fb04c0818a3c744", + "sha1": "a7d65673b2eb477016f9e09f321935bace545515", + "sha256": "ad9cfc9be59cba96763dcca5d1b5759127d2f7920055b663dbcf29474bc368de" + }, + "disc_count": 1, + "disc_number": 1, + "format": "iso", + "implant_md5": "340b7dc15b9c74b8576b81c3b33fc3f2", + "mtime": 1636012560, + "path": "Server-Gluster/x86_64/iso/Gluster-2.3-DP-1-20211104.t.4-Server-x86_64-dvd1.iso", + "size": 419840, + "subvariant": "Server-Gluster", + "type": "dvd", + "volume_id": "Gluster-2.3 DP-1 Server.x86_64" + } + ] + } + } + } +} diff --git a/tests/test_test_phase.py b/tests/test_test_phase.py index 4e82d051..1b6f1ad1 100644 --- a/tests/test_test_phase.py +++ b/tests/test_test_phase.py @@ -4,7 +4,7 @@ import mock import os import pungi.phases.test as test_phase -from tests.helpers import DummyCompose, PungiTestCase, touch +from tests.helpers import DummyCompose, PungiTestCase, touch, FIXTURE_DIR try: import dnf # noqa: F401 @@ -305,3 +305,31 @@ class TestCheckImageSanity(PungiTestCase): test_phase.check_image_sanity(compose) self.assertEqual(compose.log_warning.call_args_list, []) + + +class TestImageMetadataValidation(PungiTestCase): + def test_valid_metadata(self): + compose = mock.Mock() + compose.im.images = {"Server": mock.Mock()} + compose.paths.compose.topdir = lambda: os.path.join( + FIXTURE_DIR, "basic-metadata" + ) + + test_phase.check_image_metadata(compose) + + def test_missing_metadata(self): + compose = mock.Mock() + compose.im.images = {} + compose.paths.compose.topdir = lambda: self.topdir + + test_phase.check_image_metadata(compose) + + def test_invalid_metadata(self): + compose = mock.Mock() + compose.im.images = {"Server": mock.Mock()} + compose.paths.compose.topdir = lambda: os.path.join( + FIXTURE_DIR, "invalid-image-metadata" + ) + + with self.assertRaises(RuntimeError): + test_phase.check_image_metadata(compose)