Merge "Avoid calling neutron for N networks"

This commit is contained in:
Zuul 2020-02-06 06:50:58 +00:00 committed by Gerrit Code Review
commit 014c1ab864
2 changed files with 12 additions and 11 deletions

View File

@ -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]

View File

@ -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: