mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #39071 from sergeizv/fix-lvm-pvcreate
Fix modules.linux_lvm.pvcreate on existing LVM PVs
This commit is contained in:
commit
c54d9f4e2a
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user