diff --git a/nova/network/neutron.py b/nova/network/neutron.py index 0cfbe4b4a31d..980002626224 100644 --- a/nova/network/neutron.py +++ b/nova/network/neutron.py @@ -2645,16 +2645,13 @@ class API(base.Base): # retrieve and cache the network details now since many callers need # the network name which isn't present in the response from neutron - networks = {} + networks = {net['id']: net for net in self._get_available_networks( + context, project_id, [fip['floating_network_id'] for fip in fips], + client)} for fip in fips: network_uuid = fip['floating_network_id'] if network_uuid not in networks: - try: - network = client.show_network(network_uuid)['network'] - except neutron_client_exc.NetworkNotFoundClient: - raise exception.NetworkNotFound(network_id=network_uuid) - - networks[network['id']] = network + raise exception.NetworkNotFound(network_id=network_uuid) fip['network_details'] = networks[network_uuid] diff --git a/nova/tests/unit/network/test_neutron.py b/nova/tests/unit/network/test_neutron.py index b1ea2907cf32..a7e361a8e9d5 100644 --- a/nova/tests/unit/network/test_neutron.py +++ b/nova/tests/unit/network/test_neutron.py @@ -5398,10 +5398,12 @@ class TestAPI(TestAPIBase): } ] } - mock_nc.show_network.return_value = { - 'network': { - 'id': uuids.fip_net_id, - }, + mock_nc.list_networks.return_value = { + 'networks': [ + { + 'id': uuids.fip_net_id, + }, + ], } mock_nc.list_ports.return_value = { 'ports': [ @@ -5418,6 +5420,8 @@ class TestAPI(TestAPIBase): fips = self.api.get_floating_ips_by_project(self.context) + mock_nc.list_networks.assert_called_once_with( + id=[uuids.fip_net_id]) self.assertEqual(1, len(fips)) if fip_ext_enabled: