]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Exceptions cleanup
authorGary Kotton <gkotton@redhat.com>
Sun, 30 Dec 2012 13:50:10 +0000 (13:50 +0000)
committerGary Kotton <gkotton@redhat.com>
Mon, 31 Dec 2012 08:01:52 +0000 (08:01 +0000)
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

quantum/api/v2/base.py
quantum/common/exceptions.py
quantum/extensions/securitygroup.py
quantum/plugins/ryu/db/api_v2.py
quantum/tests/unit/test_extension_security_group.py

index 8a9eb58e6443edd50d347f0a1b3155a7e8834394..d9ab54006b89f033a3fa207e92b7085ac1f8de0d 100644 (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
index ae9c9e3b56541a2abc0624d58566c57932046908..cb6a8da40de3482c21530437939fbf9cfaed7ab4 100644 (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")
 
 
index e47c155fffd95b72e3284e076113c4e905a5be9e..a887da429928882e16e2de4fae21ca2c67a2190d 100644 (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")
 
 
index 18dd465559a9a41cd0380b4ba59b83ecfb9b7184..ca7fd1a037cd9f1ed74fe2fadf76aec992214aa7 100644 (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
index 9d3fa756d1e3d4ec80920a04a95be499be0a5ef7..b71915996d46082904335422d992e63d6bc21328 100644 (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: