From 22e94caf3c46dcb7c6aaacaf7ff0c225b95c3f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Fri, 22 Jul 2016 13:58:29 +0200 Subject: [PATCH] [test] Correctly check bootable ISOs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISO image without MBR and GPT can still be bootable if it has an El Torito boot catalog. The test phase must accept such images. This slightly defeats the point of the check: to verify the ISO is hybrid. However, based on the metadata we have no way to actually tell if the image is supposed to be hybrid. Signed-off-by: Lubomír Sedlář --- pungi/phases/test.py | 12 +++++++++--- tests/test_test_phase.py | 21 +++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pungi/phases/test.py b/pungi/phases/test.py index c7594194..5650f6d9 100644 --- a/pungi/phases/test.py +++ b/pungi/phases/test.py @@ -127,13 +127,15 @@ def check(compose, variant, arch, image): deliverable = getattr(image, 'deliverable') with failable(compose, variant, arch, deliverable, subvariant=image.subvariant): with open(path) as f: - if image.format == 'iso' and not is_iso(f): + iso = is_iso(f) + if image.format == 'iso' and not iso: result = False raise RuntimeError('%s does not look like an ISO file' % path) - if image.bootable and not has_mbr(f) and not has_gpt(f): + if image.bootable and not has_mbr(f) and not has_gpt(f) and not (iso and has_eltorito(f)): result = False raise RuntimeError( - '%s is supposed to be bootable, but does not have MBR nor GPT' % path) + '%s is supposed to be bootable, but does not have MBR nor ' + 'GPT nor is it a bootable ISO' % path) # If exception is raised above, failable may catch it return result @@ -154,3 +156,7 @@ def has_mbr(f): def has_gpt(f): return _check_magic(f, 0x200, 'EFI PART') + + +def has_eltorito(f): + return _check_magic(f, 0x8801, 'CD001\1EL TORITO SPECIFICATION') diff --git a/tests/test_test_phase.py b/tests/test_test_phase.py index 1c3f493f..44e0275d 100755 --- a/tests/test_test_phase.py +++ b/tests/test_test_phase.py @@ -23,10 +23,12 @@ FAILABLE_CONFIG = { ] } -UNBOOTABLE_ISO = ('\0' * 0x8001) + 'CD001' + ('\0' * 100) -ISO_WITH_MBR = ('\0' * 0x1fe) + '\x55\xAA' + ('\0' * 0x7e01) + 'CD001' + ('\0' * 100) -ISO_WITH_GPT = ('\0' * 0x200) + 'EFI PART' + ('\0' * 0x7df9) + 'CD001' + ('\0' * 100) -ISO_WITH_MBR_AND_GPT = ('\0' * 0x1fe) + '\x55\xAAEFI PART' + ('\0' * 0x7df9) + 'CD001' + ('\0' * 100) +PAD = '\0' * 100 +UNBOOTABLE_ISO = ('\0' * 0x8001) + 'CD001' + PAD +ISO_WITH_MBR = ('\0' * 0x1fe) + '\x55\xAA' + ('\0' * 0x7e01) + 'CD001' + PAD +ISO_WITH_GPT = ('\0' * 0x200) + 'EFI PART' + ('\0' * 0x7df9) + 'CD001' + PAD +ISO_WITH_MBR_AND_GPT = ('\0' * 0x1fe) + '\x55\xAAEFI PART' + ('\0' * 0x7df9) + 'CD001' + PAD +ISO_WITH_TORITO = ('\0' * 0x8001) + 'CD001' + ('\0' * 0x7fa) + '\0CD001\1EL TORITO SPECIFICATION' + PAD class TestCheckImageSanity(PungiTestCase): @@ -125,6 +127,17 @@ class TestCheckImageSanity(PungiTestCase): except: self.fail('Bootable image with MBR and GPT must not raise') + def test_bootable_iso_with_el_torito_does_not_raise(self): + compose = DummyCompose(self.topdir, {}) + compose.image.format = 'iso' + compose.image.bootable = True + touch(os.path.join(self.topdir, 'compose', compose.image.path), ISO_WITH_TORITO) + + try: + test_phase.check_image_sanity(compose) + except: + self.fail('Bootable image with El Torito must not raise') + def test_checks_with_optional_variant(self): compose = DummyCompose(self.topdir, {}) compose.variants['Server'].variants = {