def test_delete_backup_snapshot(self): snap_name = 'backup.%s.snap.3824923.1412' % (uuid.uuid4()) base_name = self.service._get_backup_base_name(self.volume_id, diff_format=True) self.stubs.Set(self.service, '_get_backup_snap_name', lambda *args: snap_name) self.stubs.Set(self.service, 'get_backup_snaps', lambda *args: None) rem = self.service._delete_backup_snapshot(mock_rados(), base_name, self.backup_id) self.assertEqual(rem, (snap_name, 0))
def test_diff_restore_allowed_false(self): not_allowed = (False, None) backup = db.backup_get(self.ctxt, self.backup_id) self._create_volume_db_entry(self.volume_id, 1) original_volume = db.volume_get(self.ctxt, self.volume_id) rbd_io = self._get_wrapped_rbd_io(self.service.rbd.Image()) self.stubs.Set(self.service, '_get_restore_point', lambda *args: None) self.stubs.Set(self.service, '_rbd_has_extents', lambda *args: True) self.stubs.Set(self.service, '_rbd_image_exists', lambda *args: (False, 'foo')) self.stubs.Set(self.service, '_file_is_rbd', lambda *args: False) resp = self.service._diff_restore_allowed('foo', backup, original_volume, rbd_io, mock_rados()) self.assertEqual(resp, not_allowed)
def test_diff_restore_allowed_true(self): is_allowed = (True, 'restore.foo') backup = db.backup_get(self.ctxt, self.backup_id) alt_volume_id = str(uuid.uuid4()) self._create_volume_db_entry(alt_volume_id, 1) alt_volume = db.volume_get(self.ctxt, alt_volume_id) rbd_io = self._get_wrapped_rbd_io(self.service.rbd.Image()) self.stubs.Set(self.service, '_get_restore_point', lambda *args: 'restore.foo') self.stubs.Set(self.service, '_rbd_has_extents', lambda *args: False) self.stubs.Set(self.service, '_rbd_image_exists', lambda *args: (True, 'foo')) self.stubs.Set(self.service, '_file_is_rbd', lambda *args: True) resp = self.service._diff_restore_allowed('foo', backup, alt_volume, rbd_io, mock_rados()) self.assertEqual(resp, is_allowed)
def test_diff_restore_allowed_false(self): not_allowed = (False, None) backup = db.backup_get(self.ctxt, self.backup_id) self._create_volume_db_entry(self.volume_id, 1) original_volume = db.volume_get(self.ctxt, self.volume_id) rbd_io = self._get_wrapped_rbd_io(self.service.rbd.Image()) self.stubs.Set(self.service, '_get_restore_point', lambda *args: None) self.stubs.Set(self.service, '_rbd_has_extents', lambda *args: True) self.stubs.Set(self.service, '_rbd_image_exists', lambda *args: (False, 'foo')) self.stubs.Set(self.service, '_file_is_rbd', lambda *args: False) resp = self.service._diff_restore_allowed('foo', backup, original_volume, rbd_io, mock_rados()) self.assertEquals(resp, not_allowed)
def test_diff_restore_allowed_true(self): is_allowed = (True, 'restore.foo') backup = db.backup_get(self.ctxt, self.backup_id) alt_volume_id = str(uuid.uuid4()) self._create_volume_db_entry(alt_volume_id, 1) alt_volume = db.volume_get(self.ctxt, alt_volume_id) rbd_io = self._get_wrapped_rbd_io(self.service.rbd.Image()) self.stubs.Set(self.service, '_get_restore_point', lambda *args: 'restore.foo') self.stubs.Set(self.service, '_rbd_has_extents', lambda *args: False) self.stubs.Set(self.service, '_rbd_image_exists', lambda *args: (True, 'foo')) self.stubs.Set(self.service, '_file_is_rbd', lambda *args: True) resp = self.service._diff_restore_allowed('foo', backup, alt_volume, rbd_io, mock_rados()) self.assertEquals(resp, is_allowed)
def test_diff_restore_allowed_false(self): volume_size = 1 not_allowed = (False, None) backup = db.backup_get(self.ctxt, self.backup_id) self._create_volume_db_entry(self.volume_id, volume_size) original_volume = db.volume_get(self.ctxt, self.volume_id) rbd_io = self._get_wrapped_rbd_io(self.service.rbd.Image()) test_args = 'foo', backup, original_volume, rbd_io, mock_rados() self._set_service_stub('_get_restore_point', None) resp = self.service._diff_restore_allowed(*test_args) self.assertEqual(resp, not_allowed) self._set_service_stub('_get_restore_point', 'restore.foo') self._set_service_stub('_rbd_has_extents', True) resp = self.service._diff_restore_allowed(*test_args) self.assertEqual(resp, not_allowed) self._set_service_stub('_rbd_has_extents', False) self._set_service_stub('_rbd_image_exists', (False, 'foo')) resp = self.service._diff_restore_allowed(*test_args) self.assertEqual(resp, not_allowed) self._set_service_stub('_rbd_image_exists', None) self.stubs.Set(self.service.rbd.Image, 'size', lambda *args, **kwargs: volume_size * units.GiB * 2) resp = self.service._diff_restore_allowed(*test_args) self.assertEqual(resp, not_allowed) self.stubs.Set(self.service.rbd.Image, 'size', lambda *args, **kwargs: volume_size * units.GiB) self._set_service_stub('_file_is_rbd', False) resp = self.service._diff_restore_allowed(*test_args) self.assertEqual(resp, not_allowed) self._set_service_stub('_file_is_rbd', True)