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:
parent
eeec62756f
commit
62c6d4ddcf
@ -1089,6 +1089,12 @@ Options
|
|||||||
|
|
||||||
Format: ``[(variant_uid_regex, {arch|*: number})]``
|
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
|
**create_jigdo** = True
|
||||||
(*bool*) -- controls the creation of jigdo from ISO
|
(*bool*) -- controls the creation of jigdo from ISO
|
||||||
|
|
||||||
|
@ -768,6 +768,9 @@ def make_schema():
|
|||||||
},
|
},
|
||||||
"createiso_skip": _variant_arch_mapping({"type": "boolean"}),
|
"createiso_skip": _variant_arch_mapping({"type": "boolean"}),
|
||||||
"createiso_max_size": _variant_arch_mapping({"type": "number"}),
|
"createiso_max_size": _variant_arch_mapping({"type": "number"}),
|
||||||
|
"createiso_max_size_is_strict": _variant_arch_mapping(
|
||||||
|
{"type": "boolean", "default": False}
|
||||||
|
),
|
||||||
"createiso_break_hardlinks": {
|
"createiso_break_hardlinks": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": False,
|
"default": False,
|
||||||
|
@ -176,6 +176,13 @@ def check_size_limit(compose, variant, arch, img):
|
|||||||
limit = getattr(img, "_max_size", None) or limits[0]
|
limit = getattr(img, "_max_size", None) or limits[0]
|
||||||
|
|
||||||
if img.size > limit:
|
if img.size > limit:
|
||||||
compose.log_warning(
|
is_strict = get_arch_variant_data(
|
||||||
"ISO %s is too big. Expected max %dB, got %dB" % (img.path, limit, img.size)
|
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)
|
||||||
|
@ -181,6 +181,27 @@ class TestCheckImageSanity(PungiTestCase):
|
|||||||
warnings,
|
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())
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
||||||
def test_too_big_unified(self):
|
def test_too_big_unified(self):
|
||||||
compose = DummyCompose(self.topdir, {})
|
compose = DummyCompose(self.topdir, {})
|
||||||
@ -198,6 +219,26 @@ class TestCheckImageSanity(PungiTestCase):
|
|||||||
warnings,
|
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())
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
||||||
def test_fits_in_limit(self):
|
def test_fits_in_limit(self):
|
||||||
compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 20})]})
|
compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 20})]})
|
||||||
|
Loading…
Reference in New Issue
Block a user