Exceptions cleanup

Ensure that the quantum exceptions in FAULT_MAP are grouped
together (this will save endless bug fixes when the server
will return 500 instead of 4xx)

Change-Id: I89581e1b6b4af3eb1803d6226686adf0b576d1e7
This commit is contained in:
Gary Kotton 2012-12-30 13:50:10 +00:00
parent f28eee8f51
commit 922aefc0bb
5 changed files with 30 additions and 44 deletions

View File

@ -29,27 +29,14 @@ LOG = logging.getLogger(__name__)
XML_NS_V20 = 'http://openstack.org/quantum/api/v2.0'
FAULT_MAP = {exceptions.NotFound: webob.exc.HTTPNotFound,
exceptions.InUse: webob.exc.HTTPConflict,
exceptions.Conflict: webob.exc.HTTPConflict,
exceptions.InUse: webob.exc.HTTPConflict,
exceptions.BadRequest: webob.exc.HTTPBadRequest,
exceptions.ResourceExhausted: webob.exc.HTTPServiceUnavailable,
exceptions.MacAddressGenerationFailure:
webob.exc.HTTPServiceUnavailable,
exceptions.StateInvalid: webob.exc.HTTPBadRequest,
exceptions.InvalidInput: webob.exc.HTTPBadRequest,
exceptions.OverlappingAllocationPools: webob.exc.HTTPConflict,
exceptions.OutOfBoundsAllocationPool: webob.exc.HTTPBadRequest,
exceptions.InvalidAllocationPool: webob.exc.HTTPBadRequest,
exceptions.InvalidSharedSetting: webob.exc.HTTPConflict,
exceptions.HostRoutesExhausted: webob.exc.HTTPBadRequest,
exceptions.DNSNameServersExhausted: webob.exc.HTTPBadRequest,
# Some plugins enforce policies as well
exceptions.PolicyNotAuthorized: webob.exc.HTTPForbidden,
exceptions.ServiceUnavailable: webob.exc.HTTPServiceUnavailable,
exceptions.NotAuthorized: webob.exc.HTTPForbidden,
netaddr.AddrFormatError: webob.exc.HTTPBadRequest,
AttributeError: webob.exc.HTTPBadRequest,
ValueError: webob.exc.HTTPBadRequest,
exceptions.IpAddressGenerationFailure: webob.exc.HTTPConflict,
exceptions.OverQuota: webob.exc.HTTPConflict,
}
QUOTAS = quota.QUOTAS

View File

@ -50,6 +50,10 @@ class NotAuthorized(QuantumException):
message = _("Not authorized.")
class ServiceUnavailable(QuantumException):
message = _("The service is unailable")
class AdminRequired(NotAuthorized):
message = _("User does not have admin privileges: %(reason)s")
@ -79,7 +83,7 @@ class PolicyNotFound(NotFound):
message = _("Policy configuration policy.json could not be found")
class StateInvalid(QuantumException):
class StateInvalid(BadRequest):
message = _("Unsupported port state: %(port_state)s")
@ -108,13 +112,13 @@ class MacAddressInUse(InUse):
"The mac address %(mac)s is in use.")
class HostRoutesExhausted(QuantumException):
class HostRoutesExhausted(BadRequest):
# NOTE(xchenum): probably make sense to use quota exceeded exception?
message = _("Unable to complete operation for %(subnet_id)s. "
"The number of host routes exceeds the limit %(quota)s.")
class DNSNameServersExhausted(QuantumException):
class DNSNameServersExhausted(BadRequest):
# NOTE(xchenum): probably make sense to use quota exceeded exception?
message = _("Unable to complete operation for %(subnet_id)s. "
"The number of DNS nameservers exceeds the limit %(quota)s.")
@ -141,11 +145,11 @@ class TunnelIdInUse(InUse):
"The tunnel ID %(tunnel_id)s is in use.")
class TenantNetworksDisabled(QuantumException):
class TenantNetworksDisabled(ServiceUnavailable):
message = _("Tenant network creation is not enabled.")
class ResourceExhausted(QuantumException):
class ResourceExhausted(ServiceUnavailable):
pass
@ -154,7 +158,7 @@ class NoNetworkAvailable(ResourceExhausted):
"No tenant network is available for allocation.")
class AlreadyAttached(QuantumException):
class AlreadyAttached(Conflict):
message = _("Unable to plug the attachment %(att_id)s into port "
"%(port_id)s for network %(net_id)s. The attachment is "
"already plugged into port %(att_port_id)s")
@ -165,7 +169,7 @@ class SubnetMismatchForPort(Conflict):
"the requested subnet %(subnet_id)s")
class MalformedRequestBody(QuantumException):
class MalformedRequestBody(BadRequest):
message = _("Malformed request body: %(reason)s")
@ -173,7 +177,7 @@ class Invalid(Error):
pass
class InvalidInput(QuantumException):
class InvalidInput(BadRequest):
message = _("Invalid input for operation: %(error_message)s.")
@ -181,16 +185,16 @@ class InvalidContentType(Invalid):
message = _("Invalid content type %(content_type)s.")
class InvalidAllocationPool(QuantumException):
class InvalidAllocationPool(BadRequest):
message = _("The allocation pool %(pool)s is not valid.")
class OverlappingAllocationPools(QuantumException):
class OverlappingAllocationPools(Conflict):
message = _("Found overlapping allocation pools:"
"%(pool_1)s %(pool_2)s for subnet %(subnet_cidr)s.")
class OutOfBoundsAllocationPool(QuantumException):
class OutOfBoundsAllocationPool(BadRequest):
message = _("The allocation pool %(pool)s spans "
"beyond the subnet cidr %(subnet_cidr)s.")
@ -199,16 +203,11 @@ class NotImplementedError(Error):
pass
class FixedIPNotAvailable(QuantumException):
message = _("Fixed IP (%(ip)s) unavailable for network "
"%(network_uuid)s")
class MacAddressGenerationFailure(QuantumException):
class MacAddressGenerationFailure(ServiceUnavailable):
message = _("Unable to generate unique mac on network %(net_id)s.")
class IpAddressGenerationFailure(QuantumException):
class IpAddressGenerationFailure(Conflict):
message = _("No more IP addresses available on network %(net_id)s.")
@ -224,25 +223,25 @@ class SudoRequired(QuantumException):
message = _("Sudo priviledge is required to run this command.")
class QuotaResourceUnknown(QuantumException):
class QuotaResourceUnknown(NotFound):
message = _("Unknown quota resources %(unknown)s.")
class OverQuota(QuantumException):
class OverQuota(Conflict):
message = _("Quota exceeded for resources: %(overs)s")
class InvalidQuotaValue(QuantumException):
class InvalidQuotaValue(Conflict):
message = _("Change would make usage less than 0 for the following "
"resources: %(unders)s")
class InvalidSharedSetting(QuantumException):
class InvalidSharedSetting(Conflict):
message = _("Unable to reconfigure sharing settings for network "
"%(network)s. Multiple tenants are using it")
class InvalidExtenstionEnv(QuantumException):
class InvalidExtenstionEnv(BadRequest):
message = _("Invalid extension environment: %(reason)s")

View File

@ -104,7 +104,7 @@ class SecurityGroupNotProxyMode(qexception.InUse):
message = _("Recieve external id and not in proxy mode")
class SecurityGroupProxyModeNotAdmin(qexception.InvalidExtenstionEnv):
class SecurityGroupProxyModeNotAdmin(qexception.NotAuthorized):
message = _("In Proxy Mode and not from admin")

View File

@ -171,8 +171,8 @@ class TunnelKey(object):
count += 1
if count > self._TRANSACTION_RETRY_MAX:
# if this happens too often, increase _TRANSACTION_RETRY_MAX
LOG.warn(_("Transaction retry reaches to %d. "
"abandan to allocate tunnel key."), count)
LOG.warn(_("Transaction retry exhausted (%d). "
"Abandoned tunnel key allocation."), count)
raise q_exc.ResourceExhausted()
return new_key

View File

@ -240,7 +240,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
tenant_id='bad_tenant',
set_context=True)
self.deserialize('json', res)
self.assertEqual(res.status_int, 500)
self.assertEqual(res.status_int, 403)
def test_create_security_group_no_external_id_proxy_mode(self):
cfg.CONF.SECURITYGROUP.proxy_mode = True
@ -463,7 +463,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
tenant_id='bad_tenant',
set_context=True)
self.deserialize('json', res)
self.assertEqual(res.status_int, 500)
self.assertEqual(res.status_int, 403)
def test_create_security_group_rule_bad_tenant_source_group_id(self):
with self.security_group() as sg: