diff --git a/pungi/paths.py b/pungi/paths.py index ce5a777a..1183b93c 100644 --- a/pungi/paths.py +++ b/pungi/paths.py @@ -530,10 +530,6 @@ class ComposePaths(object): @param symlink_to=None @param relative=False """ - # skip optional and addons - if variant.type != "variant": - return None - path = os.path.join(self.topdir('%(arch)s', variant, create_dir=False, relative=relative), "images") if symlink_to: diff --git a/pungi/phases/image_build.py b/pungi/phases/image_build.py index 07605e57..b1d0f878 100644 --- a/pungi/phases/image_build.py +++ b/pungi/phases/image_build.py @@ -28,6 +28,11 @@ class ImageBuildPhase(base.PhaseLoggerMixin, base.ImageConfigMixin, base.ConfigG current variant. If the config is set, it will be removed from the dict. """ + if variant.type != 'variant': + # Buildinstall only runs for top-level variants. Nested variants + # need to re-use install tree from parent. + variant = variant.parent + install_tree_from = image_conf.pop('install_tree_from', variant.uid) if '://' in install_tree_from: return install_tree_from diff --git a/tests/helpers.py b/tests/helpers.py index 53e3898d..ed78c9d0 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -89,8 +89,8 @@ class DummyCompose(object): def setup_optional(self): self.all_variants['Server-optional'] = MockVariant( - uid='Server-optional', arches=['x86_64'], type='optional', is_empty=False, - parent=self.variants['Server']) + uid='Server-optional', arches=['x86_64'], type='optional', is_empty=False) + self.all_variants['Server-optional'].parent = self.variants['Server'] self.variants['Server'].variants = {'optional': self.all_variants['Server-optional']} def get_variants(self, arch=None, types=None): diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index 609dcb38..5f753cfd 100644 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -564,6 +564,66 @@ class TestImageBuildPhase(PungiTestCase): self.assertEqual(args[0][1]['image_conf'].get('image-build', {}).get('ksurl'), resolve_git_url.return_value) + @mock.patch('pungi.phases.image_build.ThreadPool') + def test_image_build_optional(self, ThreadPool): + compose = DummyCompose(self.topdir, { + 'image_build': { + '^Server-optional$': [ + { + 'image-build': { + 'format': [('docker', 'tar.xz')], + 'name': 'Fedora-Docker-Base', + 'target': 'f24', + 'version': 'Rawhide', + 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', + 'kickstart': "fedora-docker-base.ks", + 'distro': 'Fedora-20', + 'disk_size': 3, + 'failable': ['x86_64'], + } + } + ] + }, + 'koji_profile': 'koji', + }) + compose.setup_optional() + + self.assertValidConfig(compose.conf) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + server_args = { + "format": [('docker', 'tar.xz')], + "image_conf": { + 'image-build': { + 'install_tree': self.topdir + '/compose/Server/$arch/os', + 'kickstart': 'fedora-docker-base.ks', + 'format': 'docker', + 'repo': self.topdir + '/compose/Server-optional/$arch/os', + 'variant': compose.all_variants['Server-optional'], + 'target': 'f24', + 'disk_size': 3, + 'name': 'Fedora-Docker-Base', + 'arches': 'x86_64', + 'version': 'Rawhide', + 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', + 'distro': 'Fedora-20', + } + }, + "conf_file": self.topdir + '/work/image-build/Server-optional/docker_Fedora-Docker-Base.cfg', + "image_dir": self.topdir + '/compose/Server-optional/%(arch)s/images', + "relative_image_dir": 'Server-optional/%(arch)s/images', + "link_type": 'hardlink-or-copy', + "scratch": False, + "failable_arches": ['x86_64'], + } + self.assertItemsEqual(phase.pool.queue_put.mock_calls, + [mock.call((compose, server_args))]) + class TestCreateImageBuildThread(PungiTestCase):