From 0bac2bf693f054894f2e1b8149de8ecc7772f065 Mon Sep 17 00:00:00 2001 From: NiallBunting Date: Wed, 4 Nov 2015 13:30:18 +0000 Subject: [PATCH] Update os.path.remove as it does not exist Os.path.remove does not exist so this removes it and replaces it with some code that will remove the file. Functionally fulfilling the role that os.path.remove was meant to fill. Change-Id: I040d445007055b31561a592dd74b3e2ffaa9cd54 Closes-bug: 1507564 (cherry picked from commit 36f5ff563258f47fa5159ed4bf11d259bb76caa6) --- glance/async/flows/convert.py | 2 +- glance/tests/unit/async/flows/test_convert.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/glance/async/flows/convert.py b/glance/async/flows/convert.py index c4b61dba5a..639d82886d 100644 --- a/glance/async/flows/convert.py +++ b/glance/async/flows/convert.py @@ -96,7 +96,7 @@ class _Convert(task.Task): fs_path = result.split("file://")[-1] if os.path.exists(fs_path): - os.path.remove(fs_path) + os.remove(fs_path) def get_flow(**kwargs): diff --git a/glance/tests/unit/async/flows/test_convert.py b/glance/tests/unit/async/flows/test_convert.py index 07cb30c80b..672900fc1a 100644 --- a/glance/tests/unit/async/flows/test_convert.py +++ b/glance/tests/unit/async/flows/test_convert.py @@ -94,6 +94,22 @@ class TestImportTask(test_utils.BaseTestCase): rm_mock.return_value = None image_convert.execute(image, 'file:///test/path.raw') + def test_convert_revert_success(self): + image_convert = convert._Convert(self.task.task_id, + self.task_type, + self.img_repo) + + self.task_repo.get.return_value = self.task + image_id = mock.sentinel.image_id + image = mock.MagicMock(image_id=image_id, virtual_size=None) + self.img_repo.get.return_value = image + + with mock.patch.object(processutils, 'execute') as exc_mock: + exc_mock.return_value = ("", None) + with mock.patch.object(os, 'remove') as rmtree_mock: + rmtree_mock.return_value = None + image_convert.revert(image, 'file:///tmp/test') + def test_import_flow_with_convert_and_introspect(self): self.config(engine_mode='serial', group='taskflow_executor')