Merge "ML2 plugin: extract and postpone limit in port query"
This commit is contained in:
commit
3e1cd9abef
@ -2201,6 +2201,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
def _get_ports_query(self, context, filters=None, *args, **kwargs):
|
||||
filters = filters or {}
|
||||
security_groups = filters.pop("security_groups", None)
|
||||
limit = kwargs.pop('limit', None)
|
||||
if security_groups:
|
||||
port_bindings = self._get_port_security_group_bindings(
|
||||
context, filters={'security_group_id':
|
||||
@ -2220,6 +2221,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
models_v2.IPAllocation.ip_address.like('%%%s%%' % ip))
|
||||
for ip in ip_addresses_s])
|
||||
query = query.filter(substr_filter)
|
||||
if limit:
|
||||
query = query.limit(limit)
|
||||
return query
|
||||
|
||||
def filter_hosts_with_network_access(
|
||||
|
@ -1555,6 +1555,12 @@ fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s
|
||||
query_params=query_params)
|
||||
query_params = """
|
||||
fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s
|
||||
""".strip() % ('192.168.',
|
||||
fixed_ips['subnet_id'])
|
||||
self._test_list_resources('port', [],
|
||||
query_params=query_params)
|
||||
query_params = """
|
||||
fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s&limit=1
|
||||
""".strip() % ('192.168.',
|
||||
fixed_ips['subnet_id'])
|
||||
self._test_list_resources('port', [],
|
||||
@ -1608,6 +1614,12 @@ fixed_ips=ip_address_substr%%3D%s&fixed_ips=ip_address%%3D%s
|
||||
self.assertEqual(set([port1['port']['id'], port2['port']['id']]),
|
||||
set([port['id'] for port in ports_data['ports']]))
|
||||
self.assertEqual(2, len(ports_data['ports']))
|
||||
query_params = "security_groups=%s&limit=1" % (
|
||||
port1['port']['security_groups'][0])
|
||||
ports_data = self._list('ports', query_params=query_params)
|
||||
self.assertIn(ports_data['ports'][0]['id'],
|
||||
[port1['port']['id'], port2['port']['id']])
|
||||
self.assertEqual(1, len(ports_data['ports']))
|
||||
query_params = "security_groups=%s&id=%s" % (
|
||||
port1['port']['security_groups'][0],
|
||||
port1['port']['id'])
|
||||
|
Loading…
Reference in New Issue
Block a user