From 62c6d4ddcf7ab6f38ce926d43f7e309e215a01f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 15 Jul 2019 09:25:26 +0200 Subject: [PATCH] test: Option to make size check strict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes it's practical not just warn when ISO is larger than expected, but to also abort the compose. JIRA: COMPOSE-3658 Signed-off-by: Lubomír Sedlář --- doc/configuration.rst | 6 ++++++ pungi/checks.py | 3 +++ pungi/phases/test.py | 11 +++++++++-- tests/test_test_phase.py | 41 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 115a05e1..08bebbc7 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1089,6 +1089,12 @@ Options Format: ``[(variant_uid_regex, {arch|*: number})]`` +**createiso_max_size_is_strict** + (*list*) -- Set the value to ``True`` to turn the warning from + ``createiso_max_size`` into a hard error that will abort the compose. + + Format: ``[(variant_uid_regex, {arch|*: bool})]`` + **create_jigdo** = True (*bool*) -- controls the creation of jigdo from ISO diff --git a/pungi/checks.py b/pungi/checks.py index 26749660..7073f834 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -768,6 +768,9 @@ def make_schema(): }, "createiso_skip": _variant_arch_mapping({"type": "boolean"}), "createiso_max_size": _variant_arch_mapping({"type": "number"}), + "createiso_max_size_is_strict": _variant_arch_mapping( + {"type": "boolean", "default": False} + ), "createiso_break_hardlinks": { "type": "boolean", "default": False, diff --git a/pungi/phases/test.py b/pungi/phases/test.py index a8fe4506..03f33de3 100644 --- a/pungi/phases/test.py +++ b/pungi/phases/test.py @@ -176,6 +176,13 @@ def check_size_limit(compose, variant, arch, img): limit = getattr(img, "_max_size", None) or limits[0] if img.size > limit: - compose.log_warning( - "ISO %s is too big. Expected max %dB, got %dB" % (img.path, limit, img.size) + is_strict = get_arch_variant_data( + compose.conf, "createiso_max_size_is_strict", arch, variant ) + msg = "ISO %s is too big. Expected max %dB, got %dB" % ( + img.path, limit, img.size + ) + if is_strict: + raise RuntimeError(msg) + else: + compose.log_warning(msg) diff --git a/tests/test_test_phase.py b/tests/test_test_phase.py index d974473c..adcd0998 100644 --- a/tests/test_test_phase.py +++ b/tests/test_test_phase.py @@ -181,6 +181,27 @@ class TestCheckImageSanity(PungiTestCase): warnings, ) + @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) + def test_too_big_iso_strict(self): + compose = DummyCompose( + self.topdir, + { + "createiso_max_size": [(".*", {"*": 10})], + "createiso_max_size_is_strict": [(".*", {"*": True})], + }, + ) + compose.image.format = 'iso' + compose.image.bootable = False + compose.image.size = 20 + + with self.assertRaises(RuntimeError) as ctx: + test_phase.check_image_sanity(compose) + + self.assertEqual( + str(ctx.exception), + "ISO Client/i386/iso/image.iso is too big. Expected max 10B, got 20B", + ) + @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) def test_too_big_unified(self): compose = DummyCompose(self.topdir, {}) @@ -198,6 +219,26 @@ class TestCheckImageSanity(PungiTestCase): warnings, ) + @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) + def test_too_big_unified_strict(self): + compose = DummyCompose( + self.topdir, + {"createiso_max_size_is_strict": [(".*", {"*": True})]}, + ) + compose.image.format = 'iso' + compose.image.bootable = False + compose.image.size = 20 + compose.image.unified = True + setattr(compose.image, "_max_size", 10) + + with self.assertRaises(RuntimeError) as ctx: + test_phase.check_image_sanity(compose) + + self.assertEqual( + str(ctx.exception), + "ISO Client/i386/iso/image.iso is too big. Expected max 10B, got 20B", + ) + @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) def test_fits_in_limit(self): compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 20})]})