Exemplo n.º 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)
Exemplo n.º 2
0
 def test_show_checkpoint_not_found(self, mock_provider,
                                    mock_cp_collection_get):
     mock_provider.return_value = fakes.FakeProvider()
     context = mock.MagicMock()
     mock_cp_collection_get.side_effect = exception.CheckpointNotFound()
     self.assertRaises(oslo_messaging.ExpectedException,
                       self.pro_manager.show_checkpoint, context,
                       'provider1', 'non_existent_checkpoint')
Exemplo n.º 3
0
 def reload_meta_data(self):
     try:
         new_md = self._checkpoint_section.get_object(_INDEX_FILE_NAME)
     except exception.BankGetObjectFailed:
         LOG.error("unable to reload metadata for checkpoint id: %s",
                   self.id)
         raise exception.CheckpointNotFound(checkpoint_id=self.id)
     self._assert_supported_version(new_md)
     self._md_cache = new_md
Exemplo n.º 4
0
    def _checkpoint_get(self, context, provider_id, checkpoint_id):
        if not uuidutils.is_uuid_like(provider_id):
            msg = _("Invalid provider id provided.")
            raise exc.HTTPBadRequest(explanation=msg)

        if not uuidutils.is_uuid_like(checkpoint_id):
            msg = _("Invalid checkpoint id provided.")
            raise exc.HTTPBadRequest(explanation=msg)

        try:
            context.can(provider_policy.CHECKPOINT_GET_POLICY)
        except exception.PolicyNotAuthorized:
            # raise CheckpointNotFound instead to make sure karbor behaves
            # as it used to
            raise exception.CheckpointNotFound(checkpoint_id=checkpoint_id)

        checkpoint = self.protection_api.show_checkpoint(
            context, provider_id, checkpoint_id)

        if checkpoint is None:
            raise exception.CheckpointNotFound(checkpoint_id=checkpoint_id)

        LOG.info("Checkpoint info retrieved successfully.")
        return checkpoint