diff --git a/pungi/phases/test.py b/pungi/phases/test.py index 4f9a52e4..c7594194 100644 --- a/pungi/phases/test.py +++ b/pungi/phases/test.py @@ -110,11 +110,14 @@ def check_image_sanity(compose): manifest and logged. Otherwise the compose will be aborted. """ im = compose.im - for variant_uid in im.images: - variant = compose.variants[variant_uid] - for arch in im.images[variant_uid]: - images = im.images[variant_uid][arch] - im.images[variant_uid][arch] = [img for img in images + for variant in compose.get_variants(): + if variant.uid not in im.images: + continue + for arch in variant.arches: + if arch not in im.images[variant.uid]: + continue + images = im.images[variant.uid][arch] + im.images[variant.uid][arch] = [img for img in images if check(compose, variant, arch, img)] diff --git a/tests/helpers.py b/tests/helpers.py index 9a6b04bd..9158a349 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -63,7 +63,7 @@ class DummyCompose(object): self.log_warning = mock.Mock() self.get_image_name = mock.Mock(return_value='image-name') self.image = mock.Mock(path='Client/i386/iso/image.iso') - self.im = mock.Mock(images={'Client': {'i386': [self.image]}}) + self.im = mock.Mock(images={'Client': {'amd64': [self.image]}}) self.old_composes = [] self.config_dir = '/home/releng/config' self.notifier = None diff --git a/tests/test_test_phase.py b/tests/test_test_phase.py index ef8e40fc..1c3f493f 100755 --- a/tests/test_test_phase.py +++ b/tests/test_test_phase.py @@ -7,6 +7,7 @@ try: except ImportError: import unittest +import mock import os import sys @@ -124,6 +125,25 @@ class TestCheckImageSanity(PungiTestCase): except: self.fail('Bootable image with MBR and GPT must not raise') + def test_checks_with_optional_variant(self): + compose = DummyCompose(self.topdir, {}) + compose.variants['Server'].variants = { + 'optional': mock.Mock(uid='Server-optional', arches=['x86_64'], + type='optional', is_empty=False) + } + compose.image.format = 'iso' + compose.image.bootable = True + touch(os.path.join(self.topdir, 'compose', compose.image.path), ISO_WITH_MBR_AND_GPT) + + image = mock.Mock(path="Server/i386/optional/iso/image.iso", + format='iso', bootable=False) + compose.im.images['Server-optional'] = {'i386': [image]} + + try: + test_phase.check_image_sanity(compose) + except: + self.fail('Checking optional variant must not raise') + if __name__ == "__main__": unittest.main()