From 44d7b31a806c8d35f25837c0827fce360201d1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 8 Mar 2016 12:59:40 +0100 Subject: [PATCH] [live-images] Add customizing disc type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relates: #105 Signed-off-by: Lubomír Sedlář --- doc/configuration.rst | 4 +++ pungi/phases/live_images.py | 6 ++-- tests/test_liveimagesphase.py | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 7151128e..4c684764 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -244,6 +244,9 @@ There a couple common format specifiers available for both the options: Available keys are: * ``boot`` -- for ``boot.iso`` images created in *buildinstall* phase + * ``live`` -- for images created by *live_images* phase + + Default values are the same as the keys. Example ------- @@ -267,6 +270,7 @@ Example disc_types = { 'boot': 'netinst', + 'live': 'Live', } diff --git a/pungi/phases/live_images.py b/pungi/phases/live_images.py index 1ae4c381..99ed5c98 100644 --- a/pungi/phases/live_images.py +++ b/pungi/phases/live_images.py @@ -178,6 +178,8 @@ class LiveImagesPhase(PhaseBase): if self.compose.conf.get('live_images_no_rename', False): return None + disc_type = self.compose.conf.get('disc_types', {}).get('live', 'live') + format = "%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s" # Custom name (prefix) if name: @@ -186,8 +188,8 @@ class LiveImagesPhase(PhaseBase): custom_iso_name += "-%s" % version format = custom_iso_name + "-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s" - # XXX: hardcoded disc_type and disc_num - return self.compose.get_image_name(arch, variant, disc_type="live", + # XXX: hardcoded disc_num + return self.compose.get_image_name(arch, variant, disc_type=disc_type, disc_num=None, format=format) def stop(self, *args, **kwargs): diff --git a/tests/test_liveimagesphase.py b/tests/test_liveimagesphase.py index aea61770..fae97ba6 100755 --- a/tests/test_liveimagesphase.py +++ b/tests/test_liveimagesphase.py @@ -58,6 +58,10 @@ class TestLiveImagesPhase(PungiTestCase): 'ksurl': None}, compose.variants['Client'], 'amd64'))]) + self.assertItemsEqual( + compose.get_image_name.mock_calls, + [mock.call('amd64', compose.variants['Client'], disc_num=None, disc_type='live', + format='%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s')]) @mock.patch('pungi.phases.live_images.ThreadPool') def test_live_image_build_single_repo_from(self, ThreadPool): @@ -260,6 +264,54 @@ class TestLiveImagesPhase(PungiTestCase): self.assertEqual(resolve_git_url.mock_calls, [mock.call('https://git.example.com/kickstarts.git?#HEAD')]) + @mock.patch('pungi.phases.live_images.ThreadPool') + def test_live_image_build_custom_type(self, ThreadPool): + compose = DummyCompose(self.topdir, { + 'disc_types': {'live': 'Live'}, + 'live_images': [ + ('^Client$', { + 'amd64': { + 'kickstart': 'test.ks', + 'additional_repos': ['http://example.com/repo/'], + 'repo_from': ['Everything'], + 'release': None, + } + }) + ], + }) + + 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', + 'dest_dir': self.topdir + '/compose/Client/amd64/iso', + 'scratch': False, + 'repos': [self.topdir + '/compose/Client/amd64/os', + 'http://example.com/repo/', + self.topdir + '/compose/Everything/amd64/os'], + 'label': '', + 'name': None, + 'filename': 'image-name', + 'version': None, + 'specfile': None, + 'sign': False, + 'type': 'live', + 'release': '20151203.0', + 'ksurl': None}, + compose.variants['Client'], + 'amd64'))]) + self.assertItemsEqual( + compose.get_image_name.mock_calls, + [mock.call('amd64', compose.variants['Client'], disc_num=None, disc_type='Live', + format='%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s')]) + class TestCreateLiveImageThread(PungiTestCase):