From 456fbb88129ac67118dfb1f98a9ee44f53bf260a Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Feb 23 2016 08:35:50 +0000 Subject: [PATCH 1/2] [live-images] Correctly create format 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ář --- diff --git a/pungi/phases/live_images.py b/pungi/phases/live_images.py index c3eb3e2..57f5b24 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 8a2895a..a63fe3e 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', From ca7c78d98cf090574405e62063fc03ba6bd3e6cf Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Feb 23 2016 08:41:03 +0000 Subject: [PATCH 2/2] [live-images] Set type to raw-xz for appliances Signed-off-by: Lubomír Sedlář --- diff --git a/pungi/phases/live_images.py b/pungi/phases/live_images.py index 57f5b24..87b21b7 100644 --- a/pungi/phases/live_images.py +++ b/pungi/phases/live_images.py @@ -280,7 +280,7 @@ class CreateLiveImageThread(WorkerThread): def _add_to_images(self, compose, variant, arch, type, format, path): """Adds the image to images.json""" img = Image(compose.im) - img.type = type + img.type = 'raw-xz' if type == 'appliance' else type img.format = format img.path = os.path.relpath(path, compose.paths.compose.topdir()) img.mtime = get_mtime(path) diff --git a/tests/test_liveimagesphase.py b/tests/test_liveimagesphase.py index a63fe3e..ccbf6a3 100755 --- a/tests/test_liveimagesphase.py +++ b/tests/test_liveimagesphase.py @@ -444,7 +444,7 @@ class TestCreateLiveImageThread(PungiTestCase): release=None, ksurl=None)]) - self.assertEqual(Image.return_value.type, 'appliance') + self.assertEqual(Image.return_value.type, 'raw-xz') self.assertEqual(Image.return_value.format, 'raw.xz') self.assertEqual(Image.return_value.path, 'Client/amd64/iso/image-name') self.assertEqual(Image.return_value.size, 1024)