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
This commit is contained in:
Kaifeng Wang 2018-03-01 17:22:08 +08:00
parent e26f11c3dc
commit 0c159b021e
1 changed files with 8 additions and 3 deletions

View File

@ -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):