From 0c159b021e8aaef3c4cb1173c09f40a8499aea7e Mon Sep 17 00:00:00 2001 From: Kaifeng Wang Date: Thu, 1 Mar 2018 17:22:08 +0800 Subject: [PATCH] test_failure_to_write fails with root user The test test_failure_to_write will fail with root. This patch add a mock to prevent path creation, makes the test fits for root and non-root user. Change-Id: I7e55c4070c41927f05c2cfdd284c8d542f1d8906 Closes-Bug: #1693129 --- ironic_inspector/test/unit/test_process.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ironic_inspector/test/unit/test_process.py b/ironic_inspector/test/unit/test_process.py index 2a1e9f4fc..2ace74eba 100644 --- a/ironic_inspector/test/unit/test_process.py +++ b/ironic_inspector/test/unit/test_process.py @@ -339,13 +339,18 @@ class TestStoreLogs(BaseProcessTest): process.process(self.data) self._check_contents() + @mock.patch.object(os, 'makedirs', autospec=True) @mock.patch.object(process.LOG, 'exception', autospec=True) - def test_failure_to_write(self, log_mock, hook_mock): + def test_failure_to_write(self, log_mock, makedirs_mock, hook_mock): + tempdir = tempfile.mkdtemp() + logs_dir = os.path.join(tempdir, 'I/never/exist') CONF.set_override('always_store_ramdisk_logs', True, 'processing') - CONF.set_override('ramdisk_logs_dir', '/I/cannot/write/here', - 'processing') + CONF.set_override('ramdisk_logs_dir', logs_dir, 'processing') + makedirs_mock.side_effect = OSError() process.process(self.data) + os.rmdir(tempdir) self.assertEqual([], os.listdir(self.tempdir)) + self.assertTrue(makedirs_mock.called) self.assertTrue(log_mock.called) def test_directory_is_created(self, hook_mock):