当前位置: 首页>>代码示例>>Python>>正文


Python webob.exc方法代码示例

本文整理汇总了Python中webob.exc方法的典型用法代码示例。如果您正苦于以下问题:Python webob.exc方法的具体用法?Python webob.exc怎么用?Python webob.exc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob的用法示例。


在下文中一共展示了webob.exc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __exit__

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def __exit__(self, ex_type, ex_value, ex_traceback):
        if not ex_value:
            return True

        if isinstance(ex_value, exception.NotAuthorized):
            raise Fault(webob.exc.HTTPForbidden(explanation=ex_value.msg))
        elif isinstance(ex_value, exception.Invalid):
            raise Fault(exception.ConvertedException(
                code=ex_value.code, explanation=ex_value.msg))
        elif isinstance(ex_value, TypeError):
            exc_info = (ex_type, ex_value, ex_traceback)
            LOG.error(_LE(
                'Exception handling resource: %s'),
                ex_value, exc_info=exc_info)
            raise Fault(webob.exc.HTTPBadRequest())
        elif isinstance(ex_value, Fault):
            LOG.info(_LI("Fault thrown: %s"), ex_value)
            raise ex_value
        elif isinstance(ex_value, webob.exc.HTTPException):
            LOG.info(_LI("HTTP exception thrown: %s"), ex_value)
            raise Fault(ex_value)

        # We didn't handle the exception
        return False 
开发者ID:cloudbase,项目名称:vdi-broker,代码行数:26,代码来源:wsgi.py

示例2: validate_name_and_description

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def validate_name_and_description(body):
        name = body.get('name')
        if name is not None:
            if isinstance(name, six.string_types):
                body['name'] = name.strip()
            try:
                _check_string_length(body['name'], 'Name',
                                     min_length=0, max_length=255)
            except exception.InvalidInput as error:
                raise webob.exc.HTTPBadRequest(explanation=error.msg)

        description = body.get('description')
        if description is not None:
            try:
                _check_string_length(description, 'Description',
                                     min_length=0, max_length=255)
            except exception.InvalidInput as error:
                raise webob.exc.HTTPBadRequest(explanation=error.msg) 
开发者ID:cloudbase,项目名称:vdi-broker,代码行数:20,代码来源:wsgi.py

示例3: validate_string_length

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def validate_string_length(value, entity_name, min_length=0,
                               max_length=None, remove_whitespaces=False):
        """Check the length of specified string.

        :param value: the value of the string
        :param entity_name: the name of the string
        :param min_length: the min_length of the string
        :param max_length: the max_length of the string
        :param remove_whitespaces: True if trimming whitespaces is needed
                                   else False
        """
        if isinstance(value, six.string_types) and remove_whitespaces:
            value = value.strip()
        try:
            _check_string_length(value, entity_name,
                                 min_length=min_length,
                                 max_length=max_length)
        except exception.InvalidInput as error:
            raise webob.exc.HTTPBadRequest(explanation=error.msg) 
开发者ID:cloudbase,项目名称:vdi-broker,代码行数:21,代码来源:wsgi.py

示例4: _dispatch

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def _dispatch(req):
        """
        Called by self._router after matching the incoming request to a route
        and putting the information into req.environ.  Either returns 404,
        501, or the routed WSGI app's response.
        """
        match = req.environ['wsgiorg.routing_args'][1]
        if not match:
            implemented_http_methods = ['GET', 'HEAD', 'POST', 'PUT',
                                        'DELETE', 'PATCH']
            if req.environ['REQUEST_METHOD'] not in implemented_http_methods:
                return webob.exc.HTTPNotImplemented()
            else:
                return webob.exc.HTTPNotFound()
        app = match['controller']
        return app 
开发者ID:openstack,项目名称:searchlight,代码行数:18,代码来源:wsgi.py

示例5: test__revert_not_supported

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test__revert_not_supported(self):

        share = copy.deepcopy(self.share)
        share['revert_to_snapshot_support'] = False
        share = fake_share.fake_share(**share)
        snapshot = copy.deepcopy(self.snapshot)
        snapshot['status'] = constants.STATUS_AVAILABLE
        snapshot['share_id'] = 'wrong_id'
        body = {'revert': {'snapshot_id': '2'}}
        req = fakes.HTTPRequest.blank(
            '/shares/1/action', use_admin_context=False, version='2.27')
        self.mock_object(
            self.controller, '_validate_revert_parameters',
            mock.Mock(return_value=body['revert']))
        self.mock_object(share_api.API, 'get', mock.Mock(return_value=share))
        self.mock_object(
            share_api.API, 'get_snapshot', mock.Mock(return_value=snapshot))

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._revert,
                          req,
                          '1',
                          body=body) 
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:test_shares.py

示例6: test__revert_id_mismatch

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test__revert_id_mismatch(self):

        share = copy.deepcopy(self.share)
        share['status'] = constants.STATUS_AVAILABLE
        share['revert_to_snapshot_support'] = True
        share = fake_share.fake_share(**share)
        snapshot = copy.deepcopy(self.snapshot)
        snapshot['status'] = constants.STATUS_AVAILABLE
        snapshot['share_id'] = 'wrong_id'
        body = {'revert': {'snapshot_id': '2'}}
        req = fakes.HTTPRequest.blank(
            '/shares/1/action', use_admin_context=False, version='2.27')
        self.mock_object(
            self.controller, '_validate_revert_parameters',
            mock.Mock(return_value=body['revert']))
        self.mock_object(share_api.API, 'get', mock.Mock(return_value=share))
        self.mock_object(
            share_api.API, 'get_snapshot', mock.Mock(return_value=snapshot))

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._revert,
                          req,
                          '1',
                          body=body) 
开发者ID:openstack,项目名称:manila,代码行数:26,代码来源:test_shares.py

示例7: test__revert_invalid_status

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test__revert_invalid_status(self, share_status, share_is_busy,
                                    snapshot_status):

        share = copy.deepcopy(self.share)
        share['status'] = share_status
        share['is_busy'] = share_is_busy
        share['revert_to_snapshot_support'] = True
        share = fake_share.fake_share(**share)
        snapshot = copy.deepcopy(self.snapshot)
        snapshot['status'] = snapshot_status
        body = {'revert': {'snapshot_id': '2'}}
        req = fakes.HTTPRequest.blank(
            '/shares/1/action', use_admin_context=False, version='2.27')
        self.mock_object(
            self.controller, '_validate_revert_parameters',
            mock.Mock(return_value=body['revert']))
        self.mock_object(share_api.API, 'get', mock.Mock(return_value=share))
        self.mock_object(
            share_api.API, 'get_snapshot', mock.Mock(return_value=snapshot))

        self.assertRaises(webob.exc.HTTPConflict,
                          self.controller._revert,
                          req,
                          '1',
                          body=body) 
开发者ID:openstack,项目名称:manila,代码行数:27,代码来源:test_shares.py

示例8: test_share_create_with_nonexistent_share_group

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_share_create_with_nonexistent_share_group(self):
        sg_id = 'fake_sg_id'
        self.mock_object(share_api.API, 'create', self.create_mock)
        self.mock_object(db, 'availability_zone_get')
        self.mock_object(
            db, 'share_group_get',
            mock.Mock(side_effect=exception.ShareGroupNotFound(
                share_group_id=sg_id)))
        body = {"share": {
            "size": 100,
            "share_proto": "fakeproto",
            "share_group_id": sg_id,
        }}
        req = fakes.HTTPRequest.blank(
            '/shares', version="2.31", experimental=True)

        self.assertRaises(
            webob.exc.HTTPNotFound, self.controller.create, req, body)

        self.assertEqual(0, db.availability_zone_get.call_count)
        self.assertEqual(0, share_api.API.create.call_count)
        db.share_group_get.assert_called_once_with(
            req.environ['manila.context'], sg_id) 
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:test_shares.py

示例9: test_share_create_az_not_in_share_type

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_share_create_az_not_in_share_type(self, version, snap):
        """For API version>=2.48, AZ validation should be performed."""
        self.mock_object(share_api.API, 'create', self.create_mock)
        create_args = copy.deepcopy(self.share)
        create_args['availability_zone'] = 'az2'
        create_args['share_type'] = (uuidutils.generate_uuid() if not snap
                                     else None)
        create_args['snapshot_id'] = (uuidutils.generate_uuid() if snap
                                      else None)
        stype_with_azs = copy.deepcopy(self.vt)
        stype_with_azs['extra_specs']['availability_zones'] = 'az1 , az3'
        self.mock_object(share_types, 'get_share_type', mock.Mock(
            return_value=stype_with_azs))
        self.mock_object(share_api.API, 'get_snapshot',
                         stubs.stub_snapshot_get)

        req = fakes.HTTPRequest.blank('/shares', version=version)

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create,
                          req, {'share': create_args})
        share_api.API.create.assert_not_called() 
开发者ID:openstack,项目名称:manila,代码行数:24,代码来源:test_shares.py

示例10: test_migration_start_conflict

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_migration_start_conflict(self):
        share = db_utils.create_share()
        req = fakes.HTTPRequest.blank('/shares/%s/action' % share['id'],
                                      use_admin_context=True)
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.api_version_request = api_version.APIVersionRequest('2.29')
        req.api_version_request.experimental = True

        body = {
            'migration_start': {
                'host': 'fake_host',
                'preserve_metadata': True,
                'preserve_snapshots': True,
                'writable': True,
                'nondisruptive': True,
            }
        }

        self.mock_object(share_api.API, 'migration_start',
                         mock.Mock(side_effect=exception.Conflict(err='err')))

        self.assertRaises(webob.exc.HTTPConflict,
                          self.controller.migration_start,
                          req, share['id'], body) 
开发者ID:openstack,项目名称:manila,代码行数:27,代码来源:test_shares.py

示例11: test_migration_start_new_share_network_not_found

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_migration_start_new_share_network_not_found(self):
        share = db_utils.create_share()
        req = fakes.HTTPRequest.blank('/shares/%s/action' % share['id'],
                                      use_admin_context=True, version='2.29')
        context = req.environ['manila.context']
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.api_version_request.experimental = True

        body = {
            'migration_start': {
                'host': 'fake_host',
                'preserve_metadata': True,
                'preserve_snapshots': True,
                'writable': True,
                'nondisruptive': True,
                'new_share_network_id': 'nonexistent'}}

        self.mock_object(db, 'share_network_get',
                         mock.Mock(side_effect=exception.NotFound()))
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.migration_start,
                          req, share['id'], body)
        db.share_network_get.assert_called_once_with(context, 'nonexistent') 
开发者ID:openstack,项目名称:manila,代码行数:26,代码来源:test_shares.py

示例12: test_migration_start_new_share_type_not_found

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_migration_start_new_share_type_not_found(self):
        share = db_utils.create_share()
        req = fakes.HTTPRequest.blank('/shares/%s/action' % share['id'],
                                      use_admin_context=True, version='2.29')
        context = req.environ['manila.context']
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.api_version_request.experimental = True

        body = {
            'migration_start': {
                'host': 'fake_host',
                'preserve_metadata': True,
                'preserve_snapshots': True,
                'writable': True,
                'nondisruptive': True,
                'new_share_type_id': 'nonexistent'}}

        self.mock_object(db, 'share_type_get',
                         mock.Mock(side_effect=exception.NotFound()))
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.migration_start,
                          req, share['id'], body)
        db.share_type_get.assert_called_once_with(context, 'nonexistent') 
开发者ID:openstack,项目名称:manila,代码行数:26,代码来源:test_shares.py

示例13: test_reset_task_state_not_found

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_reset_task_state_not_found(self):
        share = db_utils.create_share()
        req = fakes.HTTPRequest.blank('/shares/%s/action' % share['id'],
                                      use_admin_context=True, version='2.22')
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.api_version_request.experimental = True

        update = {'task_state': constants.TASK_STATE_MIGRATION_ERROR}
        body = {'reset_task_state': update}

        self.mock_object(db, 'share_update',
                         mock.Mock(side_effect=exception.NotFound()))

        self.assertRaises(webob.exc.HTTPNotFound,
                          self.controller.reset_task_state, req, share['id'],
                          body)

        db.share_update.assert_called_once_with(utils.IsAMatcher(
            context.RequestContext), share['id'], update) 
开发者ID:openstack,项目名称:manila,代码行数:22,代码来源:test_shares.py

示例14: test_migration_complete_not_found

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_migration_complete_not_found(self):
        share = db_utils.create_share()
        req = fakes.HTTPRequest.blank('/shares/%s/action' % share['id'],
                                      use_admin_context=True, version='2.22')
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.api_version_request.experimental = True

        body = {'migration_complete': None}

        self.mock_object(share_api.API, 'get',
                         mock.Mock(side_effect=exception.NotFound()))
        self.mock_object(share_api.API, 'migration_complete')

        self.assertRaises(webob.exc.HTTPNotFound,
                          self.controller.migration_complete, req, share['id'],
                          body) 
开发者ID:openstack,项目名称:manila,代码行数:19,代码来源:test_shares.py

示例15: test_migration_cancel_not_found

# 需要导入模块: import webob [as 别名]
# 或者: from webob import exc [as 别名]
def test_migration_cancel_not_found(self):
        share = db_utils.create_share()
        req = fakes.HTTPRequest.blank('/shares/%s/action' % share['id'],
                                      use_admin_context=True, version='2.22')
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.api_version_request.experimental = True

        body = {'migration_cancel': None}

        self.mock_object(share_api.API, 'get',
                         mock.Mock(side_effect=exception.NotFound()))
        self.mock_object(share_api.API, 'migration_cancel')

        self.assertRaises(webob.exc.HTTPNotFound,
                          self.controller.migration_cancel, req, share['id'],
                          body) 
开发者ID:openstack,项目名称:manila,代码行数:19,代码来源:test_shares.py


注:本文中的webob.exc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。