From ba0eb30a75c0e20dfe0e8065d9765292fc963e95 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Wed, 18 Apr 2018 12:39:35 -0400 Subject: [PATCH] mock utils.execute() in qemu-img unit test There was a unit test that was not mocking utils.execute() and relying on qemu-img being installed on the machine running the tests. This fixes the test to mock out utils.execute() and raise a ProcessExecutionError that simulates the expected behaviour from qemu-img. Fixes bug: #1765122 Change-Id: Ia6fc089fce0cc0ba1fb8d4d4ffbf7f47968a0507 (cherry picked from commit 815b11f70a3fd31888fb3e3e7b38e3a697bf6244) (cherry picked from commit cf927f177be3ff0d1df069bc66f889ebcce93754) --- nova/tests/unit/virt/test_images.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nova/tests/unit/virt/test_images.py b/nova/tests/unit/virt/test_images.py index ac6392d99a70..f89703c525ce 100644 --- a/nova/tests/unit/virt/test_images.py +++ b/nova/tests/unit/virt/test_images.py @@ -30,8 +30,12 @@ class QemuTestCase(test.NoDBTestCase): images.qemu_img_info, '/path/that/does/not/exist') + @mock.patch.object(utils, 'execute') @mock.patch.object(os.path, 'exists', return_value=True) - def test_qemu_info_with_errors(self, path_exists): + def test_qemu_info_with_errors(self, path_exists, mock_exec): + err = processutils.ProcessExecutionError( + exit_code=1, stderr='No such file or directory') + mock_exec.side_effect = err self.assertRaises(exception.DiskNotFound, images.qemu_img_info, '/fake/path')