示例#1
0
def test_import_duplicate(utils_patch):
    """
    Tests import with already imported pool
    """
    ret = {}
    ret["stdout"] = ""
    ret["stderr"] = "\n".join(
        [
            "cannot import 'mypool': a pool with that name already exists",
            "use the form 'zpool import <pool | id> <newpool>' to give it a new"
            " name",
        ]
    )
    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.import_("mypool")
        res = OrderedDict(
            [
                ("imported", False),
                (
                    "error",
                    "cannot import 'mypool': a pool with that name already"
                    " exists\nuse the form 'zpool import <pool | id> <newpool>' to"
                    " give it a new name",
                ),
            ]
        )
        assert ret == res
示例#2
0
    def test_import_success(self):
        """
        Tests import
        """
        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.import_("mypool")
            res = OrderedDict([("imported", True)])
            self.assertEqual(ret, res)
示例#3
0
    def test_import_success(self):
        '''
        Tests import
        '''
        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.import_('mypool')
            res = OrderedDict([('imported', True)])
            self.assertEqual(ret, res)
示例#4
0
    def test_import_nopool(self):
        """
        Tests import
        """
        ret = {}
        ret["stdout"] = ""
        ret["stderr"] = "cannot import 'mypool': no such pool available"
        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.import_("mypool")
            res = OrderedDict([
                ("imported", False),
                ("error", "cannot import 'mypool': no such pool available"),
            ])
            self.assertEqual(ret, res)
示例#5
0
    def test_import_nopool(self):
        '''
        Tests import
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "cannot import 'mypool': no such pool available"
        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.import_('mypool')
            res = OrderedDict([
                ('imported', False),
                ('error', "cannot import 'mypool': no such pool available"),
            ])
            self.assertEqual(ret, res)
示例#6
0
    def test_import_duplicate(self):
        '''
        Tests import with already imported pool
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "\n".join([
            "cannot import 'mypool': a pool with that name already exists",
            "use the form 'zpool import <pool | id> <newpool>' to give it a new name",
        ])
        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.import_('mypool')
            res = OrderedDict([
                ('imported', False),
                ('error', "cannot import 'mypool': a pool with that name already exists\nuse the form 'zpool import <pool | id> <newpool>' to give it a new name"),
            ])
            self.assertEqual(ret, res)