Mock execute in unit test

This patch fixes the test_volume_create_after_thin_creation test
to mock execute instead of defining an execute method inside
the test. Since the unit test is run twice with different options,
the unit test asserts different things depending on the configuration
of how the test is being run.

Change-Id: Ia841ca55b36aa19d4d6b174239f4d4200793d4e5
Closes-bug: 1676646
This commit is contained in:
Kendall Nelson 2017-07-24 22:15:01 -07:00
parent 212b045a02
commit 438b3e8fc2
1 changed files with 13 additions and 8 deletions

View File

@ -347,18 +347,23 @@ class BrickLvmTestCase(test.TestCase):
See bug #1220286 for more info.
"""
vg_name = "vg-name"
pool_name = vg_name + "-pool"
pool_path = "%s/%s" % (vg_name, pool_name)
def executor(obj, *cmd, **kwargs):
self.assertEqual(pool_path, cmd[-1])
self.vg._executor = executor
self.vg.create_thin_pool(pool_name, "1G")
self.vg.create_volume("test", "1G", lv_type='thin')
with mock.patch.object(self.vg, '_execute'):
self.vg.create_volume("test", "1G", lv_type='thin')
if self.configuration.lvm_suppress_fd_warnings is False:
self.vg._execute.assert_called_once_with(
'env', 'LC_ALL=C', 'lvcreate', '-T', '-V',
'1G', '-n', 'test', 'fake-vg/vg-name-pool',
root_helper='sudo', run_as_root=True)
else:
self.vg._execute.assert_called_once_with(
'env', 'LC_ALL=C', 'LVM_SUPPRESS_FD_WARNINGS=1',
'lvcreate', '-T', '-V', '1G', '-n', 'test',
'fake-vg/vg-name-pool', root_helper='sudo',
run_as_root=True)
self.assertEqual(pool_name, self.vg.vg_thin_pool)
def test_volume_create_when_executor_failed(self):