From: Matt Riedemann Date: Thu, 8 Aug 2013 19:33:10 +0000 (-0700) Subject: Make SubnetMismatchForPort extend BadRequest rather than Conflict X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6cd3e190c6ef6f5df9b1b101bd45102e44ca8588;p=openstack-build%2Fneutron-build.git Make SubnetMismatchForPort extend BadRequest rather than Conflict 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 --- diff --git a/neutron/common/exceptions.py b/neutron/common/exceptions.py index 63ff13894..65c05af43 100644 --- a/neutron/common/exceptions.py +++ b/neutron/common/exceptions.py @@ -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") diff --git a/neutron/tests/unit/bigswitch/test_router_db.py b/neutron/tests/unit/bigswitch/test_router_db.py index a5d16068b..72712fa7c 100644 --- a/neutron/tests/unit/bigswitch/test_router_db.py +++ b/neutron/tests/unit/bigswitch/test_router_db.py @@ -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'], diff --git a/neutron/tests/unit/nicira/test_nicira_plugin.py b/neutron/tests/unit/nicira/test_nicira_plugin.py index 80c4575db..00746350c 100644 --- a/neutron/tests/unit/nicira/test_nicira_plugin.py +++ b/neutron/tests/unit/nicira/test_nicira_plugin.py @@ -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): diff --git a/neutron/tests/unit/test_l3_plugin.py b/neutron/tests/unit/test_l3_plugin.py index 2145b6e63..3ce117cd1 100644 --- a/neutron/tests/unit/test_l3_plugin.py +++ b/neutron/tests/unit/test_l3_plugin.py @@ -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'],