Пример #1
0
    def test_pvcreate(self):
        '''
        Tests for set a physical device to be used as an LVM physical volume
        '''
        self.assertEqual(linux_lvm.pvcreate(''),
                         'Error: at least one device is required')

        self.assertRaises(CommandExecutionError, linux_lvm.pvcreate, 'A')

        # 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'
                }
                mock = MagicMock(return_value=ret)
                with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
                    self.assertEqual(
                        linux_lvm.pvcreate('A', metadatasize=1000), True)
Пример #2
0
    def test_pvcreate(self):
        """
        Tests for set a physical device to be used as an LVM physical volume
        """
        self.assertEqual(
            linux_lvm.pvcreate(""), "Error: at least one device is required"
        )

        self.assertEqual(linux_lvm.pvcreate("A"), "A does not exist")

        # 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",
                }
                mock = MagicMock(return_value=ret)
                with patch.dict(linux_lvm.__salt__, {"cmd.run_all": mock}):
                    self.assertEqual(linux_lvm.pvcreate("A", metadatasize=1000), True)
Пример #3
0
    def test_pvcreate(self):
        '''
        Tests for set a physical device to be used as an LVM physical volume
        '''
        self.assertEqual(linux_lvm.pvcreate(''),
                         'Error: at least one device is required')

        self.assertEqual(linux_lvm.pvcreate('A'), 'A does not exist')

        with patch.object(os.path, 'exists', return_value=True):
            mock = MagicMock(return_value='A\nB')
            with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
                self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000),
                                 'A')
Пример #4
0
    def test_pvcreate(self):
        '''
        Tests for set a physical device to be used as an LVM physical volume
        '''
        self.assertEqual(linux_lvm.pvcreate(''),
                         'Error: at least one device is required')

        self.assertEqual(linux_lvm.pvcreate('A'), 'A does not exist')

        with patch.object(os.path, 'exists', return_value=True):
            mock = MagicMock(return_value='A\nB')
            with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
                self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000),
                                 'A')
Пример #5
0
    def test_pvcreate(self):
        '''
        Tests for set a physical device to be used as an LVM physical volume
        '''
        self.assertEqual(linux_lvm.pvcreate(''),
                         'Error: at least one device is required')

        self.assertRaises(CommandExecutionError, linux_lvm.pvcreate, 'A')

        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'}
                mock = MagicMock(return_value=ret)
                with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
                    self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000), True)
Пример #6
0
    def test_pvcreate(self):
        '''
        Tests for set a physical device to be used as an LVM physical volume
        '''
        self.assertEqual(linux_lvm.pvcreate(''),
                         'Error: at least one device is required')

        self.assertRaises(CommandExecutionError, linux_lvm.pvcreate, 'A')

        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'}
                mock = MagicMock(return_value=ret)
                with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
                    self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000), True)
Пример #7
0
 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)
                 self.assertTrue(cmd_mock.call_count == 0)
Пример #8
0
 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)
                 self.assertTrue(cmd_mock.call_count == 0)