def test_snapshot_success(self): ''' Tests zfs snapshot success ''' res = OrderedDict([('snapshotted', True)]) ret = {'pid': 69125, 'retcode': 0, 'stderr': '', 'stdout': ''} mock_cmd = MagicMock(return_value=ret) with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}), \ patch.dict(zfs.__utils__, utils_patch): self.assertEqual(res, zfs.snapshot('myzpool/mydataset@baseline'))
def test_snapshot_failure2(self): ''' Tests zfs snapshot failure ''' res = OrderedDict([ ('snapshotted', False), ('error', "cannot open 'myzpool/mydataset': dataset does not exist"), ]) ret = { 'pid': 69256, 'retcode': 2, 'stderr': "cannot open 'myzpool/mydataset': dataset does not exist\nusage:\n\tsnapshot [-r] [-o property=value] ... <filesystem|volume>@<snap> ...\n\nFor the property list, run: zfs set|get\n\nFor the delegated permission list, run: zfs allow|unallow", 'stdout': '' } mock_cmd = MagicMock(return_value=ret) with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}), \ patch.dict(zfs.__utils__, utils_patch): self.assertEqual(res, zfs.snapshot('myzpool/mydataset@baseline'))
def test_snapshot_failure(self): ''' Tests zfs snapshot failure ''' res = OrderedDict([ ('snapshotted', False), ('error', "cannot create snapshot 'myzpool/mydataset@baseline': dataset already exists" ), ]) ret = { 'pid': 68526, 'retcode': 1, 'stderr': "cannot create snapshot 'myzpool/mydataset@baseline': dataset already exists", 'stdout': '' } mock_cmd = MagicMock(return_value=ret) with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}), \ patch.dict(zfs.__utils__, utils_patch): self.assertEqual(res, zfs.snapshot('myzpool/mydataset@baseline'))