Merge pull request #39071 from sergeizv/fix-lvm-pvcreate

Fix modules.linux_lvm.pvcreate on existing LVM PVs
This commit is contained in:
Mike Place 2017-01-31 11:36:53 -07:00 committed by GitHub
commit c54d9f4e2a
2 changed files with 19 additions and 2 deletions

View File

@ -229,7 +229,7 @@ def pvcreate(devices, override=True, **kwargs):
elif not override:
raise CommandExecutionError('Device "{0}" is already an LVM physical volume.'.format(device))
if not cmd[1:]:
if not cmd[2:]:
# All specified devices are already LVM volumes
return True

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'}
@ -160,6 +163,20 @@ class LinuxLVMTestCase(TestCase):
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000), True)
def test_pvcreate_existing_pvs(self):
'''
Test a scenario when all the submitted devices are already LVM PVs.
'''
pvdisplay = MagicMock(return_value=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'}
cmd_mock = MagicMock(return_value=ret)
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': cmd_mock}):
self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000),
True)
cmd_mock.assert_not_called()
def test_pvremove(self):
'''
Tests for remove a physical device being used as an LVM physical volume