Fix showing nonexistent NetworkGateway throws 500 instead of 404
Change-Id: I5304bd52f7a5ae22fbc0d48206d7c1d282b34a91 Closes-Bug: #1252921
This commit is contained in:
parent
6810b62fbb
commit
68369fe678
@ -223,7 +223,7 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
try:
|
try:
|
||||||
def_network_gw = self._get_network_gateway(ctx,
|
def_network_gw = self._get_network_gateway(ctx,
|
||||||
def_l2_gw_uuid)
|
def_l2_gw_uuid)
|
||||||
except sa_exc.NoResultFound:
|
except networkgw_db.GatewayNotFound:
|
||||||
# Create in DB only - don't go on NVP
|
# Create in DB only - don't go on NVP
|
||||||
def_gw_data = {'id': def_l2_gw_uuid,
|
def_gw_data = {'id': def_l2_gw_uuid,
|
||||||
'name': 'default L2 gateway service',
|
'name': 'default L2 gateway service',
|
||||||
|
@ -48,6 +48,10 @@ class GatewayInUse(exceptions.InUse):
|
|||||||
"with one or more neutron networks.")
|
"with one or more neutron networks.")
|
||||||
|
|
||||||
|
|
||||||
|
class GatewayNotFound(exceptions.NotFound):
|
||||||
|
message = _("Network Gateway %(gateway_id)s could not be found")
|
||||||
|
|
||||||
|
|
||||||
class NetworkGatewayPortInUse(exceptions.InUse):
|
class NetworkGatewayPortInUse(exceptions.InUse):
|
||||||
message = _("Port '%(port_id)s' is owned by '%(device_owner)s' and "
|
message = _("Port '%(port_id)s' is owned by '%(device_owner)s' and "
|
||||||
"therefore cannot be deleted directly via the port API.")
|
"therefore cannot be deleted directly via the port API.")
|
||||||
@ -130,7 +134,11 @@ class NetworkGatewayMixin(nvp_networkgw.NetworkGatewayPluginBase):
|
|||||||
resource = nvp_networkgw.RESOURCE_NAME.replace('-', '_')
|
resource = nvp_networkgw.RESOURCE_NAME.replace('-', '_')
|
||||||
|
|
||||||
def _get_network_gateway(self, context, gw_id):
|
def _get_network_gateway(self, context, gw_id):
|
||||||
return self._get_by_id(context, NetworkGateway, gw_id)
|
try:
|
||||||
|
gw = self._get_by_id(context, NetworkGateway, gw_id)
|
||||||
|
except sa_orm_exc.NoResultFound:
|
||||||
|
raise GatewayNotFound(gateway_id=gw_id)
|
||||||
|
return gw
|
||||||
|
|
||||||
def _make_gw_connection_dict(self, gw_conn):
|
def _make_gw_connection_dict(self, gw_conn):
|
||||||
return {'port_id': gw_conn['port_id'],
|
return {'port_id': gw_conn['port_id'],
|
||||||
|
@ -1421,6 +1421,12 @@ class TestNiciraNetworkGateway(test_l2_gw.NetworkGatewayDbTestCase,
|
|||||||
# The default gateway must still be there
|
# The default gateway must still be there
|
||||||
self._test_delete_network_gateway(1)
|
self._test_delete_network_gateway(1)
|
||||||
|
|
||||||
|
def test_show_network_gateway_nvp_error_returns_404(self):
|
||||||
|
invalid_id = 'b5afd4a9-eb71-4af7-a082-8fc625a35b61'
|
||||||
|
req = self.new_show_request(nvp_networkgw.COLLECTION_NAME, invalid_id)
|
||||||
|
res = req.get_response(self.ext_api)
|
||||||
|
self.assertEqual(webob.exc.HTTPNotFound.code, res.status_int)
|
||||||
|
|
||||||
|
|
||||||
class TestNiciraMultiProviderNetworks(NiciraPluginV2TestCase):
|
class TestNiciraMultiProviderNetworks(NiciraPluginV2TestCase):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user