def test_checkpoints_update_reset_state_with_protection_api_exceptions( self, mock_reset_state): req = fakes.HTTPRequest.blank('/v1/providers/{provider_id}/' 'checkpoints/{checkpoint_id}') body = {'os-resetState': {'state': 'error'}} mock_reset_state.side_effect = exception.AccessCheckpointNotAllowed( checkpoint_id='2220f8b1-975d-4621-a872-fa9afb43cb6c') self.assertRaises(exc.HTTPForbidden, self.controller.checkpoints_update, req, '2220f8b1-975d-4621-a872-fa9afb43cb6c', '2220f8b1-975d-4621-a872-fa9afb43cb6c', body=body) mock_reset_state.side_effect = exception.CheckpointNotFound( checkpoint_id='2220f8b1-975d-4621-a872-fa9afb43cb6c') self.assertRaises(exc.HTTPNotFound, self.controller.checkpoints_update, req, '2220f8b1-975d-4621-a872-fa9afb43cb6c', '2220f8b1-975d-4621-a872-fa9afb43cb6c', body=body) mock_reset_state.side_effect = exception.CheckpointNotBeReset( checkpoint_id='2220f8b1-975d-4621-a872-fa9afb43cb6c') self.assertRaises(exc.HTTPBadRequest, self.controller.checkpoints_update, req, '2220f8b1-975d-4621-a872-fa9afb43cb6c', '2220f8b1-975d-4621-a872-fa9afb43cb6c', body=body)
def show_checkpoint(self, context, provider_id, checkpoint_id): provider = self.provider_registry.show_provider(provider_id) checkpoint = provider.get_checkpoint(checkpoint_id, context=context) checkpoint_dict = checkpoint.to_dict() if not context.is_admin and (context.project_id != checkpoint_dict['project_id']): raise exception.AccessCheckpointNotAllowed( checkpoint_id=checkpoint_id) return checkpoint_dict
def reset_state(self, context, provider_id, checkpoint_id, state): provider = self.provider_registry.show_provider(provider_id) checkpoint = provider.get_checkpoint(checkpoint_id, context=context) checkpoint_dict = checkpoint.to_dict() if not context.is_admin and (context.project_id != checkpoint_dict['project_id']): raise exception.AccessCheckpointNotAllowed( checkpoint_id=checkpoint_id) if checkpoint.status not in [ constants.CHECKPOINT_STATUS_AVAILABLE, constants.CHECKPOINT_STATUS_ERROR, constants.CHECKPOINT_STATUS_COPYING, constants.CHECKPOINT_STATUS_WAIT_COPYING, constants.CHECKPOINT_STATUS_COPY_FINISHED ]: raise exception.CheckpointNotBeReset(checkpoint_id=checkpoint_id) checkpoint.status = state checkpoint.commit()
def restore(self, context, restore, restore_auth): LOG.info("Starting restore service:restore action") checkpoint_id = restore["checkpoint_id"] provider_id = restore["provider_id"] provider = self.provider_registry.show_provider(provider_id) if not provider: raise exception.ProviderNotFound(provider_id=provider_id) self.validate_restore_parameters(restore, provider) checkpoint_collection = provider.get_checkpoint_collection() checkpoint = checkpoint_collection.get(checkpoint_id) if not context.is_admin and (checkpoint.project_id != context.project_id): raise exception.AccessCheckpointNotAllowed( checkpoint_id=checkpoint_id) if checkpoint.status != constants.CHECKPOINT_STATUS_AVAILABLE: raise exception.CheckpointNotAvailable(checkpoint_id=checkpoint_id) try: flow = self.worker.get_flow( context=context, operation_type=constants.OPERATION_RESTORE, checkpoint=checkpoint, provider=provider, restore=restore, restore_auth=restore_auth) except Exception: LOG.exception("Failed to create restore flow checkpoint: %s", checkpoint_id) raise exception.FlowError(flow="restore", error=_("Failed to create flow")) self._spawn(self.worker.run_flow, flow)