Exemple #1
0
def test_labelclear_exported(utils_patch):
    """
    Tests labelclear on device with from exported pool
    """
    ret = {}
    ret["stdout"] = ""
    ret["stderr"] = "\n".join(
        [
            "use '-f' to override the following error:",
            '/dev/rdsk/c0t0d0 is a member of exported pool "mypool"',
        ]
    )
    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.labelclear("/dev/rdsk/c0t0d0", force=False)
        res = OrderedDict(
            [
                ("labelcleared", False),
                (
                    "error",
                    "use 'force=True' to override the following"
                    " error:\n/dev/rdsk/c0t0d0 is a member of exported pool"
                    ' "mypool"',
                ),
            ]
        )
        assert ret == res
Exemple #2
0
 def test_labelclear_success(self):
     '''
     Tests labelclear on succesful label removal
     '''
     ret = {}
     ret['stdout'] = ""
     ret['stderr'] = ""
     ret['retcode'] = 0
     mock_cmd = MagicMock(return_value=ret)
     with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
         ret = zpool.labelclear('/dev/rdsk/c0t0d0', force=False)
         res = OrderedDict([('/dev/rdsk/c0t0d0', 'cleared')])
         self.assertEqual(res, ret)
Exemple #3
0
 def test_labelclear_cleared(self):
     '''
     Tests labelclear on device with no label
     '''
     ret = {}
     ret['stdout'] = ""
     ret['stderr'] = "failed to read label from /dev/rdsk/c0t0d0"
     ret['retcode'] = 1
     mock_cmd = MagicMock(return_value=ret)
     with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
         ret = zpool.labelclear('/dev/rdsk/c0t0d0', force=False)
         res = OrderedDict([('/dev/rdsk/c0t0d0',
                             'failed to read label from /dev/rdsk/c0t0d0')])
         self.assertEqual(res, ret)
Exemple #4
0
    def test_labelclear_success(self):
        """
        Tests labelclear on successful label removal
        """
        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.labelclear("/dev/rdsk/c0t0d0", force=False)
            res = OrderedDict([("labelcleared", True)])
            self.assertEqual(ret, res)
Exemple #5
0
    def test_labelclear_cleared(self):
        """
        Tests labelclear on device with no label
        """
        ret = {}
        ret["stdout"] = ""
        ret["stderr"] = "failed to read label from /dev/rdsk/c0t0d0"
        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.labelclear("/dev/rdsk/c0t0d0", force=False)
            res = OrderedDict([
                ("labelcleared", False),
                ("error", "failed to read label from /dev/rdsk/c0t0d0"),
            ])
            self.assertEqual(ret, res)
Exemple #6
0
    def test_labelclear_nodevice(self):
        '''
        Tests labelclear on non existing device
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "failed to open /dev/rdsk/c0t0d0: No such file or directory"
        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.labelclear('/dev/rdsk/c0t0d0', force=False)
            res = OrderedDict([
                ('labelcleared', False),
                ('error', 'failed to open /dev/rdsk/c0t0d0: No such file or directory'),
            ])
            self.assertEqual(ret, res)
Exemple #7
0
 def test_labelclear_exported(self):
     '''
     Tests labelclear on device with from exported pool
     '''
     ret = {}
     ret['stdout'] = ""
     ret['stderr'] = "\n".join([
         "use '-f' to override the following error:",
         '/dev/rdsk/c0t0d0 is a member of exported pool "mypool"',
     ])
     ret['retcode'] = 1
     mock_cmd = MagicMock(return_value=ret)
     with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
         ret = zpool.labelclear('/dev/rdsk/c0t0d0', force=False)
         res = OrderedDict([
             ('/dev/rdsk/c0t0d0',
              '/dev/rdsk/c0t0d0 is a member of exported pool "mypool"')
         ])
         self.assertEqual(res, ret)
Exemple #8
0
    def test_labelclear_nodevice(self):
        """
        Tests labelclear on non existing device
        """
        ret = {}
        ret["stdout"] = ""
        ret["stderr"] = "failed to open /dev/rdsk/c0t0d0: No such file or directory"
        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.labelclear("/dev/rdsk/c0t0d0", force=False)
            res = OrderedDict([
                ("labelcleared", False),
                (
                    "error",
                    "failed to open /dev/rdsk/c0t0d0: No such file or directory",
                ),
            ])
            self.assertEqual(ret, res)