]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make SubnetMismatchForPort extend BadRequest rather than Conflict
authorMatt Riedemann <mriedem@us.ibm.com>
Thu, 8 Aug 2013 19:33:10 +0000 (12:33 -0700)
committerMark McClain <mark.mcclain@dreamhost.com>
Fri, 9 Aug 2013 03:10:41 +0000 (23:10 -0400)
Nova is trying to do a better job of mapping Neutron exceptions and
change I4c087684ef77988e5f463d7f2f50fc2a04f37db0 is trying to map 409 to
the proper nova exception. In looking at what raises a 409 exception in
Neutron, the SubnetMismatchForPort exception seemed like a candidate for
changing from Conflict (409) to BadRequest (400) to ease that mapping.

Note that the only thing currently using this exception is the L3 router
extension when removing a router interface and the 400 response code is
already listed in the API docs as a possible response code:

http://docs.openstack.org/api/openstack-network/2.0/content/router_remove_interface.html

Also note that it's generally OK to change APIs for a more accurate
response code:

https://wiki.openstack.org/wiki/APIChangeGuidelines#Generally_Considered_OK

Related-Bug: #1209446

Change-Id: I4507e1db69d738ec0f943f1b8b1209f269d5aebf

neutron/common/exceptions.py
neutron/tests/unit/bigswitch/test_router_db.py
neutron/tests/unit/nicira/test_nicira_plugin.py
neutron/tests/unit/test_l3_plugin.py

index 63ff13894d601b9b8ed7a724b5c67391f7aed92a..65c05af433389573886668713ce7d673b1bf480a 100644 (file)
@@ -178,7 +178,7 @@ class NoNetworkAvailable(ResourceExhausted):
                 "No tenant network is available for allocation.")
 
 
-class SubnetMismatchForPort(Conflict):
+class SubnetMismatchForPort(BadRequest):
     message = _("Subnet on port %(port_id)s does not match "
                 "the requested subnet %(subnet_id)s")
 
index a5d16068be8e853cb9e83d72f59500780b98cd28..72712fa7cd3802c1f58623527a6c5f2e12f47cd9 100644 (file)
@@ -112,7 +112,7 @@ class RouterDBTestCase(test_l3_plugin.L3NatDBTestCase):
         cfg.CONF.reset()
         test_l3_plugin.L3NatDBTestCase.setUp = origSetUp
 
-    def test_router_remove_router_interface_wrong_subnet_returns_409(self):
+    def test_router_remove_router_interface_wrong_subnet_returns_400(self):
         with self.router() as r:
             with self.subnet() as s:
                 with self.subnet(cidr='10.0.10.0/24') as s1:
@@ -125,7 +125,7 @@ class RouterDBTestCase(test_l3_plugin.L3NatDBTestCase):
                                                       r['router']['id'],
                                                       s['subnet']['id'],
                                                       p['port']['id'],
-                                                      exc.HTTPConflict.code)
+                                                      exc.HTTPBadRequest.code)
                         #remove properly to clean-up
                         self._router_interface_action('remove',
                                                       r['router']['id'],
@@ -213,7 +213,7 @@ class RouterDBTestCase(test_l3_plugin.L3NatDBTestCase):
                     subnet['subnet']['network_id'],
                     expected_code=exc.HTTPConflict.code)
 
-    def test_router_remove_interface_wrong_subnet_returns_409(self):
+    def test_router_remove_interface_wrong_subnet_returns_400(self):
         with self.router() as r:
             with self.subnet(cidr='10.0.10.0/24') as s:
                 with self.port(no_delete=True) as p:
@@ -225,7 +225,7 @@ class RouterDBTestCase(test_l3_plugin.L3NatDBTestCase):
                                                   r['router']['id'],
                                                   s['subnet']['id'],
                                                   p['port']['id'],
-                                                  exc.HTTPConflict.code)
+                                                  exc.HTTPBadRequest.code)
                     #remove properly to clean-up
                     self._router_interface_action('remove',
                                                   r['router']['id'],
index 80c4575dbac7ccb5d55dd6b674cc9b1a10311348..00746350c4b5bfeeff8478ce169b569103cdd1b4 100644 (file)
@@ -514,9 +514,9 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase,
         self.test_router_remove_interface_inuse_returns_409()
         self._nvp_metadata_teardown()
 
-    def test_router_remove_iface_wrong_sub_returns_409_with_metadata(self):
+    def test_router_remove_iface_wrong_sub_returns_400_with_metadata(self):
         self._nvp_metadata_setup()
-        self.test_router_remove_interface_wrong_subnet_returns_409()
+        self.test_router_remove_interface_wrong_subnet_returns_400()
         self._nvp_metadata_teardown()
 
     def test_router_delete_with_metadata_access(self):
index 2145b6e6303d2681abc3be477eba93124e43d361..3ce117cd1a315dfc8216c1fb88c7bec668bb8e94 100644 (file)
@@ -989,7 +989,7 @@ class L3NatDBTestCase(L3NatTestCaseBase):
                                               s['subnet']['id'],
                                               None)
 
-    def test_router_remove_interface_wrong_subnet_returns_409(self):
+    def test_router_remove_interface_wrong_subnet_returns_400(self):
         with self.router() as r:
             with self.subnet() as s:
                 with self.port(no_delete=True) as p:
@@ -1001,7 +1001,7 @@ class L3NatDBTestCase(L3NatTestCaseBase):
                                                   r['router']['id'],
                                                   s['subnet']['id'],
                                                   p['port']['id'],
-                                                  exc.HTTPConflict.code)
+                                                  exc.HTTPBadRequest.code)
                     #remove properly to clean-up
                     self._router_interface_action('remove',
                                                   r['router']['id'],