~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/exception.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
"""
26
26
 
27
27
import functools
28
 
import sys
 
28
import itertools
29
29
 
30
 
import novaclient.exceptions
31
30
import webob.exc
32
31
 
33
32
from nova import log as logging
 
33
from nova.openstack.common import excutils
34
34
 
35
35
LOG = logging.getLogger(__name__)
36
36
 
62
62
        IOError.__init__(self, message)
63
63
 
64
64
 
65
 
class Error(Exception):
66
 
    pass
67
 
 
68
 
 
69
 
class EC2APIError(Error):
70
 
    def __init__(self, message='Unknown', code=None):
71
 
        self.msg = message
72
 
        self.code = code
73
 
        if code:
74
 
            outstr = '%s: %s' % (code, message)
75
 
        else:
76
 
            outstr = '%s' % message
77
 
        super(EC2APIError, self).__init__(outstr)
78
 
 
79
 
 
80
 
class DBError(Error):
81
 
    """Wraps an implementation specific exception."""
82
 
    def __init__(self, inner_exception=None):
83
 
        self.inner_exception = inner_exception
84
 
        super(DBError, self).__init__(str(inner_exception))
85
 
 
86
 
 
87
65
def wrap_db_error(f):
88
66
    def _wrap(*args, **kwargs):
89
67
        try:
113
91
            try:
114
92
                return f(*args, **kw)
115
93
            except Exception, e:
116
 
                # Save exception since it can be clobbered during processing
117
 
                # below before we can re-raise
118
 
                exc_info = sys.exc_info()
119
 
 
120
 
                if notifier:
121
 
                    payload = dict(args=args, exception=e)
122
 
                    payload.update(kw)
123
 
 
124
 
                    # Use a temp vars so we don't shadow
125
 
                    # our outer definitions.
126
 
                    temp_level = level
127
 
                    if not temp_level:
128
 
                        temp_level = notifier.ERROR
129
 
 
130
 
                    temp_type = event_type
131
 
                    if not temp_type:
132
 
                        # If f has multiple decorators, they must use
133
 
                        # functools.wraps to ensure the name is
134
 
                        # propagated.
135
 
                        temp_type = f.__name__
136
 
 
137
 
                    notifier.notify(publisher_id, temp_type, temp_level,
138
 
                                    payload)
139
 
 
140
 
                # re-raise original exception since it may have been clobbered
141
 
                raise exc_info[0], exc_info[1], exc_info[2]
 
94
                with excutils.save_and_reraise_exception():
 
95
                    if notifier:
 
96
                        payload = dict(args=args, exception=e)
 
97
                        payload.update(kw)
 
98
 
 
99
                        # Use a temp vars so we don't shadow
 
100
                        # our outer definitions.
 
101
                        temp_level = level
 
102
                        if not temp_level:
 
103
                            temp_level = notifier.ERROR
 
104
 
 
105
                        temp_type = event_type
 
106
                        if not temp_type:
 
107
                            # If f has multiple decorators, they must use
 
108
                            # functools.wraps to ensure the name is
 
109
                            # propagated.
 
110
                            temp_type = f.__name__
 
111
 
 
112
                        context = get_context_from_function_and_args(f,
 
113
                                                                     args,
 
114
                                                                     kw)
 
115
 
 
116
                        notifier.notify(context, publisher_id, temp_type,
 
117
                                        temp_level, payload)
142
118
 
143
119
        return functools.wraps(f)(wrapped)
144
120
    return inner
168
144
                message = self.message % kwargs
169
145
 
170
146
            except Exception as e:
 
147
                # kwargs doesn't match a variable in the message
 
148
                # log the issue and the kwargs
 
149
                LOG.exception(_('Exception in string format operation'))
 
150
                for name, value in kwargs.iteritems():
 
151
                    LOG.error("%s: %s" % (name, value))
171
152
                # at least get the core message out if something happened
172
153
                message = self.message
173
154
 
174
155
        super(NovaException, self).__init__(message)
175
156
 
176
157
 
 
158
class EC2APIError(NovaException):
 
159
    message = _("Unknown")
 
160
 
 
161
    def __init__(self, message=None, code=None):
 
162
        self.msg = message
 
163
        self.code = code
 
164
        if code:
 
165
            outstr = '%s: %s' % (code, message)
 
166
        else:
 
167
            outstr = '%s' % message
 
168
        super(EC2APIError, self).__init__(outstr)
 
169
 
 
170
 
 
171
class DBError(NovaException):
 
172
    """Wraps an implementation specific exception."""
 
173
    def __init__(self, inner_exception=None):
 
174
        self.inner_exception = inner_exception
 
175
        super(DBError, self).__init__(str(inner_exception))
 
176
 
 
177
 
177
178
class DecryptionFailure(NovaException):
178
179
    message = _("Failed to decrypt text")
179
180
 
261
262
    message = _("Invalid volume") + ": %(reason)s"
262
263
 
263
264
 
 
265
class InvalidMetadata(Invalid):
 
266
    message = _("Invalid metadata") + ": %(reason)s"
 
267
 
 
268
 
264
269
class InvalidPortRange(Invalid):
265
270
    message = _("Invalid port range %(from_port)s:%(to_port)s. %(msg)s")
266
271
 
277
282
    message = _("Invalid cidr %(cidr)s.")
278
283
 
279
284
 
280
 
class InvalidRPCConnectionReuse(Invalid):
281
 
    message = _("Invalid reuse of an RPC connection.")
282
 
 
283
 
 
284
285
class InvalidUnicodeParameter(Invalid):
285
286
    message = _("Invalid Parameter: "
286
287
                "Unicode is not supported by the current database.")
338
339
    message = _("Service is unavailable at this time.")
339
340
 
340
341
 
341
 
class VolumeServiceUnavailable(ServiceUnavailable):
342
 
    message = _("Volume service is unavailable at this time.")
343
 
 
344
 
 
345
342
class ComputeServiceUnavailable(ServiceUnavailable):
346
343
    message = _("Compute service is unavailable at this time.")
347
344
 
418
415
    message = _("Ec2 id %(ec2_id)s is unacceptable.")
419
416
 
420
417
 
 
418
class InvalidUUID(Invalid):
 
419
    message = _("Expected a uuid but received %(uuid).")
 
420
 
 
421
 
421
422
class NotFound(NovaException):
422
423
    message = _("Resource could not be found.")
423
424
    code = 404
494
495
 
495
496
class ListingImageRefsNotSupported(Invalid):
496
497
    message = _("Some images have been stored via hrefs."
497
 
        + " This version of the api does not support displaying image hrefs.")
 
498
          " This version of the api does not support displaying image hrefs.")
498
499
 
499
500
 
500
501
class ImageNotFound(NotFound):
525
526
    message = _("Cannot find SR to read/write VDI.")
526
527
 
527
528
 
 
529
class NetworkInUse(NovaException):
 
530
    message = _("Network %(network_id)s is still in use.")
 
531
 
 
532
 
528
533
class NetworkNotCreated(NovaException):
529
534
    message = _("%(req)s is required to create a network.")
530
535
 
684
689
    message = _("Access Key %(access_key)s could not be found.")
685
690
 
686
691
 
 
692
class InvalidReservationExpiration(Invalid):
 
693
    message = _("Invalid reservation expiration %(expire)s.")
 
694
 
 
695
 
 
696
class InvalidQuotaValue(Invalid):
 
697
    message = _("Change would make usage less than 0 for the following "
 
698
                "resources: %(unders)s")
 
699
 
 
700
 
687
701
class QuotaNotFound(NotFound):
688
702
    message = _("Quota could not be found")
689
703
 
690
704
 
 
705
class QuotaResourceUnknown(QuotaNotFound):
 
706
    message = _("Unknown quota resources %(unknown)s.")
 
707
 
 
708
 
691
709
class ProjectQuotaNotFound(QuotaNotFound):
692
710
    message = _("Quota for project %(project_id)s could not be found.")
693
711
 
694
712
 
 
713
class QuotaClassNotFound(QuotaNotFound):
 
714
    message = _("Quota class %(class_name)s could not be found.")
 
715
 
 
716
 
 
717
class QuotaUsageNotFound(QuotaNotFound):
 
718
    message = _("Quota usage for project %(project_id)s could not be found.")
 
719
 
 
720
 
 
721
class ReservationNotFound(QuotaNotFound):
 
722
    message = _("Quota reservation %(uuid)s could not be found.")
 
723
 
 
724
 
 
725
class OverQuota(NovaException):
 
726
    message = _("Quota exceeded for resources: %(overs)s")
 
727
 
 
728
 
695
729
class SecurityGroupNotFound(NotFound):
696
730
    message = _("Security group %(security_group_id)s not found.")
697
731
 
790
824
                "key %(metadata_key)s.")
791
825
 
792
826
 
 
827
class InstanceSystemMetadataNotFound(NotFound):
 
828
    message = _("Instance %(instance_uuid)s has no system metadata with "
 
829
                "key %(metadata_key)s.")
 
830
 
 
831
 
793
832
class InstanceTypeExtraSpecsNotFound(NotFound):
794
833
    message = _("Instance Type %(instance_type_id)s has no extra specs with "
795
834
                "key %(extra_specs_key)s.")
950
989
    message = _("Quota exceeded") + ": code=%(code)s"
951
990
 
952
991
 
 
992
class TooManyInstances(QuotaError):
 
993
    message = _("Quota exceeded: already used %(used)d of %(allowed)d"
 
994
                " instances")
 
995
 
 
996
 
 
997
class VolumeSizeTooLarge(QuotaError):
 
998
    message = _("Maximum volume size exceeded")
 
999
 
 
1000
 
 
1001
class MetadataLimitExceeded(QuotaError):
 
1002
    message = _("Maximum number of metadata items exceeds %(allowed)d")
 
1003
 
 
1004
 
 
1005
class OnsetFileLimitExceeded(QuotaError):
 
1006
    message = _("Personality file limit exceeded")
 
1007
 
 
1008
 
 
1009
class OnsetFilePathLimitExceeded(QuotaError):
 
1010
    message = _("Personality file path too long")
 
1011
 
 
1012
 
 
1013
class OnsetFileContentLimitExceeded(QuotaError):
 
1014
    message = _("Personality file content too long")
 
1015
 
 
1016
 
 
1017
class KeypairLimitExceeded(QuotaError):
 
1018
    message = _("Maximum number of key pairs exceeded")
 
1019
 
 
1020
 
953
1021
class AggregateError(NovaException):
954
1022
    message = _("Aggregate %(aggregate_id)s: action '%(action)s' "
955
1023
                "caused an error: %(reason)s.")
1019
1087
 
1020
1088
class CouldNotFetchImage(NovaException):
1021
1089
    message = _("Could not fetch image %(image)s")
 
1090
 
 
1091
 
 
1092
def get_context_from_function_and_args(function, args, kwargs):
 
1093
    """Find an arg of type RequestContext and return it.
 
1094
 
 
1095
       This is useful in a couple of decorators where we don't
 
1096
       know much about the function we're wrapping.
 
1097
    """
 
1098
 
 
1099
    # import here to avoid circularity:
 
1100
    from nova import context
 
1101
 
 
1102
    for arg in itertools.chain(kwargs.values(), args):
 
1103
        if isinstance(arg, context.RequestContext):
 
1104
            return arg
 
1105
 
 
1106
    return None