From 0c9ad96a31276d0f0b7a01fde184096d3e233839 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:36:28 +0100 Subject: [PATCH] [buildinstall] Add customizing disc type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds configuration option to change disc type used in file name. So far this can only be changed for link to images/boot.iso. Resolves: #109 Signed-off-by: Lubomír Sedlář --- doc/configuration.rst | 12 ++++++++- pungi/phases/buildinstall.py | 4 ++- tests/test_buildinstall.py | 49 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 00e92473..7151128e 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -233,12 +233,18 @@ There a couple common format specifiers available for both the options: * base_product_version **image_volid_layered_product_formats** [optional] - (*list*) -- A listof format strings for generating volume id for layered + (*list*) -- A list of format strings for generating volume id for layered products. The keys available are the same as for ``image_volid_formats``. **volume_id_substitutions** [optional] (*dict*) -- A mapping of string replacements to shorten the volume id. +**disc_types** [optional] + (*dict*) -- A mapping for customizing ``disc_type`` used in image names. + + Available keys are: + * ``boot`` -- for ``boot.iso`` images created in *buildinstall* phase + Example ------- :: @@ -259,6 +265,10 @@ Example 'TC': 'T', } + disc_types = { + 'boot': 'netinst', + } + Signing ======= diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index 619f83c7..5cf40217 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -316,6 +316,8 @@ def link_boot_iso(compose, arch, variant): if arch == "src": return + disc_type = compose.conf.get('disc_types', {}).get('boot', 'boot') + symlink_isos_to = compose.conf.get("symlink_isos_to", None) os_tree = compose.paths.compose.os_tree(arch, variant) # TODO: find in treeinfo? @@ -324,7 +326,7 @@ def link_boot_iso(compose, arch, variant): return msg = "Linking boot.iso (arch: %s, variant: %s)" % (arch, variant) - filename = compose.get_image_name(arch, variant, disc_type="boot", + filename = compose.get_image_name(arch, variant, disc_type=disc_type, disc_num=None, suffix=".iso") new_boot_iso_path = compose.paths.compose.iso_path(arch, variant, filename, symlink_to=symlink_isos_to) diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index 775f22ef..74e31790 100755 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -611,6 +611,55 @@ class TestSymlinkIso(PungiTestCase): self.assertEqual(self.compose.im.add.mock_calls, [mock.call('Server', 'x86_64', image)]) + @mock.patch('pungi.phases.buildinstall.Image') + @mock.patch('pungi.phases.buildinstall.get_mtime') + @mock.patch('pungi.phases.buildinstall.get_file_size') + @mock.patch('pungi.phases.buildinstall.IsoWrapper') + @mock.patch('pungi.phases.buildinstall.run') + def test_hardlink_with_custom_type(self, run, IsoWrapperCls, get_file_size, get_mtime, ImageCls): + self.compose.conf = { + 'buildinstall_symlink': False, + 'disc_types': {'boot': 'netinst'}, + } + IsoWrapper = IsoWrapperCls.return_value + get_file_size.return_value = 1024 + get_mtime.return_value = 13579 + + link_boot_iso(self.compose, 'x86_64', self.compose.variants['Server']) + + tgt = self.topdir + '/compose/Server/x86_64/iso/image-name' + self.assertTrue(os.path.isfile(tgt)) + self.assertEqual(os.stat(tgt).st_ino, + os.stat(self.topdir + '/compose/Server/x86_64/os/images/boot.iso').st_ino) + + self.assertItemsEqual( + self.compose.get_image_name.mock_calls, + [mock.call('x86_64', self.compose.variants['Server'], + disc_type='netinst', disc_num=None, suffix='.iso')]) + self.assertItemsEqual(IsoWrapper.get_implanted_md5.mock_calls, + [mock.call(tgt)]) + self.assertItemsEqual(IsoWrapper.get_manifest_cmd.mock_calls, + [mock.call('image-name')]) + self.assertItemsEqual(IsoWrapper.get_volume_id.mock_calls, + [mock.call(tgt)]) + self.assertItemsEqual(run.mock_calls, + [mock.call(IsoWrapper.get_manifest_cmd.return_value, + workdir=self.topdir + '/compose/Server/x86_64/iso')]) + + image = ImageCls.return_value + self.assertEqual(image.path, 'Server/x86_64/iso/image-name') + self.assertEqual(image.mtime, 13579) + self.assertEqual(image.size, 1024) + self.assertEqual(image.arch, 'x86_64') + self.assertEqual(image.type, "boot") + self.assertEqual(image.format, "iso") + self.assertEqual(image.disc_number, 1) + self.assertEqual(image.disc_count, 1) + self.assertEqual(image.bootable, True) + self.assertEqual(image.implant_md5, IsoWrapper.get_implanted_md5.return_value) + self.assertEqual(self.compose.im.add.mock_calls, + [mock.call('Server', 'x86_64', image)]) + if __name__ == "__main__": unittest.main()