示例#1
0
    def test_snapshot_present(self):
        '''
        Test if snapshot is present (snapshot already present)
        '''
        ret = {
            'name': 'myzpool/filesystem@snap',
            'result': True,
            'comment': 'snapshot is present',
            'changes': {}
        }

        mock_exists = MagicMock(return_value=True)
        with patch.dict(zfs.__salt__, {'zfs.exists': mock_exists}), \
             patch.dict(zfs.__utils__, utils_patch):
            self.assertEqual(ret,
                             zfs.snapshot_present('myzpool/filesystem@snap'))
示例#2
0
    def test_snapshot_present_new(self):
        '''
        Test if snapshot is present (new)
        '''
        ret = {
            'name': 'myzpool/filesystem@snap',
            'result': True,
            'comment': 'snapshot myzpool/filesystem@snap was created',
            'changes': {
                u'myzpool/filesystem@snap': u'snapshotted'
            }
        }

        mock_exists = MagicMock(return_value=False)
        mock_snapshot = MagicMock(return_value=OrderedDict([('snapshotted',
                                                             True)]))
        with patch.dict(zfs.__salt__, {'zfs.exists': mock_exists}), \
             patch.dict(zfs.__salt__, {'zfs.snapshot': mock_snapshot}), \
             patch.dict(zfs.__utils__, utils_patch):
            self.assertEqual(ret,
                             zfs.snapshot_present('myzpool/filesystem@snap'))
示例#3
0
    def test_snapshot_present_fail(self):
        '''
        Test if snapshot is present (using non existing snapshot)
        '''
        ret = {
            'name': 'myzpool/filesystem@snap',
            'result': False,
            'comment':
            "cannot open 'myzpool/filesystem': dataset does not exist",
            'changes': {}
        }

        mock_exists = MagicMock(return_value=False)
        mock_snapshot = MagicMock(return_value=OrderedDict([
            ('snapshotted', False),
            ('error',
             "cannot open 'myzpool/filesystem': dataset does not exist"),
        ]))
        with patch.dict(zfs.__salt__, {'zfs.exists': mock_exists}), \
             patch.dict(zfs.__salt__, {'zfs.snapshot': mock_snapshot}), \
             patch.dict(zfs.__utils__, utils_patch):
            self.assertEqual(ret,
                             zfs.snapshot_present('myzpool/filesystem@snap'))