Browse Source

Merge "ML2 plugin: extract and postpone limit in port query" into stable/rocky

stable/rocky
Zuul 6 days ago
parent
commit
053e9b662c
2 changed files with 15 additions and 0 deletions
  1. 3
    0
      neutron/plugins/ml2/plugin.py
  2. 12
    0
      neutron/tests/unit/plugins/ml2/test_plugin.py

+ 3
- 0
neutron/plugins/ml2/plugin.py View File

@@ -1995,6 +1995,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
1995 1995
     def _get_ports_query(self, context, filters=None, *args, **kwargs):
1996 1996
         filters = filters or {}
1997 1997
         security_groups = filters.pop("security_groups", None)
1998
+        limit = kwargs.pop('limit', None)
1998 1999
         if security_groups:
1999 2000
             port_bindings = self._get_port_security_group_bindings(
2000 2001
                 context, filters={'security_group_id':
@@ -2014,6 +2015,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
2014 2015
                 models_v2.IPAllocation.ip_address.like('%%%s%%' % ip))
2015 2016
                 for ip in ip_addresses_s])
2016 2017
             query = query.filter(substr_filter)
2018
+        if limit:
2019
+            query = query.limit(limit)
2017 2020
         return query
2018 2021
 
2019 2022
     def filter_hosts_with_network_access(

+ 12
- 0
neutron/tests/unit/plugins/ml2/test_plugin.py View File

@@ -1418,6 +1418,12 @@ fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s
1418 1418
                                       query_params=query_params)
1419 1419
             query_params = """
1420 1420
 fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s
1421
+""".strip() % ('192.168.',
1422
+               fixed_ips['subnet_id'])
1423
+            self._test_list_resources('port', [],
1424
+                                      query_params=query_params)
1425
+            query_params = """
1426
+fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s&limit=1
1421 1427
 """.strip() % ('192.168.',
1422 1428
                fixed_ips['subnet_id'])
1423 1429
             self._test_list_resources('port', [],
@@ -1471,6 +1477,12 @@ fixed_ips=ip_address_substr%%3D%s&fixed_ips=ip_address%%3D%s
1471 1477
             self.assertEqual(set([port1['port']['id'], port2['port']['id']]),
1472 1478
                              set([port['id'] for port in ports_data['ports']]))
1473 1479
             self.assertEqual(2, len(ports_data['ports']))
1480
+            query_params = "security_groups=%s&limit=1" % (
1481
+                           port1['port']['security_groups'][0])
1482
+            ports_data = self._list('ports', query_params=query_params)
1483
+            self.assertIn(ports_data['ports'][0]['id'],
1484
+                          [port1['port']['id'], port2['port']['id']])
1485
+            self.assertEqual(1, len(ports_data['ports']))
1474 1486
             query_params = "security_groups=%s&id=%s" % (
1475 1487
                            port1['port']['security_groups'][0],
1476 1488
                            port1['port']['id'])

Loading…
Cancel
Save