Avoid calling neutron for N networks
In the worst case scenario, we could list N floating IPs, each of which has a different network. This would result in N additional calls to neutron - one for each of the networks. Avoid this by calling neutron once for all networks associated with the floating IPs. Change-Id: If067a730b0fcbe3f59f4472b00c690cc43be4b3b Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
eef658bf53
commit
3e79cb7577
@ -2658,16 +2658,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]
|
||||
|
||||
|
@ -5412,10 +5412,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': [
|
||||
@ -5432,6 +5434,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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user