1 # Copyright 2010 United States Government as represented by the
2 # Administrator of the National Aeronautics and Space Administration.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
17 """Escalator exception subclasses"""
20 import six.moves.urllib.parse as urlparse
22 from escalator import i18n
26 _FATAL_EXCEPTION_FORMAT_ERRORS = False
29 class RedirectException(Exception):
31 def __init__(self, url):
32 self.url = urlparse.urlparse(url)
35 class EscalatorException(Exception):
37 Base Escalator Exception
39 To correctly use this class, inherit from it and define
40 a 'message' property. That message will get printf'd
41 with the keyword arguments provided to the constructor.
43 message = _("An unknown exception occurred")
45 def __init__(self, message=None, *args, **kwargs):
47 message = self.message
50 message = message % kwargs
52 if _FATAL_EXCEPTION_FORMAT_ERRORS:
55 # at least get the core message out if something happened
58 self.message = message
59 super(EscalatorException, self).__init__(message)
61 def __unicode__(self):
62 # NOTE(flwang): By default, self.msg is an instance of Message, which
63 # can't be converted by str(). Based on the definition of
64 # __unicode__, it should return unicode always.
65 return six.text_type(self.msg)
68 class MissingCredentialError(EscalatorException):
69 message = _("Missing required credential: %(required)s")
72 class BadAuthStrategy(EscalatorException):
73 message = _("Incorrect auth strategy, expected \"%(expected)s\" but "
74 "received \"%(received)s\"")
77 class NotFound(EscalatorException):
78 message = _("An object with the specified identifier was not found.")
81 class BadStoreUri(EscalatorException):
82 message = _("The Store URI was malformed.")
85 class Duplicate(EscalatorException):
86 message = _("An object with the same identifier already exists.")
89 class Conflict(EscalatorException):
90 message = _("An object with the same identifier is currently being "
94 class AuthBadRequest(EscalatorException):
95 message = _("Connect error/bad request to Auth service at URL %(url)s.")
98 class AuthUrlNotFound(EscalatorException):
99 message = _("Auth service at URL %(url)s not found.")
102 class AuthorizationFailure(EscalatorException):
103 message = _("Authorization failed.")
106 class NotAuthenticated(EscalatorException):
107 message = _("You are not authenticated.")
110 class Forbidden(EscalatorException):
111 message = _("You are not authorized to complete this action.")
114 class ProtectedMetadefNamespaceDelete(Forbidden):
115 message = _("Metadata definition namespace %(namespace)s is protected"
116 " and cannot be deleted.")
119 class ProtectedMetadefNamespacePropDelete(Forbidden):
120 message = _("Metadata definition property %(property_name)s is protected"
121 " and cannot be deleted.")
124 class ProtectedMetadefObjectDelete(Forbidden):
125 message = _("Metadata definition object %(object_name)s is protected"
126 " and cannot be deleted.")
129 class ProtectedMetadefResourceTypeAssociationDelete(Forbidden):
130 message = _("Metadata definition resource-type-association"
131 " %(resource_type)s is protected and cannot be deleted.")
134 class ProtectedMetadefResourceTypeSystemDelete(Forbidden):
135 message = _("Metadata definition resource-type %(resource_type_name)s is"
136 " a seeded-system type and cannot be deleted.")
139 class ProtectedMetadefTagDelete(Forbidden):
140 message = _("Metadata definition tag %(tag_name)s is protected"
141 " and cannot be deleted.")
144 class Invalid(EscalatorException):
145 message = _("Data supplied was not valid.")
148 class InvalidSortKey(Invalid):
149 message = _("Sort key supplied was not valid.")
152 class InvalidSortDir(Invalid):
153 message = _("Sort direction supplied was not valid.")
156 class InvalidPropertyProtectionConfiguration(Invalid):
157 message = _("Invalid configuration in property protection file.")
160 class InvalidFilterRangeValue(Invalid):
161 message = _("Unable to filter using the specified range.")
164 class InvalidOptionValue(Invalid):
165 message = _("Invalid value for option %(option)s: %(value)s")
168 class ReadonlyProperty(Forbidden):
169 message = _("Attribute '%(property)s' is read-only.")
172 class ReservedProperty(Forbidden):
173 message = _("Attribute '%(property)s' is reserved.")
176 class AuthorizationRedirect(EscalatorException):
177 message = _("Redirecting to %(uri)s for authorization.")
180 class ClientConnectionError(EscalatorException):
181 message = _("There was an error connecting to a server")
184 class ClientConfigurationError(EscalatorException):
185 message = _("There was an error configuring the client.")
188 class MultipleChoices(EscalatorException):
189 message = _("The request returned a 302 Multiple Choices. This generally "
190 "means that you have not included a version indicator in a "
191 "request URI.\n\nThe body of response returned:\n%(body)s")
194 class LimitExceeded(EscalatorException):
195 message = _("The request returned a 413 Request Entity Too Large. This "
196 "generally means that rate limiting or a quota threshold was "
197 "breached.\n\nThe response body:\n%(body)s")
199 def __init__(self, *args, **kwargs):
200 self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
202 super(LimitExceeded, self).__init__(*args, **kwargs)
205 class ServiceUnavailable(EscalatorException):
206 message = _("The request returned 503 Service Unavailable. This "
207 "generally occurs on service overload or other transient "
210 def __init__(self, *args, **kwargs):
211 self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
213 super(ServiceUnavailable, self).__init__(*args, **kwargs)
216 class ServerError(EscalatorException):
217 message = _("The request returned 500 Internal Server Error.")
220 class UnexpectedStatus(EscalatorException):
221 message = _("The request returned an unexpected status: %(status)s."
222 "\n\nThe response body:\n%(body)s")
225 class InvalidContentType(EscalatorException):
226 message = _("Invalid content type %(content_type)s")
229 class BadRegistryConnectionConfiguration(EscalatorException):
230 message = _("Registry was not configured correctly on API server. "
231 "Reason: %(reason)s")
234 class BadDriverConfiguration(EscalatorException):
235 message = _("Driver %(driver_name)s could not be configured correctly. "
236 "Reason: %(reason)s")
239 class MaxRedirectsExceeded(EscalatorException):
240 message = _("Maximum redirects (%(redirects)s) was exceeded.")
243 class InvalidRedirect(EscalatorException):
244 message = _("Received invalid HTTP redirect.")
247 class NoServiceEndpoint(EscalatorException):
248 message = _("Response from Keystone does not contain a Glance endpoint.")
251 class RegionAmbiguity(EscalatorException):
252 message = _("Multiple 'image' service matches for region %(region)s. This "
253 "generally means that a region is required and you have not "
257 class WorkerCreationFailure(EscalatorException):
258 message = _("Server worker creation failed: %(reason)s.")
261 class SchemaLoadError(EscalatorException):
262 message = _("Unable to load schema: %(reason)s")
265 class InvalidObject(EscalatorException):
266 message = _("Provided object does not match schema "
267 "'%(schema)s': %(reason)s")
270 class UnsupportedHeaderFeature(EscalatorException):
271 message = _("Provided header feature is unsupported: %(feature)s")
274 class InUseByStore(EscalatorException):
275 message = _("The image cannot be deleted because it is in use through "
276 "the backend store outside of escalator.")
279 class SIGHUPInterrupt(EscalatorException):
280 message = _("System SIGHUP signal received.")
283 class RPCError(EscalatorException):
284 message = _("%(cls)s exception was raised in the last rpc call: %(val)s")
287 class TaskException(EscalatorException):
288 message = _("An unknown task exception occurred")
291 class BadTaskConfiguration(EscalatorException):
292 message = _("Task was not configured properly")
295 class TaskNotFound(TaskException, NotFound):
296 message = _("Task with the given id %(task_id)s was not found")
299 class InvalidTaskStatus(TaskException, Invalid):
300 message = _("Provided status of task is unsupported: %(status)s")
303 class InvalidTaskType(TaskException, Invalid):
304 message = _("Provided type of task is unsupported: %(type)s")
307 class InvalidTaskStatusTransition(TaskException, Invalid):
308 message = _("Status transition from %(cur_status)s to"
309 " %(new_status)s is not allowed")
312 class DuplicateLocation(Duplicate):
313 message = _("The location %(location)s already exists")
316 class InvalidParameterValue(Invalid):
317 message = _("Invalid value '%(value)s' for parameter '%(param)s': "
321 class MetadefDuplicateNamespace(Duplicate):
322 message = _("The metadata definition namespace=%(namespace_name)s"
326 class MetadefDuplicateObject(Duplicate):
327 message = _("A metadata definition object with name=%(object_name)s"
328 " already exists in namespace=%(namespace_name)s.")
331 class MetadefDuplicateProperty(Duplicate):
332 message = _("A metadata definition property with name=%(property_name)s"
333 " already exists in namespace=%(namespace_name)s.")
336 class MetadefDuplicateResourceType(Duplicate):
337 message = _("A metadata definition resource-type with"
338 " name=%(resource_type_name)s already exists.")
341 class MetadefDuplicateResourceTypeAssociation(Duplicate):
342 message = _("The metadata definition resource-type association of"
343 " resource-type=%(resource_type_name)s to"
344 " namespace=%(namespace_name)s"
348 class MetadefDuplicateTag(Duplicate):
349 message = _("A metadata tag with name=%(name)s"
350 " already exists in namespace=%(namespace_name)s.")
353 class MetadefForbidden(Forbidden):
354 message = _("You are not authorized to complete this action.")
357 class MetadefIntegrityError(Forbidden):
358 message = _("The metadata definition %(record_type)s with"
359 " name=%(record_name)s not deleted."
360 " Other records still refer to it.")
363 class MetadefNamespaceNotFound(NotFound):
364 message = _("Metadata definition namespace=%(namespace_name)s"
368 class MetadefObjectNotFound(NotFound):
369 message = _("The metadata definition object with"
370 " name=%(object_name)s was not found in"
371 " namespace=%(namespace_name)s.")
374 class MetadefPropertyNotFound(NotFound):
375 message = _("The metadata definition property with"
376 " name=%(property_name)s was not found in"
377 " namespace=%(namespace_name)s.")
380 class MetadefResourceTypeNotFound(NotFound):
381 message = _("The metadata definition resource-type with"
382 " name=%(resource_type_name)s, was not found.")
385 class MetadefResourceTypeAssociationNotFound(NotFound):
386 message = _("The metadata definition resource-type association of"
387 " resource-type=%(resource_type_name)s to"
388 " namespace=%(namespace_name)s,"
392 class MetadefTagNotFound(NotFound):
393 message = _("The metadata definition tag with"
394 " name=%(name)s was not found in"
395 " namespace=%(namespace_name)s.")
398 class InvalidVersion(Invalid):
399 message = _("Version is invalid: %(reason)s")
402 class InvalidArtifactTypePropertyDefinition(Invalid):
403 message = _("Invalid property definition")
406 class InvalidArtifactTypeDefinition(Invalid):
407 message = _("Invalid type definition")
410 class InvalidArtifactPropertyValue(Invalid):
411 message = _("Property '%(name)s' may not have value '%(val)s': %(msg)s")
413 def __init__(self, message=None, *args, **kwargs):
414 super(InvalidArtifactPropertyValue, self).__init__(message, *args,
416 self.name = kwargs.get('name')
417 self.value = kwargs.get('val')
420 class ArtifactNotFound(NotFound):
421 message = _("Artifact with id=%(id)s was not found")
424 class ArtifactForbidden(Forbidden):
425 message = _("Artifact with id=%(id)s is not accessible")
428 class ArtifactDuplicateNameTypeVersion(Duplicate):
429 message = _("Artifact with the specified type, name and version"
433 class InvalidArtifactStateTransition(Invalid):
434 message = _("Artifact cannot change state from %(source)s to %(target)s")
437 class ArtifactDuplicateDirectDependency(Duplicate):
438 message = _("Artifact with the specified type, name and version"
439 " already has the direct dependency=%(dep)s")
442 class ArtifactDuplicateTransitiveDependency(Duplicate):
443 message = _("Artifact with the specified type, name and version"
444 " already has the transitive dependency=%(dep)s")
447 class ArtifactUnsupportedPropertyOperator(Invalid):
448 message = _("Operator %(op)s is not supported")
451 class ArtifactUnsupportedShowLevel(Invalid):
452 message = _("Show level %(shl)s is not supported in this operation")
455 class ArtifactPropertyValueNotFound(NotFound):
456 message = _("Property's %(prop)s value has not been found")
459 class ArtifactInvalidProperty(Invalid):
460 message = _("Artifact has no property %(prop)s")
463 class ArtifactInvalidPropertyParameter(Invalid):
464 message = _("Cannot use this parameter with the operator %(op)s")
467 class ArtifactLoadError(EscalatorException):
468 message = _("Cannot load artifact '%(name)s'")
471 class ArtifactNonMatchingTypeName(ArtifactLoadError):
473 "Plugin name '%(plugin)s' should match artifact typename '%(name)s'")
476 class ArtifactPluginNotFound(NotFound):
477 message = _("No plugin for '%(name)s' has been loaded")
480 class UnknownArtifactType(NotFound):
481 message = _("Artifact type with name '%(name)s' and version '%(version)s' "
485 class ArtifactInvalidStateTransition(Invalid):
486 message = _("Artifact state cannot be changed from %(curr)s to %(to)s")
489 class JsonPatchException(EscalatorException):
490 message = _("Invalid jsonpatch request")
493 class InvalidJsonPatchBody(JsonPatchException):
494 message = _("The provided body %(body)s is invalid "
495 "under given schema: %(schema)s")
498 class InvalidJsonPatchPath(JsonPatchException):
499 message = _("The provided path '%(path)s' is invalid: %(explanation)s")
501 def __init__(self, message=None, *args, **kwargs):
502 self.explanation = kwargs.get("explanation")
503 super(InvalidJsonPatchPath, self).__init__(message, *args, **kwargs)
506 class ThreadBinException(EscalatorException):
508 def __init__(self, *args):
509 super(ThreadBinException, self).__init__(*args)
512 class SubprocessCmdFailed(EscalatorException):
513 message = _("suprocess command failed.")
516 class DeleteConstrainted(EscalatorException):
517 message = _("delete is not allowed.")
520 class TrustMeFailed(EscalatorException):
521 message = _("Trust me script failed.")