test: Option to make size check strict

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-07-15 09:25:26 +02:00
parent eeec62756f
commit 62c6d4ddcf
4 changed files with 59 additions and 2 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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})]})