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
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)
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)
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)
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)
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)