From 456fbb88129ac67118dfb1f98a9ee44f53bf260a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 23 Feb 2016 09:35:50 +0100 Subject: [PATCH] [live-images] Correctly create format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extracting extensions from the file name is not reliable as there is no way to determine where extensions start. There can very well be a version.release separated by dot. To bypass this, just use hardcoded list of possible formats. Signed-off-by: Lubomír Sedlář --- pungi/phases/live_images.py | 17 ++++++++--------- tests/test_liveimagesphase.py | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pungi/phases/live_images.py b/pungi/phases/live_images.py index c3eb3e20..57f5b24b 100644 --- a/pungi/phases/live_images.py +++ b/pungi/phases/live_images.py @@ -197,6 +197,8 @@ class LiveImagesPhase(PhaseBase): class CreateLiveImageThread(WorkerThread): + EXTS = ('.iso', '.raw.xz') + def process(self, item, num): compose, cmd, variant, arch = item try: @@ -290,20 +292,17 @@ class CreateLiveImageThread(WorkerThread): compose.im.add(variant=variant.uid, arch=arch, image=img) def _is_image(self, path): - for ext in ('.iso', '.raw.xz'): + for ext in self.EXTS: if path.endswith(ext): return True return False def _get_format(self, path): - """Extract all extensions from the path.""" - exts = [] - while True: - path, ext = os.path.splitext(path) - if not ext: - break - exts.append(ext.lstrip('.')) - return '.'.join(reversed(exts)) + """Get format based on extension.""" + for ext in self.EXTS: + if path.endswith(ext): + return ext[1:] + raise RuntimeError('Getting format for unknown image %s' % path) def _write_manifest(self, iso_path): """Generate manifest for ISO at given path. diff --git a/tests/test_liveimagesphase.py b/tests/test_liveimagesphase.py index 8a2895a7..a63fe3ef 100755 --- a/tests/test_liveimagesphase.py +++ b/tests/test_liveimagesphase.py @@ -409,7 +409,7 @@ class TestCreateLiveImageThread(PungiTestCase): 'output': 'some output', 'task_id': 123 } - koji_wrapper.get_image_path.return_value = ['/path/to/image.raw.xz'] + koji_wrapper.get_image_path.return_value = ['/path/to/image-a.b-sda.raw.xz'] t = CreateLiveImageThread(pool) with mock.patch('pungi.phases.live_images.get_file_size') as get_file_size: @@ -424,7 +424,7 @@ class TestCreateLiveImageThread(PungiTestCase): log_file=self.topdir + '/logs/amd64/createiso-None-None-None.amd64.log')]) self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)]) self.assertEqual(copy2.mock_calls, - [mock.call('/path/to/image.raw.xz', self.topdir + '/compose/Client/amd64/iso/image-name')]) + [mock.call('/path/to/image-a.b-sda.raw.xz', self.topdir + '/compose/Client/amd64/iso/image-name')]) write_manifest_cmd = ' && '.join([ 'cd ' + self.topdir + '/compose/Client/amd64/iso',