De-dupe subnet IDs when calling neutron /subnets API
In the _get_subnets_from_port method, we call the neutron /subnets API
to list subnets filtered by subnet IDs. We get the subnet IDs by
iterating all of the fixed IPs for the instance and sending the list of
corresponding subnet IDs. The python-neutronclient sends the list of
subnet IDs as a query string in the URI. When an instance has a large
number of interfaces attached, the list of subnet IDs can be too long
for the URI, resulting in a RequestURITooLong error from neutronclient.
This de-dupes the subnet IDs before calling neutron, to handle the case
where an instance has a large number of interfaces attached, but many
of them are on the same subnet.
Closes-Bug: #1796074
Change-Id: I5b52ff81f74ae7cb11e6f012ab7e53cfc6821486
(cherry picked from commit ab5fc68702
)
This commit is contained in:
parent
55b63c4d60
commit
057a05dbbd
|
@ -2885,7 +2885,7 @@ class API(base_api.NetworkAPI):
|
|||
return []
|
||||
if not client:
|
||||
client = get_client(context)
|
||||
search_opts = {'id': [ip['subnet_id'] for ip in fixed_ips]}
|
||||
search_opts = {'id': list(set(ip['subnet_id'] for ip in fixed_ips))}
|
||||
data = client.list_subnets(**search_opts)
|
||||
ipam_subnets = data.get('subnets', [])
|
||||
subnets = []
|
||||
|
|
|
@ -2865,6 +2865,9 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
api = neutronapi.API()
|
||||
|
||||
port_data = copy.copy(self.port_data1[0])
|
||||
# add another IP on the same subnet and verify the subnet is deduped
|
||||
port_data['fixed_ips'].append({'ip_address': '10.0.1.3',
|
||||
'subnet_id': 'my_subid1'})
|
||||
subnet_data1 = copy.copy(self.subnet_data1)
|
||||
subnet_data1[0]['host_routes'] = [
|
||||
{'destination': '192.168.0.0/24', 'nexthop': '1.0.0.10'}
|
||||
|
|
Loading…
Reference in New Issue