Catch NeutronClientException when showing a network
When a network id can't be found, neutronclient raise NetworkNotFoundClient exception, but this exception is not handled by nova. This will cause a 500 error. This patch fixes this bug. Closes-Bug: #1286969 Change-Id: Ia96c9668c74374476d4dccdbdb281e99d91b0088
This commit is contained in:
parent
785d7c78ca
commit
dac0ce979e
|
@ -829,7 +829,10 @@ class API(base_api.NetworkAPI):
|
|||
def get(self, context, network_uuid):
|
||||
"""Get specific network for client."""
|
||||
client = neutronv2.get_client(context)
|
||||
network = client.show_network(network_uuid).get('network') or {}
|
||||
try:
|
||||
network = client.show_network(network_uuid).get('network') or {}
|
||||
except neutron_client_exc.NetworkNotFoundClient:
|
||||
raise exception.NetworkNotFound(network_id=network_uuid)
|
||||
network['label'] = network['name']
|
||||
return network
|
||||
|
||||
|
|
|
@ -2369,6 +2369,19 @@ class TestNeutronv2WithMock(test.TestCase):
|
|||
# Assert the calls.
|
||||
create_port_mock.assert_called_once_with(port_req_body)
|
||||
|
||||
def test_get_network_detail_not_found(self):
|
||||
api = neutronapi.API()
|
||||
expected_exc = exceptions.NetworkNotFoundClient()
|
||||
network_uuid = '02cacbca-7d48-4a2c-8011-43eecf8a9786'
|
||||
with mock.patch.object(client.Client, 'show_network',
|
||||
side_effect=expected_exc) as (
|
||||
fake_show_network):
|
||||
self.assertRaises(exception.NetworkNotFound,
|
||||
api.get,
|
||||
self.context,
|
||||
network_uuid)
|
||||
fake_show_network.assert_called_once_with(network_uuid)
|
||||
|
||||
|
||||
class TestNeutronv2ModuleMethods(test.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue