示例#1
0
    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)
示例#2
0
    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()