コード例 #1
0
ファイル: test_utils.py プロジェクト: sebrandon1/neutron
 def test_attach_exc_details_with_dict_interpolation(self):
     e = Exception()
     utils.attach_exc_details(
         e, 'details: %(foo)s, %(bar)s', {'foo': 'foo', 'bar': 'bar'})
     self.assertEqual('details: foo, bar', utils.extract_exc_details(e))
コード例 #2
0
ファイル: test_utils.py プロジェクト: sebrandon1/neutron
 def test_extract_exc_details_no_details_attached(self):
     self.assertIsInstance(
         utils.extract_exc_details(Exception()), six.text_type)
コード例 #3
0
ファイル: test_utils.py プロジェクト: sebrandon1/neutron
 def test_attach_exc_details_with_None_interpolation(self):
     e = Exception()
     utils.attach_exc_details(e, 'details: %s', None)
     self.assertEqual(
         'details: %s' % str(None), utils.extract_exc_details(e))
コード例 #4
0
ファイル: test_utils.py プロジェクト: sebrandon1/neutron
 def test_attach_exc_details_with_multiple_interpolation(self):
     e = Exception()
     utils.attach_exc_details(
         e, 'details: %s, %s', ('foo', 'bar'))
     self.assertEqual('details: foo, bar', utils.extract_exc_details(e))
コード例 #5
0
ファイル: test_utils.py プロジェクト: sebrandon1/neutron
 def test_attach_exc_details(self):
     e = Exception()
     utils.attach_exc_details(e, 'details')
     self.assertEqual('details', utils.extract_exc_details(e))
コード例 #6
0
ファイル: test_utils.py プロジェクト: sebrandon1/neutron
 def test_attach_exc_details_with_interpolation(self):
     e = Exception()
     utils.attach_exc_details(e, 'details: %s', 'foo')
     self.assertEqual('details: foo', utils.extract_exc_details(e))
コード例 #7
0
ファイル: test_utils.py プロジェクト: younkun/neutron
 def test_attach_exc_details_with_interpolation(self):
     e = Exception()
     utils.attach_exc_details(e, 'details: %s', 'foo')
     self.assertEqual('details: foo', utils.extract_exc_details(e))
コード例 #8
0
ファイル: test_utils.py プロジェクト: younkun/neutron
 def test_attach_exc_details_with_None_interpolation(self):
     e = Exception()
     utils.attach_exc_details(e, 'details: %s', None)
     self.assertEqual('details: %s' % str(None),
                      utils.extract_exc_details(e))
コード例 #9
0
ファイル: test_utils.py プロジェクト: williamwang0/MusicGen
 def test_extract_exc_details_no_details_attached(self):
     self.assertIsInstance(utils.extract_exc_details(Exception()),
                           six.text_type)
コード例 #10
0
ファイル: test_utils.py プロジェクト: younkun/neutron
 def test_attach_exc_details(self):
     e = Exception()
     utils.attach_exc_details(e, 'details')
     self.assertEqual('details', utils.extract_exc_details(e))
コード例 #11
0
ファイル: test_utils.py プロジェクト: williamwang0/MusicGen
 def test_attach_exc_details_with_multiple_interpolation(self):
     e = Exception()
     utils.attach_exc_details(e, 'details: %s, %s', ('foo', 'bar'))
     self.assertEqual('details: foo, bar', utils.extract_exc_details(e))
コード例 #12
0
ファイル: resource.py プロジェクト: cubeek/neutron
    def resource(request):
        route_args = request.environ.get('wsgiorg.routing_args')
        if route_args:
            args = route_args[1].copy()
        else:
            args = {}

        # NOTE(jkoelker) by now the controller is already found, remove
        #                it from the args if it is in the matchdict
        args.pop('controller', None)
        fmt = args.pop('format', None)
        action = args.pop('action', None)
        content_type = format_types.get(fmt,
                                        request.best_match_content_type())
        language = request.best_match_language()
        deserializer = deserializers.get(content_type)
        serializer = serializers.get(content_type)

        try:
            if request.body:
                args['body'] = deserializer.deserialize(request.body)['body']

            # Routes library is dumb and cuts off everything after last dot (.)
            # as format. At the same time, it doesn't enforce format suffix,
            # which combined makes it impossible to pass a 'id' with dots
            # included (the last section after the last dot is lost). This is
            # important for some API extensions like tags where the id is
            # really a tag name that can contain special characters.
            #
            # To work around the Routes behaviour, we will attach the suffix
            # back to id if it's not one of supported formats (atm json only).
            # This of course won't work for the corner case of a tag name that
            # actually ends with '.json', but there seems to be no better way
            # to tackle it without breaking API backwards compatibility.
            if fmt is not None and fmt not in format_types:
                args['id'] = '.'.join([args['id'], fmt])

            revision_number = api_common.check_request_for_revision_constraint(
                request)
            if revision_number is not None:
                request.context.set_transaction_constraint(
                    controller._collection, args['id'], revision_number)

            method = getattr(controller, action)
            result = method(request=request, **args)
        except Exception as e:
            mapped_exc = api_common.convert_exception_to_http_exc(e, faults,
                                                                  language)
            if hasattr(mapped_exc, 'code') and 400 <= mapped_exc.code < 500:
                LOG.info('%(action)s failed (client error): %(exc)s',
                         {'action': action, 'exc': mapped_exc})
            else:
                LOG.exception('%(action)s failed: %(details)s',
                              {
                                  'action': action,
                                  'details': utils.extract_exc_details(e),
                              }
                              )
            raise mapped_exc

        status = action_status.get(action, 200)
        body = serializer.serialize(result)
        # NOTE(jkoelker) Comply with RFC2616 section 9.7
        if status == 204:
            content_type = ''
            body = None

        return webob.Response(request=request, status=status,
                              content_type=content_type,
                              body=body)
コード例 #13
0
    def resource(request):
        route_args = request.environ.get('wsgiorg.routing_args')
        if route_args:
            args = route_args[1].copy()
        else:
            args = {}

        # NOTE(jkoelker) by now the controller is already found, remove
        #                it from the args if it is in the matchdict
        args.pop('controller', None)
        fmt = args.pop('format', None)
        action = args.pop('action', None)
        content_type = format_types.get(fmt, request.best_match_content_type())
        language = request.best_match_language()
        deserializer = deserializers.get(content_type)
        serializer = serializers.get(content_type)

        try:
            if request.body:
                args['body'] = deserializer.deserialize(request.body)['body']

            # Routes library is dumb and cuts off everything after last dot (.)
            # as format. At the same time, it doesn't enforce format suffix,
            # which combined makes it impossible to pass a 'id' with dots
            # included (the last section after the last dot is lost). This is
            # important for some API extensions like tags where the id is
            # really a tag name that can contain special characters.
            #
            # To work around the Routes behaviour, we will attach the suffix
            # back to id if it's not one of supported formats (atm json only).
            # This of course won't work for the corner case of a tag name that
            # actually ends with '.json', but there seems to be no better way
            # to tackle it without breaking API backwards compatibility.
            if fmt is not None and fmt not in format_types:
                args['id'] = '.'.join([args['id'], fmt])

            revision_number = api_common.check_request_for_revision_constraint(
                request)
            if revision_number is not None:
                request.context.set_transaction_constraint(
                    controller._collection, args['id'], revision_number)

            method = getattr(controller, action)
            result = method(request=request, **args)
        except Exception as e:
            mapped_exc = api_common.convert_exception_to_http_exc(
                e, faults, language)
            if hasattr(mapped_exc, 'code') and 400 <= mapped_exc.code < 500:
                LOG.info('%(action)s failed (client error): %(exc)s', {
                    'action': action,
                    'exc': mapped_exc
                })
            else:
                LOG.exception('%(action)s failed: %(details)s', {
                    'action': action,
                    'details': utils.extract_exc_details(e),
                })
            raise mapped_exc

        status = action_status.get(action, 200)
        body = serializer.serialize(result)
        # NOTE(jkoelker) Comply with RFC2616 section 9.7
        if status == 204:
            content_type = ''
            body = None

        return webob.Response(request=request,
                              status=status,
                              content_type=content_type,
                              body=body)
コード例 #14
0
ファイル: test_utils.py プロジェクト: wkite/neutron
 def test_attach_exc_details_with_dict_interpolation(self):
     e = Exception()
     utils.attach_exc_details(
         e, 'details: %(foo)s, %(bar)s', {'foo': 'foo', 'bar': 'bar'})
     self.assertEqual('details: foo, bar', utils.extract_exc_details(e))
コード例 #15
0
ファイル: resource.py プロジェクト: electrocucaracha/neutron
    def resource(request):
        route_args = request.environ.get("wsgiorg.routing_args")
        if route_args:
            args = route_args[1].copy()
        else:
            args = {}

        # NOTE(jkoelker) by now the controller is already found, remove
        #                it from the args if it is in the matchdict
        args.pop("controller", None)
        fmt = args.pop("format", None)
        action = args.pop("action", None)
        content_type = format_types.get(fmt, request.best_match_content_type())
        language = request.best_match_language()
        deserializer = deserializers.get(content_type)
        serializer = serializers.get(content_type)

        try:
            if request.body:
                args["body"] = deserializer.deserialize(request.body)["body"]

            method = getattr(controller, action)

            result = method(request=request, **args)
        except Exception as e:
            mapped_exc = api_common.convert_exception_to_http_exc(e, faults, language)
            if hasattr(mapped_exc, "code") and 400 <= mapped_exc.code < 500:
                LOG.info(_LI("%(action)s failed (client error): %(exc)s"), {"action": action, "exc": mapped_exc})
            else:
                LOG.exception(
                    _LE("%(action)s failed: %(details)s"), {"action": action, "details": utils.extract_exc_details(e)}
                )
            raise mapped_exc

        status = action_status.get(action, 200)
        body = serializer.serialize(result)
        # NOTE(jkoelker) Comply with RFC2616 section 9.7
        if status == 204:
            content_type = ""
            body = None

        return webob.Response(request=request, status=status, content_type=content_type, body=body)