Browse Source

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

changes/85/681585/1
Zuul 1 week ago
parent
commit
7bb394e401
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

@@ -2196,6 +2196,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
2196 2196
     def _get_ports_query(self, context, filters=None, *args, **kwargs):
2197 2197
         filters = filters or {}
2198 2198
         security_groups = filters.pop("security_groups", None)
2199
+        limit = kwargs.pop('limit', None)
2199 2200
         if security_groups:
2200 2201
             port_bindings = self._get_port_security_group_bindings(
2201 2202
                 context, filters={'security_group_id':
@@ -2215,6 +2216,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
2215 2216
                 models_v2.IPAllocation.ip_address.like('%%%s%%' % ip))
2216 2217
                 for ip in ip_addresses_s])
2217 2218
             query = query.filter(substr_filter)
2219
+        if limit:
2220
+            query = query.limit(limit)
2218 2221
         return query
2219 2222
 
2220 2223
     def filter_hosts_with_network_access(

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

@@ -1460,6 +1460,12 @@ fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s
1460 1460
                                       query_params=query_params)
1461 1461
             query_params = """
1462 1462
 fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s
1463
+""".strip() % ('192.168.',
1464
+               fixed_ips['subnet_id'])
1465
+            self._test_list_resources('port', [],
1466
+                                      query_params=query_params)
1467
+            query_params = """
1468
+fixed_ips=ip_address_substr%%3D%s&fixed_ips=subnet_id%%3D%s&limit=1
1463 1469
 """.strip() % ('192.168.',
1464 1470
                fixed_ips['subnet_id'])
1465 1471
             self._test_list_resources('port', [],
@@ -1513,6 +1519,12 @@ fixed_ips=ip_address_substr%%3D%s&fixed_ips=ip_address%%3D%s
1513 1519
             self.assertEqual(set([port1['port']['id'], port2['port']['id']]),
1514 1520
                              set([port['id'] for port in ports_data['ports']]))
1515 1521
             self.assertEqual(2, len(ports_data['ports']))
1522
+            query_params = "security_groups=%s&limit=1" % (
1523
+                           port1['port']['security_groups'][0])
1524
+            ports_data = self._list('ports', query_params=query_params)
1525
+            self.assertIn(ports_data['ports'][0]['id'],
1526
+                          [port1['port']['id'], port2['port']['id']])
1527
+            self.assertEqual(1, len(ports_data['ports']))
1516 1528
             query_params = "security_groups=%s&id=%s" % (
1517 1529
                            port1['port']['security_groups'][0],
1518 1530
                            port1['port']['id'])

Loading…
Cancel
Save