Automatically generate missing image version

If the configuration does not specify version for images or live media,
Pungi will create a default value based on `release_version`. If label
is used for the compose, the milestone from it will be appended to the
version (unless it's RC).

This change is backwards compatible: nothing changes when version is set
in configuration. If the version was missing before, building the
artifacts would fail. With this patch, default values will be supplied.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-08-30 09:51:36 +02:00
parent 5534fda192
commit 223a015898
11 changed files with 141 additions and 16 deletions

View file

@ -355,3 +355,17 @@ class Compose(kobo.log.LoggingBase):
return '%s%s.%s' % (self.compose_date, self.ci_base.compose.type_suffix,
self.compose_respin)
@property
def image_version(self):
"""Generate a value to pass to Koji as image version.
The value is based on release version. If compose has a label, the
milestone from it is appended to the version (unless it is RC).
"""
version = self.ci_base.release.version
if self.compose_label and not self.compose_label.startswith('RC-'):
milestone, release = self.compose_label.split('-')
return '%s_%s' % (version, milestone)
return version

View file

@ -106,6 +106,13 @@ class ImageConfigMixin(object):
'%s_%s' % (self.name, opt), self.compose.conf.get(
'global_%s' % opt)))
def get_version(self, cfg):
"""
Get version from configuration hierarchy or fall back to release
version.
"""
return self.get_config(cfg, 'version') or self.compose.image_version
def get_release(self, cfg):
"""
If release is set explicitly to None, replace it with date and respin.

View file

@ -134,7 +134,7 @@ class ImageBuildPhase(base.ImageConfigMixin, base.ConfigGuardedPhase):
if release:
image_conf['image-build']['release'] = release
image_conf['image-build']['version'] = self.get_config(image_conf['image-build'], 'version')
image_conf['image-build']['version'] = self.get_version(image_conf['image-build'])
image_conf['image-build']['target'] = self.get_config(image_conf['image-build'], 'target')
# transform format into right 'format' for image-build

View file

@ -140,7 +140,7 @@ class LiveImagesPhase(base.ImageConfigMixin, base.ConfigGuardedPhase):
cmd = {
"name": data.get('name'),
"version": self.get_config(data, 'version'),
"version": self.get_version(data),
"release": self.get_release(data),
"dest_dir": dest_dir,
"build_arch": arch,

View file

@ -115,7 +115,7 @@ class LiveMediaPhase(ImageConfigMixin, ConfigGuardedPhase):
'title': image_conf.get('title'),
'repo': self._get_repos(image_conf, variant),
'install_tree': self._get_install_tree(image_conf, variant),
'version': self.get_config(image_conf, 'version'),
'version': self.get_version(image_conf),
'failable_arches': image_conf.get('failable', []),
}
self.pool.add(LiveMediaThread(self.pool))