[image-build] Take install tree from another variant
Add a configuration option to use install tree from another variant. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
195b13d434
commit
7f815d80f5
@ -613,7 +613,10 @@ Image Build Settings
|
|||||||
automatically transformed into format suitable for ``koji``. A repo for the
|
automatically transformed into format suitable for ``koji``. A repo for the
|
||||||
currently built variant will be added as well.
|
currently built variant will be added as well.
|
||||||
|
|
||||||
Please don't set ``install_tree`` as it would get overriden by pungi.
|
Please don't set ``install_tree``. This gets automatically set by *pungi*
|
||||||
|
based on current variant. You can use ``install_tree_from`` key to use
|
||||||
|
install tree from another variant.
|
||||||
|
|
||||||
The ``format`` attr is [('image_type', 'image_suffix'), ...].
|
The ``format`` attr is [('image_type', 'image_suffix'), ...].
|
||||||
See productmd documentation for list of supported types and suffixes.
|
See productmd documentation for list of supported types and suffixes.
|
||||||
|
|
||||||
@ -655,6 +658,9 @@ Example
|
|||||||
|
|
||||||
# only build this type of image on x86_64
|
# only build this type of image on x86_64
|
||||||
'arches': ['x86_64']
|
'arches': ['x86_64']
|
||||||
|
|
||||||
|
# Use install tree from Everything variant.
|
||||||
|
'install_tree_from': 'Everything',
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,23 @@ class ImageBuildPhase(PhaseBase):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _get_install_tree(self, image_conf, variant):
|
||||||
|
"""
|
||||||
|
Get a path to os tree for a variant specified in `install_tree_from` or
|
||||||
|
current variant. If the config is set, it will be removed from the
|
||||||
|
dict.
|
||||||
|
"""
|
||||||
|
install_tree_from = image_conf.pop('install_tree_from', variant.uid)
|
||||||
|
install_tree_source = self.compose.variants.get(install_tree_from)
|
||||||
|
if not install_tree_source:
|
||||||
|
raise RuntimeError(
|
||||||
|
'There is no variant %s to get install tree from when building image for %s.'
|
||||||
|
% (install_tree_from, variant.uid))
|
||||||
|
return translate_path(
|
||||||
|
self.compose,
|
||||||
|
self.compose.paths.compose.os_tree('$arch', install_tree_source)
|
||||||
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
for variant in self.compose.get_variants():
|
for variant in self.compose.get_variants():
|
||||||
arches = set([x for x in variant.arches if x != 'src'])
|
arches = set([x for x in variant.arches if x != 'src'])
|
||||||
@ -54,10 +71,9 @@ class ImageBuildPhase(PhaseBase):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
image_conf["variant"] = variant
|
image_conf["variant"] = variant
|
||||||
image_conf["install_tree"] = translate_path(
|
|
||||||
self.compose,
|
image_conf["install_tree"] = self._get_install_tree(image_conf, variant)
|
||||||
self.compose.paths.compose.os_tree('$arch', variant)
|
|
||||||
)
|
|
||||||
# transform format into right 'format' for image-build
|
# transform format into right 'format' for image-build
|
||||||
# e.g. 'docker,qcow2'
|
# e.g. 'docker,qcow2'
|
||||||
format = image_conf["format"]
|
format = image_conf["format"]
|
||||||
|
@ -49,17 +49,18 @@ class _DummyCompose(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._logger = mock.Mock()
|
self._logger = mock.Mock()
|
||||||
self.variants = [
|
self.variants = {
|
||||||
mock.Mock(uid='Server', arches=['x86_64', 'amd64']),
|
'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64']),
|
||||||
mock.Mock(uid='Client', arches=['amd64']),
|
'Client': mock.Mock(uid='Client', arches=['amd64']),
|
||||||
]
|
'Everything': mock.Mock(uid='Everything', arches=['x86_64', 'amd64']),
|
||||||
|
}
|
||||||
self.im = mock.Mock()
|
self.im = mock.Mock()
|
||||||
|
|
||||||
def get_arches(self):
|
def get_arches(self):
|
||||||
return ['x86_64', 'amd64']
|
return ['x86_64', 'amd64']
|
||||||
|
|
||||||
def get_variants(self, arch=None, types=None):
|
def get_variants(self, arch=None, types=None):
|
||||||
return [v for v in self.variants if not arch or arch in v.arches]
|
return [v for v in self.variants.values() if not arch or arch in v.arches]
|
||||||
|
|
||||||
|
|
||||||
class TestImageBuildPhase(unittest.TestCase):
|
class TestImageBuildPhase(unittest.TestCase):
|
||||||
@ -97,7 +98,7 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
'kickstart': 'fedora-docker-base.ks',
|
'kickstart': 'fedora-docker-base.ks',
|
||||||
'format': 'docker',
|
'format': 'docker',
|
||||||
'repo': '/ostree/$arch/Client',
|
'repo': '/ostree/$arch/Client',
|
||||||
'variant': compose.variants[1],
|
'variant': compose.variants['Client'],
|
||||||
'target': 'f24',
|
'target': 'f24',
|
||||||
'disk_size': 3,
|
'disk_size': 3,
|
||||||
'name': 'Fedora-Docker-Base',
|
'name': 'Fedora-Docker-Base',
|
||||||
@ -118,7 +119,7 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
'kickstart': 'fedora-docker-base.ks',
|
'kickstart': 'fedora-docker-base.ks',
|
||||||
'format': 'docker',
|
'format': 'docker',
|
||||||
'repo': '/ostree/$arch/Server',
|
'repo': '/ostree/$arch/Server',
|
||||||
'variant': compose.variants[0],
|
'variant': compose.variants['Server'],
|
||||||
'target': 'f24',
|
'target': 'f24',
|
||||||
'disk_size': 3,
|
'disk_size': 3,
|
||||||
'name': 'Fedora-Docker-Base',
|
'name': 'Fedora-Docker-Base',
|
||||||
@ -165,6 +166,61 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
self.assertFalse(phase.pool.add.called)
|
self.assertFalse(phase.pool.add.called)
|
||||||
self.assertFalse(phase.pool.queue_put.called)
|
self.assertFalse(phase.pool.queue_put.called)
|
||||||
|
|
||||||
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
||||||
|
def test_image_build_set_install_tree(self, ThreadPool):
|
||||||
|
compose = _DummyCompose({
|
||||||
|
'image_build': {
|
||||||
|
'^Server$': [
|
||||||
|
{
|
||||||
|
'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,
|
||||||
|
'arches': ['x86_64'],
|
||||||
|
'install_tree_from': 'Everything',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'koji_profile': 'koji',
|
||||||
|
})
|
||||||
|
|
||||||
|
phase = ImageBuildPhase(compose)
|
||||||
|
|
||||||
|
phase.run()
|
||||||
|
|
||||||
|
# assert at least one thread was started
|
||||||
|
self.assertTrue(phase.pool.add.called)
|
||||||
|
|
||||||
|
self.assertTrue(phase.pool.queue_put.called_once)
|
||||||
|
args, kwargs = phase.pool.queue_put.call_args
|
||||||
|
self.assertEqual(args[0][0], compose)
|
||||||
|
self.maxDiff = None
|
||||||
|
self.assertDictEqual(args[0][1], {
|
||||||
|
"format": [('docker', 'tar.xz')],
|
||||||
|
"image_conf": {
|
||||||
|
'install_tree': '/ostree/$arch/Everything',
|
||||||
|
'kickstart': 'fedora-docker-base.ks',
|
||||||
|
'format': 'docker',
|
||||||
|
'repo': '/ostree/$arch/Server',
|
||||||
|
'variant': compose.variants['Server'],
|
||||||
|
'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": 'Server-Fedora-Docker-Base-docker',
|
||||||
|
"image_dir": '/image_dir/Server/%(arch)s',
|
||||||
|
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
||||||
|
"link_type": 'hardlink-or-copy',
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class TestCreateImageBuildThread(unittest.TestCase):
|
class TestCreateImageBuildThread(unittest.TestCase):
|
||||||
|
|
||||||
@ -182,7 +238,7 @@ class TestCreateImageBuildThread(unittest.TestCase):
|
|||||||
'kickstart': 'fedora-docker-base.ks',
|
'kickstart': 'fedora-docker-base.ks',
|
||||||
'format': 'docker',
|
'format': 'docker',
|
||||||
'repo': '/ostree/$arch/Client',
|
'repo': '/ostree/$arch/Client',
|
||||||
'variant': compose.variants[1],
|
'variant': compose.variants['Client'],
|
||||||
'target': 'f24',
|
'target': 'f24',
|
||||||
'disk_size': 3,
|
'disk_size': 3,
|
||||||
'name': 'Fedora-Docker-Base',
|
'name': 'Fedora-Docker-Base',
|
||||||
|
Loading…
Reference in New Issue
Block a user