Merge pull request #30057 from abednarik/virtual_ret_parted_module

modules.parted: __virtual__ return err msg.
This commit is contained in:
Mike Place 2015-12-30 08:57:55 -07:00
commit d09e69f3fc
2 changed files with 16 additions and 8 deletions

View file

@ -49,13 +49,17 @@ def __virtual__():
These are usually provided by the ``parted`` and ``util-linux`` packages.
'''
if salt.utils.is_windows():
return False
return (False, 'The parted execution module failed to load '
'Windows systems are not supported.')
if not salt.utils.which('parted'):
return False
return (False, 'The parted execution module failed to load '
'parted binary is not in the path.')
if not salt.utils.which('lsblk'):
return False
return (False, 'The parted execution module failed to load '
'lsblk binary is not in the path.')
if not salt.utils.which('partprobe'):
return False
return (False, 'The parted execution module failed to load '
'partprobe binary is not in the path.')
return __virtualname__

View file

@ -41,25 +41,29 @@ class PartedTestCase(TestCase):
def test_virtual_bails_on_windows(self):
'''If running windows, __virtual__ shouldn't register module'''
ret = parted.__virtual__()
self.assertFalse(ret)
err = (False, 'The parted execution module failed to load Windows systems are not supported.')
self.assertEqual(err, ret)
@patch('salt.utils.which', lambda exe: not exe == "parted")
def test_virtual_bails_without_parted(self):
'''If parted not in PATH, __virtual__ shouldn't register module'''
ret = parted.__virtual__()
self.assertFalse(ret)
err = (False, 'The parted execution module failed to load parted binary is not in the path.')
self.assertEqual(err, ret)
@patch('salt.utils.which', lambda exe: not exe == "lsblk")
def test_virtual_bails_without_lsblk(self):
'''If lsblk not in PATH, __virtual__ shouldn't register module'''
ret = parted.__virtual__()
self.assertFalse(ret)
err = (False, 'The parted execution module failed to load lsblk binary is not in the path.')
self.assertEqual(err, ret)
@patch('salt.utils.which', lambda exe: not exe == "partprobe")
def test_virtual_bails_without_partprobe(self):
'''If partprobe not in PATH, __virtual__ shouldn't register module'''
ret = parted.__virtual__()
self.assertFalse(ret)
err = (False, 'The parted execution module failed to load partprobe binary is not in the path.')
self.assertEqual(err, ret)
@patch('salt.utils.is_windows', lambda: False)
@patch('salt.utils.which',