~ddellav/ubuntu/xenial/manila/manila-share

« back to all changes in this revision

Viewing changes to manila/api/middleware/fault.py

  • Committer: David Della Vecchia
  • Date: 2016-03-08 17:56:43 UTC
  • Revision ID: ddv@canonical.com-20160308175643-jctkndscyn472ck0
* d/control: Include manila-share binary package from debian.
* d/manila-share.init.in: Add manila upstart script. 
* New upstream milestone for OpenStack Mitaka.
* d/control: Align (build-)depends with upstream.
* d/p/doc-conf-git.patch: Drop git commands that fail sphinx-build.
* New upstream milestone for OpenStack Mitaka.
* d/control: Align (build-)depends with upstream.
* New upstream release for OpenStack Liberty.
* New upstream release candidate for OpenStack Liberty.
* d/control: Align dependencies with upstream.
* New upstream release candidate for OpenStack Liberty.
* d/control: Set minimum pbr version at 1.8.
* New upstream release candidate for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* d/watch: Update to cope with upstream rc naming.
* New upstream milestone for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* New upstream milestone for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* d/rules: Remove .eggs directory in override_dh_auto_clean.
* No change rebuild with SQLAlchemy 1.0.6.
* New upstream milestone for OpenStack Liberty.
* Align (build-)depends with upstream.
* Drop all patches, no longer required.
* New upstream release for OpenStack kilo. (LP: #1449744) 
* New upstream milestone release for OpenStack Kilo:
  - d/control: Align dependencies and versions with upstream.
  - debian/patches/pep-0476.patch: Dropped no longer needed.
  - debian/patches/skipped-tests.patch: Skipped failing test.
* New upstream milestone release for OpenStack Kilo:
  - d/control: Align dependencies and versions with upstream.
* New upstream milestone release for OpenStack Kilo:
  - d/control: Align dependencies and versions with upstream.
  - d/p/fixup-test-failure.patch: Align expected string with unicode
    encoded result.
* New upstream milestone release:
  - d/control: Resync dependency versions with upstream.
  - d/control: Version BD on ddt to >= 1.0.0, resolving test failures.
* d/control: Add missing BD on python-testresources.
* d/*: wrap-and-sort.
* New upstream release:
  - d/control: Add new dependencies.
  - Install any new binaries and configuration to common package.
* d/watch: Update to use tarballs.openstack.org.
* d/control,compat: Bump debhelper compat level to 9.
* d/control: Bumped Standards-Version to 3.9.6, no changes.
* Systemd enablement:
  - d/rules,control: Enable use of dh-systemd and openstack-pkg-tools.
  - d/*.init.in: Write templates for generation of init, service and
    upstart configurations.
  - d/*.upstart: Drop in preference to above.
* d/*.logrotate: Move to single logrotate configuration in common package.
* d/rules: Ensure unit test suite failure fails package build.
* d/p/pep-0476.patch: Deal with SSL certification chain verification unit
  test failures.
* Rebuild for sqlalchemy 0.9. 
* Fix dependency typo (pyhon-oslo.config -> python-oslo.config).
* Initial release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 United States Government as represented by the
 
2
# Administrator of the National Aeronautics and Space Administration.
 
3
# All Rights Reserved.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
from oslo_log import log
 
18
import six
 
19
import webob.dec
 
20
import webob.exc
 
21
 
 
22
from manila.api.openstack import wsgi
 
23
from manila.i18n import _LE
 
24
from manila.i18n import _LI
 
25
from manila import utils
 
26
from manila import wsgi as base_wsgi
 
27
 
 
28
LOG = log.getLogger(__name__)
 
29
 
 
30
 
 
31
class FaultWrapper(base_wsgi.Middleware):
 
32
    """Calls down the middleware stack, making exceptions into faults."""
 
33
 
 
34
    _status_to_type = {}
 
35
 
 
36
    @staticmethod
 
37
    def status_to_type(status):
 
38
        if not FaultWrapper._status_to_type:
 
39
            for clazz in utils.walk_class_hierarchy(webob.exc.HTTPError):
 
40
                FaultWrapper._status_to_type[clazz.code] = clazz
 
41
        return FaultWrapper._status_to_type.get(
 
42
            status, webob.exc.HTTPInternalServerError)()
 
43
 
 
44
    def _error(self, inner, req):
 
45
        LOG.exception(_LE("Caught error: %s"), six.text_type(inner))
 
46
 
 
47
        safe = getattr(inner, 'safe', False)
 
48
        headers = getattr(inner, 'headers', None)
 
49
        status = getattr(inner, 'code', 500)
 
50
        if status is None:
 
51
            status = 500
 
52
 
 
53
        msg_dict = dict(url=req.url, status=status)
 
54
        LOG.info(_LI("%(url)s returned with HTTP %(status)d"), msg_dict)
 
55
        outer = self.status_to_type(status)
 
56
        if headers:
 
57
            outer.headers = headers
 
58
        # NOTE(johannes): We leave the explanation empty here on
 
59
        # purpose. It could possibly have sensitive information
 
60
        # that should not be returned back to the user. See
 
61
        # bugs 868360 and 874472
 
62
        # NOTE(eglynn): However, it would be over-conservative and
 
63
        # inconsistent with the EC2 API to hide every exception,
 
64
        # including those that are safe to expose, see bug 1021373
 
65
        if safe:
 
66
            outer.explanation = '%s: %s' % (inner.__class__.__name__,
 
67
                                            six.text_type(inner))
 
68
        return wsgi.Fault(outer)
 
69
 
 
70
    @webob.dec.wsgify(RequestClass=wsgi.Request)
 
71
    def __call__(self, req):
 
72
        try:
 
73
            return req.get_response(self.application)
 
74
        except Exception as ex:
 
75
            return self._error(ex, req)