From b62b468ccf4690ba46addf9c796b4c2c9ec6f97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 1 Jun 2016 16:53:51 +0200 Subject: [PATCH] [createiso] Enable customizing media reserve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a documented and tested config options for setting ISO parameters instead of hardcoding magic values. Fixes: #256 Signed-off-by: Lubomír Sedlář --- doc/configuration.rst | 9 +++++++++ pungi/phases/createiso.py | 19 ++++++++++--------- tests/test_createiso_phase.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index be5f8156..06c8e797 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -765,6 +765,15 @@ Options ``optional`` variants. By default only variants with type ``variant`` or ``layered-product`` will get ISOs. +**iso_size** = 4700000000 + (*int|str*) -- size of ISO image. The value should either be an integer + meaning size in bytes, or it can be a string with ``k``, ``M``, ``G`` + suffix (using multiples of 1024). + +**split_iso_reserve** = 10MiB + (*int|str*) -- how much free space should be left on each disk. The format + is the same as for ``iso_size`` option. + .. note:: Source architecture needs to be listed explicitly. diff --git a/pungi/phases/createiso.py b/pungi/phases/createiso.py index 1823f15d..e8c97b6b 100644 --- a/pungi/phases/createiso.py +++ b/pungi/phases/createiso.py @@ -32,7 +32,7 @@ from pungi.wrappers.kojiwrapper import KojiWrapper from pungi.phases.base import PhaseBase from pungi.util import (makedirs, get_volid, get_arch_variant_data, failable, get_file_size, get_mtime) -from pungi.media_split import MediaSplitter +from pungi.media_split import MediaSplitter, convert_media_size from pungi.compose_metadata.discinfo import read_discinfo, write_discinfo @@ -284,19 +284,20 @@ class CreateIsoThread(WorkerThread): def split_iso(compose, arch, variant): - # XXX: hardcoded - media_size = 4700000000 - media_reserve = 10 * 1024 * 1024 + """ + Split contents of the os/ directory for given tree into chunks fitting on ISO. - ms = MediaSplitter(str(media_size - media_reserve), compose) + All files from the directory are taken except for possible boot.iso image. + Files added in extra_files phase are put on all disks. + """ + media_size = compose.conf.get('iso_size', 4700000000) + media_reserve = compose.conf.get('split_iso_reserve', 10 * 1024 * 1024) + + ms = MediaSplitter(convert_media_size(media_size) - convert_media_size(media_reserve), compose) os_tree = compose.paths.compose.os_tree(arch, variant) extra_files_dir = compose.paths.work.extra_files_dir(arch, variant) -# ti_path = os.path.join(os_tree, ".treeinfo") -# ti = productmd.treeinfo.TreeInfo() -# ti.load(ti_path) - # scan extra files to mark them "sticky" -> they'll be on all media after split extra_files = set() for root, dirs, files in os.walk(extra_files_dir): diff --git a/tests/test_createiso_phase.py b/tests/test_createiso_phase.py index 837d2e54..b5412cc9 100755 --- a/tests/test_createiso_phase.py +++ b/tests/test_createiso_phase.py @@ -603,6 +603,34 @@ class SplitIsoTest(helpers.PungiTestCase): os.path.join(base_path, 'Packages/spacer.rpm')]) self.assertEqual(data[1]['files'], [os.path.join(base_path, 'Packages/x/pad.rpm')]) + def test_can_customize_reserve(self): + compose = helpers.DummyCompose(self.topdir, {'split_iso_reserve': 1024 ** 2}) + helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), + TREEINFO) + helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/spacer.rpm')) + helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/x/pad.rpm')) + + M = 1024 ** 2 + + with mock.patch('os.path.getsize', DummySize({'spacer': 4688465664, 'pad': 5 * M})): + data = createiso.split_iso(compose, 'x86_64', compose.variants['Server']) + + self.assertEqual(len(data), 1) + + def test_can_change_iso_size(self): + compose = helpers.DummyCompose(self.topdir, {'iso_size': '8G'}) + helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), + TREEINFO) + helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/spacer.rpm')) + helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/x/pad.rpm')) + + M = 1024 ** 2 + + with mock.patch('os.path.getsize', DummySize({'spacer': 4688465664, 'pad': 5 * M})): + data = createiso.split_iso(compose, 'x86_64', compose.variants['Server']) + + self.assertEqual(len(data), 1) + if __name__ == '__main__': unittest.main()