Fix checking optional ISO images in test phase

Instead of iterating over image manifest, loop through all variants and
arches and see if there are any images. This avoids a crash for variants
nested under other variants (layered products, optionals or addons).

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-06-06 10:29:40 +02:00
parent b62b468ccf
commit b2a266c3e4
3 changed files with 29 additions and 6 deletions

View File

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

View File

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

View File

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