Be explicit about generating release for images

The config now uses similar logic what previous commit did for OSTree.
Also we should report error when an unknown generator is used.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-04-07 15:33:43 +02:00
parent 0f4b6b1947
commit f6d07c1651
8 changed files with 148 additions and 45 deletions

View file

@ -112,7 +112,7 @@ class TestImageBuildPhase(PungiTestCase):
def test_image_build_phase_global_options(self, ThreadPool):
compose = DummyCompose(self.topdir, {
'image_build_ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
'image_build_release': None,
'image_build_release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN',
'image_build_target': 'f24',
'image_build_version': 'Rawhide',
'image_build': {
@ -171,7 +171,7 @@ class TestImageBuildPhase(PungiTestCase):
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_release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN',
'image_build_target': 'f24',
'image_build': {
'^Server$': [
@ -481,6 +481,44 @@ class TestImageBuildPhase(PungiTestCase):
self.assertEqual(args[0][1].get('image_conf', {}).get('image-build', {}).get('release'),
'20151203.t.0')
@mock.patch('pungi.phases.image_build.ThreadPool')
def test_image_build_create_release_with_explicit_config(self, ThreadPool):
compose = DummyCompose(self.topdir, {
'image_build': {
'^Server$': [
{
'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,
'arches': ['x86_64'],
'release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN',
}
}
]
},
'koji_profile': 'koji',
})
self.assertValidConfig(compose.conf)
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][1].get('image_conf', {}).get('image-build', {}).get('release'),
'20151203.t.0')
@mock.patch('pungi.phases.image_build.ThreadPool')
def test_image_build_scratch_build(self, ThreadPool):
compose = DummyCompose(self.topdir, {

View file

@ -355,6 +355,67 @@ class OstreeThreadTest(helpers.PungiTestCase):
self.assertImageAdded(self.compose, ImageCls, iso)
self.assertAllCopied(run)
@mock.patch('kobo.shortcuts.run')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@mock.patch('pungi.phases.ostree_installer.iso')
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run_with_explicitly_generated_release(self, KojiWrapper, link, iso,
get_file_size, get_mtime, ImageCls, run):
pool = mock.Mock()
cfg = {
'repo': 'Everything',
'release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN',
"installpkgs": ["fedora-productimg-atomic"],
"add_template": ["/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl"],
"add_template_var": [
"ostree_osname=fedora-atomic",
"ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host",
],
"add_arch_template": ["/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl"],
"add_arch_template_var": [
"ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/",
"ostree_osname=fedora-atomic",
"ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host",
],
}
self.compose.conf['runroot_weights'] = {'ostree_installer': 123}
koji = KojiWrapper.return_value
koji.run_runroot_cmd.return_value = {
'task_id': 1234,
'retcode': 0,
'output': 'Foo bar\n',
}
get_file_size.return_value = 1024
get_mtime.return_value = 13579
final_iso_path = self.topdir + '/compose/Everything/x86_64/iso/image-name'
t = ostree.OstreeInstallerThread(pool)
t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)
self.assertRunrootCall(
koji,
'file://%s/compose/Everything/x86_64/os' % self.topdir,
'20151203.t.0',
isfinal=True,
extra=['--installpkgs=fedora-productimg-atomic',
'--add-template=/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl',
'--add-arch-template=/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl',
'--add-template-var=ostree_osname=fedora-atomic',
'--add-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host',
'--add-arch-template-var=ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/',
'--add-arch-template-var=ostree_osname=fedora-atomic',
'--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host',
'--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)],
weight=123,
)
self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)
self.assertImageAdded(self.compose, ImageCls, iso)
self.assertAllCopied(run)
@mock.patch('kobo.shortcuts.run')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')

View file

@ -642,5 +642,23 @@ class GetRepoFuncsTestCase(unittest.TestCase):
self.assertEqual(repos, expect)
class TestVersionGenerator(unittest.TestCase):
def test_unknown_generator(self):
compose = mock.Mock()
with self.assertRaises(RuntimeError) as ctx:
util.version_generator(compose, '!GIMME_VERSION')
self.assertEqual(str(ctx.exception),
"Unknown version generator '!GIMME_VERSION'")
def test_passthrough_value(self):
compose = mock.Mock()
self.assertEqual(util.version_generator(compose, '1.2.3'), '1.2.3')
def test_passthrough_none(self):
compose = mock.Mock()
self.assertEqual(util.version_generator(compose, None), None)
if __name__ == "__main__":
unittest.main()