Esempio n. 1
0
def test_split_not_mirror(utils_patch):
    """
    Tests split on source pool is not a mirror
    """
    ret = {}
    ret["stdout"] = ""
    ret[
        "stderr"
    ] = "Unable to split datapool: Source pool must be composed only of mirrors"
    ret["retcode"] = 1
    mock_cmd = MagicMock(return_value=ret)

    with patch.dict(zpool.__salt__, {"cmd.run_all": mock_cmd}), patch.dict(
        zpool.__utils__, utils_patch
    ):
        ret = zpool.split("datapool", "backuppool")
        res = OrderedDict(
            [
                ("split", False),
                (
                    "error",
                    "Unable to split datapool: Source pool must be composed only of"
                    " mirrors",
                ),
            ]
        )
        assert ret == res
Esempio n. 2
0
    def test_split_success(self):
        """
        Tests split on success
        """
        ret = {}
        ret["stdout"] = ""
        ret["stderr"] = ""
        ret["retcode"] = 0
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {"cmd.run_all": mock_cmd}), patch.dict(
                zpool.__utils__, self.utils_patch):
            ret = zpool.split("datapool", "backuppool")
            res = OrderedDict([("split", True)])
            self.assertEqual(ret, res)
Esempio n. 3
0
    def test_split_success(self):
        '''
        Tests split on success
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = ""
        ret['retcode'] = 0
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}), \
             patch.dict(zpool.__utils__, self.utils_patch):
            ret = zpool.split('datapool', 'backuppool')
            res = OrderedDict([('split', True)])
            self.assertEqual(ret, res)
Esempio n. 4
0
    def test_split_not_mirror(self):
        '''
        Tests split on source pool is not a mirror
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "Unable to split datapool: Source pool must be composed only of mirrors"
        ret['retcode'] = 1
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}), \
             patch.dict(zpool.__utils__, utils_patch):
            ret = zpool.split('datapool', 'backuppool')
            res = OrderedDict([('split', False), ('error', 'Unable to split datapool: Source pool must be composed only of mirrors')])
            self.assertEqual(ret, res)
Esempio n. 5
0
    def test_split_missing_pool(self):
        '''
        Tests split on missing source pool
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "cannot open 'datapool': no such pool"
        ret['retcode'] = 1
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}), \
             patch.dict(zpool.__utils__, utils_patch):
            ret = zpool.split('datapool', 'backuppool')
            res = OrderedDict([('split', False), ('error', "cannot open 'datapool': no such pool")])
            self.assertEqual(ret, res)
Esempio n. 6
0
    def test_split_exist_new(self):
        '''
        Tests split on exising new pool
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "Unable to split datapool: pool already exists"
        ret['retcode'] = 1
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}), \
             patch.dict(zpool.__utils__, utils_patch):
            ret = zpool.split('datapool', 'backuppool')
            res = OrderedDict([('split', False), ('error', 'Unable to split datapool: pool already exists')])
            self.assertEqual(ret, res)
Esempio n. 7
0
    def test_split_missing_pool(self):
        """
        Tests split on missing source pool
        """
        ret = {}
        ret["stdout"] = ""
        ret["stderr"] = "cannot open 'datapool': no such pool"
        ret["retcode"] = 1
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {"cmd.run_all": mock_cmd}), patch.dict(
                zpool.__utils__, self.utils_patch):
            ret = zpool.split("datapool", "backuppool")
            res = OrderedDict([("split", False),
                               ("error",
                                "cannot open 'datapool': no such pool")])
            self.assertEqual(ret, res)
Esempio n. 8
0
    def test_split_success(self):
        '''
        Tests split on success
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = ""
        ret['retcode'] = 0
        mock_cmd = MagicMock(return_value=ret)
        mock_exists = Mock()
        mock_exists.side_effect = [False, True]

        with patch.dict(zpool.__salt__, {'zpool.exists': mock_exists}):
            with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
                ret = zpool.split('datapool', 'backuppool')
                res = OrderedDict([('backuppool', 'split off from datapool')])
                self.assertEqual(res, ret)
Esempio n. 9
0
    def test_split_exist_new(self):
        """
        Tests split on exising new pool
        """
        ret = {}
        ret["stdout"] = ""
        ret["stderr"] = "Unable to split datapool: pool already exists"
        ret["retcode"] = 1
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {"cmd.run_all": mock_cmd}), patch.dict(
                zpool.__utils__, self.utils_patch):
            ret = zpool.split("datapool", "backuppool")
            res = OrderedDict([
                ("split", False),
                ("error", "Unable to split datapool: pool already exists"),
            ])
            self.assertEqual(ret, res)
Esempio n. 10
0
    def test_split_missing_pool(self):
        '''
        Tests split on missing source pool
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = ""
        ret['retcode'] = 0
        mock_cmd = MagicMock(return_value=ret)
        mock_exists = Mock()
        mock_exists.side_effect = [False, False]

        with patch.dict(zpool.__salt__, {'zpool.exists': mock_exists}):
            with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
                ret = zpool.split('datapool', 'backuppool')
                res = OrderedDict([('datapool', 'storage pool does not exists')
                                   ])
                self.assertEqual(res, ret)
Esempio n. 11
0
    def test_split_not_mirror(self):
        '''
        Tests split on source pool is not a mirror
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "Unable to split datapool: Source pool must be composed only of mirrors"
        ret['retcode'] = 1
        mock_cmd = MagicMock(return_value=ret)
        mock_exists = Mock()
        mock_exists.side_effect = [False, True]

        with patch.dict(zpool.__salt__, {'zpool.exists': mock_exists}):
            with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
                ret = zpool.split('datapool', 'backuppool')
                res = OrderedDict([(
                    'backuppool',
                    'Unable to split datapool: Source pool must be composed only of mirrors'
                )])
                self.assertEqual(res, ret)