Fix test for modules.linux_lvm.pvcreate

pvdisplay() would be called by pvcreate() twice: firstly to check
whether a device is already initialized for use by LVM and then to
ensure that the pvcreate executable did its job correctly. The test
replaces pvdisplay() with a mock that always returns True and thus
pvcreate() would think that a specified device is already initialized
and exit. In the other words, instead of testing physical volume
initialization the test simulates a case with all the submitted
devices already initialized.

Fix it by replacing pvdisplay with a mock that returns False on the
first call (thus pvcreate thinks that a device is not a PV yet) and True
on the second call (after the pvcreate executable is called).
This commit is contained in:
Sergei Zviagintsev 2017-01-27 00:03:55 +01:00
parent 88b171f863
commit 3967992bfd

View file

@ -152,7 +152,10 @@ class LinuxLVMTestCase(TestCase):
self.assertRaises(CommandExecutionError, linux_lvm.pvcreate, 'A')
pvdisplay = MagicMock(return_value=True)
# pvdisplay() would be called by pvcreate() twice: firstly to check
# whether a device is already initialized for use by LVM and then to
# ensure that the pvcreate executable did its job correctly.
pvdisplay = MagicMock(side_effect=[False, True])
with patch('salt.modules.linux_lvm.pvdisplay', pvdisplay):
with patch.object(os.path, 'exists', return_value=True):
ret = {'stdout': 'saltines', 'stderr': 'cheese', 'retcode': 0, 'pid': '1337'}