Merge #381 `Automatically generate missing image version`

This commit is contained in:
Dennis Gilmore 2016-09-06 15:19:55 +00:00
commit 6aeab9ee9d
11 changed files with 141 additions and 16 deletions

View File

@ -810,14 +810,17 @@ Target is specified by these settings. For live images refer to ``live_target``.
* ``live_media_target``
* ``image_build_target``
Version is specified by these options.
.. _auto_version:
Version is specified by these options. If no version is set, a default value
will be provided based on product version. If label is used (and is not
``RC``), the milestone will be appended to the version with an underscore.
* ``global_version`` -- global fallback setting
* ``live_media_version``
* ``image_build_version``
* ``live_images_version``
.. _auto_release:
Release is specified by these options. If set explicitly to ``None``, a value

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

@ -102,6 +102,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

@ -106,7 +106,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

@ -92,7 +92,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

@ -87,7 +87,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))

View File

@ -37,6 +37,7 @@ class DummyCompose(object):
self.compose_label = None
self.compose_label_major_version = None
self.image_release = '20151203.t.0'
self.image_version = '25'
self.ci_base = mock.Mock(
release_id='Test-1.0',
release=mock.Mock(

View File

@ -127,12 +127,12 @@ class ComposeTestCase(unittest.TestCase):
ci.return_value.compose.respin = 2
ci.return_value.compose.date = '20160107'
ci.return_value.compose.type = 'production'
ci.return_value.compose.type_suffix = '.n'
ci.return_value.compose.type_suffix = ''
ci.return_value.compose.label = None
compose = Compose(conf, self.tmp_dir)
self.assertEqual(compose.image_release, '20160107.n.2')
self.assertEqual(compose.image_release, '20160107.2')
@mock.patch('pungi.compose.ComposeInfo')
def test_image_release_from_label(self, ci):
@ -147,6 +147,48 @@ class ComposeTestCase(unittest.TestCase):
self.assertEqual(compose.image_release, '1.2')
@mock.patch('pungi.compose.ComposeInfo')
def test_image_version_without_label(self, ci):
conf = {}
ci.return_value.compose.respin = 2
ci.return_value.compose.date = '20160107'
ci.return_value.compose.type = 'nightly'
ci.return_value.compose.type_suffix = '.n'
ci.return_value.compose.label = None
ci.return_value.release.version = '25'
compose = Compose(conf, self.tmp_dir)
self.assertEqual(compose.image_version, '25')
@mock.patch('pungi.compose.ComposeInfo')
def test_image_version_with_label(self, ci):
conf = {}
ci.return_value.compose.respin = 2
ci.return_value.compose.date = '20160107'
ci.return_value.compose.type = 'nightly'
ci.return_value.compose.type_suffix = '.n'
ci.return_value.compose.label = 'Alpha-1.2'
ci.return_value.release.version = '25'
compose = Compose(conf, self.tmp_dir)
self.assertEqual(compose.image_version, '25_Alpha')
@mock.patch('pungi.compose.ComposeInfo')
def test_image_version_with_label_rc(self, ci):
conf = {}
ci.return_value.compose.respin = 2
ci.return_value.compose.date = '20160107'
ci.return_value.compose.type = 'nightly'
ci.return_value.compose.type_suffix = '.n'
ci.return_value.compose.label = 'RC-1.2'
ci.return_value.release.version = '25'
compose = Compose(conf, self.tmp_dir)
self.assertEqual(compose.image_version, '25')
@mock.patch('pungi.compose.ComposeInfo')
def test_get_variant_arches_without_filter(self, ci):
conf = ConfigWrapper(

View File

@ -169,6 +169,65 @@ class TestImageBuildPhase(PungiTestCase):
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
[mock.call((compose, server_args))])
@mock.patch('pungi.phases.image_build.ThreadPool')
def test_image_build_phase_missing_version(self, ThreadPool):
compose = DummyCompose(self.topdir, {
'image_build_ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
'image_build_release': None,
'image_build_target': 'f24',
'image_build': {
'^Server$': [
{
'image-build': {
'format': [('docker', 'tar.xz')],
'name': 'Fedora-Docker-Base',
'kickstart': "fedora-docker-base.ks",
'distro': 'Fedora-20',
'disk_size': 3
}
}
]
},
'koji_profile': 'koji',
})
phase = ImageBuildPhase(compose)
phase.run()
self.maxDiff = None
# 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/$arch/os',
'variant': compose.variants['Server'],
'target': 'f24',
'disk_size': 3,
'name': 'Fedora-Docker-Base',
'arches': 'amd64,x86_64',
'version': '25',
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
'distro': 'Fedora-20',
'release': '20151203.t.0',
}
},
"conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg',
"image_dir": self.topdir + '/compose/Server/%(arch)s/images',
"relative_image_dir": 'Server/%(arch)s/images',
"link_type": 'hardlink-or-copy',
"scratch": False,
"failable_arches": [],
}
self.maxDiff = None
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
[mock.call((compose, server_args))])
@mock.patch('pungi.phases.image_build.ThreadPool')
def test_image_build_filter_all_variants(self, ThreadPool):
compose = DummyCompose(self.topdir, {

View File

@ -53,7 +53,7 @@ class TestLiveImagesPhase(PungiTestCase):
'label': '',
'name': None,
'filename': 'image-name',
'version': None,
'version': '25',
'specfile': None,
'sign': False,
'type': 'live',
@ -104,7 +104,7 @@ class TestLiveImagesPhase(PungiTestCase):
'label': '',
'name': None,
'filename': 'image-name',
'version': None,
'version': '25',
'specfile': None,
'sign': False,
'type': 'live',
@ -152,7 +152,7 @@ class TestLiveImagesPhase(PungiTestCase):
'label': '',
'name': None,
'filename': None,
'version': None,
'version': '25',
'specfile': None,
'sign': False,
'type': 'live',
@ -202,7 +202,7 @@ class TestLiveImagesPhase(PungiTestCase):
'label': '',
'name': None,
'filename': 'image-name',
'version': None,
'version': '25',
'specfile': None,
'sign': False,
'type': 'live',
@ -223,7 +223,7 @@ class TestLiveImagesPhase(PungiTestCase):
'label': '',
'name': None,
'filename': 'image-name',
'version': None,
'version': '25',
'specfile': None,
'sign': False,
'type': 'live',
@ -274,7 +274,7 @@ class TestLiveImagesPhase(PungiTestCase):
'label': '',
'name': None,
'filename': 'image-name',
'version': None,
'version': '25',
'specfile': None,
'sign': False,
'type': 'appliance',
@ -434,7 +434,7 @@ class TestLiveImagesPhase(PungiTestCase):
'label': '',
'name': None,
'filename': 'image-name',
'version': None,
'version': '25',
'specfile': None,
'sign': False,
'type': 'live',

View File

@ -331,7 +331,6 @@ class TestLiveMediaPhase(PungiTestCase):
'arches': ['x86_64'],
'ksversion': '24',
'release': None,
'version': 'Rawhide',
'install_tree_from': 'Everything',
'subvariant': 'Something',
'failable': ['*'],
@ -366,7 +365,7 @@ class TestLiveMediaPhase(PungiTestCase):
'target': 'f24',
'title': 'Custom Title',
'install_tree': self.topdir + '/compose/Everything/$basearch/os',
'version': 'Rawhide',
'version': '25',
'subvariant': 'Something',
'failable_arches': ['*'],
}))])