[live-images] Build all images specified in config

Not just the first one.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-02-22 08:21:51 +01:00
parent 8ed44dd153
commit 32a966fc91
2 changed files with 119 additions and 60 deletions

View File

@ -98,78 +98,74 @@ class LiveImagesPhase(PhaseBase):
for variant in self.compose.variants.values(): for variant in self.compose.variants.values():
for arch in variant.arches + ["src"]: for arch in variant.arches + ["src"]:
data = get_arch_variant_data(self.compose.conf, "live_images", arch, variant) for data in get_arch_variant_data(self.compose.conf, "live_images", arch, variant):
if not data: iso_dir = self.compose.paths.compose.iso_dir(arch, variant, symlink_to=symlink_isos_to)
continue if not iso_dir:
data = data[0] continue
iso_dir = self.compose.paths.compose.iso_dir(arch, variant, symlink_to=symlink_isos_to) cmd = {
if not iso_dir: "name": None,
continue "version": None,
"iso_path": None,
"wrapped_rpms_path": iso_dir,
"build_arch": arch,
"ks_file": data['kickstart'],
"ksurl": None,
"specfile": None,
"scratch": False,
"sign": False,
"label": "", # currently not used
}
cmd = { if 'ksurl' in data:
"name": None, cmd['ksurl'] = resolve_git_url(data['ksurl'])
"version": None,
"iso_path": None,
"wrapped_rpms_path": iso_dir,
"build_arch": arch,
"ks_file": data['kickstart'],
"ksurl": None,
"specfile": None,
"scratch": False,
"sign": False,
"label": "", # currently not used
}
if 'ksurl' in data: cmd["repos"] = []
cmd['ksurl'] = resolve_git_url(data['ksurl']) if not variant.is_empty:
cmd["repos"].append(translate_path(
self.compose, self.compose.paths.compose.repository(arch, variant, create_dir=False)))
cmd["repos"] = [] # additional repos
if not variant.is_empty: cmd["repos"].extend(data.get("additional_repos", []))
cmd["repos"].append(translate_path( cmd['repos'].extend(self._get_extra_repos(arch, variant, data.get('repos_from', [])))
self.compose, self.compose.paths.compose.repository(arch, variant, create_dir=False)))
# additional repos # Explicit name and version
cmd["repos"].extend(data.get("additional_repos", [])) cmd["name"] = data.get("name", None)
cmd['repos'].extend(self._get_extra_repos(arch, variant, data.get('repos_from', []))) cmd["version"] = data.get("version", None)
# Explicit name and version cmd['type'] = data.get('type', 'live')
cmd["name"] = data.get("name", None)
cmd["version"] = data.get("version", None)
cmd['type'] = data.get('type', 'live') # Specfile (for images wrapped in rpm)
cmd["specfile"] = data.get("specfile", None)
# Specfile (for images wrapped in rpm) # Scratch (only taken in consideration if specfile specified)
cmd["specfile"] = data.get("specfile", None) # For images wrapped in rpm is scratch disabled by default
# For other images is scratch always on
cmd["scratch"] = data.get("scratch", False)
# Scratch (only taken in consideration if specfile specified) # Signing of the rpm wrapped image
# For images wrapped in rpm is scratch disabled by default if not cmd["scratch"] and data.get("sign"):
# For other images is scratch always on cmd["sign"] = True
cmd["scratch"] = data.get("scratch", False)
# Signing of the rpm wrapped image format = "%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s"
if not cmd["scratch"] and data.get("sign"): # Custom name (prefix)
cmd["sign"] = True if cmd["name"]:
custom_iso_name = cmd["name"]
if cmd["version"]:
custom_iso_name += "-%s" % cmd["version"]
format = custom_iso_name + "-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s"
format = "%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s" # XXX: hardcoded disc_type and disc_num
# Custom name (prefix) filename = self.compose.get_image_name(arch, variant, disc_type="live",
if cmd["name"]: disc_num=None, format=format)
custom_iso_name = cmd["name"] iso_path = self.compose.paths.compose.iso_path(arch, variant, filename,
if cmd["version"]: symlink_to=symlink_isos_to)
custom_iso_name += "-%s" % cmd["version"] if os.path.isfile(iso_path):
format = custom_iso_name + "-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s" self.compose.log_warning("Skipping creating live image, it already exists: %s" % iso_path)
continue
cmd["iso_path"] = iso_path
# XXX: hardcoded disc_type and disc_num commands.append((cmd, variant, arch))
filename = self.compose.get_image_name(arch, variant, disc_type="live",
disc_num=None, format=format)
iso_path = self.compose.paths.compose.iso_path(arch, variant, filename,
symlink_to=symlink_isos_to)
if os.path.isfile(iso_path):
self.compose.log_warning("Skipping creating live image, it already exists: %s" % iso_path)
continue
cmd["iso_path"] = iso_path
commands.append((cmd, variant, arch))
for (cmd, variant, arch) in commands: for (cmd, variant, arch) in commands:
self.pool.add(CreateLiveImageThread(self.pool)) self.pool.add(CreateLiveImageThread(self.pool))

View File

@ -101,6 +101,69 @@ class TestLiveImagesPhase(unittest.TestCase):
compose.variants['Client'], compose.variants['Client'],
'amd64'))]) 'amd64'))])
@mock.patch('pungi.phases.live_images.ThreadPool')
def test_live_image_build_two_images(self, ThreadPool):
compose = _DummyCompose({
'live_images': [
('^Client$', {
'amd64': [{
'kickstart': 'test.ks',
'additional_repos': ['http://example.com/repo/'],
'repos_from': ['Everything'],
}, {
'kickstart': 'another.ks',
'additional_repos': ['http://example.com/repo/'],
'repos_from': ['Everything'],
}]
})
],
})
phase = LiveImagesPhase(compose)
phase.run()
# assert at least one thread was started
self.assertTrue(phase.pool.add.called)
self.maxDiff = None
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
[mock.call((compose,
{'ks_file': 'test.ks',
'build_arch': 'amd64',
'wrapped_rpms_path': '/iso_dir/amd64/Client',
'scratch': False,
'repos': ['/repo/amd64/Client',
'http://example.com/repo/',
'/repo/amd64/Everything'],
'label': '',
'name': None,
'iso_path': '/iso_dir/amd64/Client/image-name',
'version': None,
'specfile': None,
'sign': False,
'type': 'live',
'ksurl': None},
compose.variants['Client'],
'amd64')),
mock.call((compose,
{'ks_file': 'another.ks',
'build_arch': 'amd64',
'wrapped_rpms_path': '/iso_dir/amd64/Client',
'scratch': False,
'repos': ['/repo/amd64/Client',
'http://example.com/repo/',
'/repo/amd64/Everything'],
'label': '',
'name': None,
'iso_path': '/iso_dir/amd64/Client/image-name',
'version': None,
'specfile': None,
'sign': False,
'type': 'live',
'ksurl': None},
compose.variants['Client'],
'amd64'))])
@mock.patch('pungi.phases.live_images.ThreadPool') @mock.patch('pungi.phases.live_images.ThreadPool')
@mock.patch('pungi.phases.live_images.resolve_git_url') @mock.patch('pungi.phases.live_images.resolve_git_url')
def test_spin_appliance(self, resolve_git_url, ThreadPool): def test_spin_appliance(self, resolve_git_url, ThreadPool):