]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: Fix pagination support
authorarmando-migliaccio <armamig@gmail.com>
Fri, 21 Mar 2014 21:48:19 +0000 (14:48 -0700)
committerMark McClain <mmcclain@yahoo-inc.com>
Fri, 4 Apr 2014 23:13:51 +0000 (19:13 -0400)
Add pagination support to the base plugin,
leaving the service plugin unaltered.

Minor tweaks to the UT where required to
avoid intermittent failures caused by random
ordering.

Closes-bug: 1295854

Change-Id: I03e9e104967716046909d6120426e879f714a5c8
(cherry picked from commit 16ce0ae2c2b50b4317cdb95e62246d805b3d76a9)

neutron/plugins/vmware/dbexts/networkgw_db.py
neutron/plugins/vmware/dbexts/qos_db.py
neutron/plugins/vmware/extensions/networkgw.py
neutron/plugins/vmware/extensions/qos.py
neutron/plugins/vmware/plugins/base.py
neutron/plugins/vmware/plugins/service.py
neutron/tests/unit/vmware/extensions/test_networkgw.py

index 6a1c3c21b3c5d6b3d17fd0190ad019b3d80e16ad..17773d96366491b199964ded08fd499909503800 100644 (file)
@@ -294,10 +294,17 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
             context.session.delete(gw_db)
         LOG.debug(_("Network gateway '%s' was destroyed."), id)
 
-    def get_network_gateways(self, context, filters=None, fields=None):
+    def get_network_gateways(self, context, filters=None, fields=None,
+                             sorts=None, limit=None, marker=None,
+                             page_reverse=False):
+        marker_obj = self._get_marker_obj(
+            context, 'network_gateway', limit, marker)
         return self._get_collection(context, NetworkGateway,
                                     self._make_network_gateway_dict,
-                                    filters=filters, fields=fields)
+                                    filters=filters, fields=fields,
+                                    sorts=sorts, limit=limit,
+                                    marker_obj=marker_obj,
+                                    page_reverse=page_reverse)
 
     def connect_network(self, context, network_gateway_id,
                         network_mapping_info):
@@ -437,10 +444,18 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
             fields, include_nsx_id)
 
     def get_gateway_devices(self, context, filters=None, fields=None,
-                            include_nsx_id=False):
+                            sorts=None, limit=None, marker=None,
+                            page_reverse=False, include_nsx_id=False):
+        marker_obj = self._get_marker_obj(
+            context, 'gateway_device', limit, marker)
         query = self._get_collection_query(context,
                                            NetworkGatewayDevice,
-                                           filters=filters)
+                                           filters=filters,
+                                           fields=fields,
+                                           sorts=sorts,
+                                           limit=limit,
+                                           marker_obj=marker_obj,
+                                           page_reverse=page_reverse)
         return [self._make_gateway_device_dict(row, fields, include_nsx_id)
                 for row in query]
 
index 4f9ff316e5c688f7476679354e080e320baf59f1..b094a2293f073dde239362ec9ca3f702f0697609 100644 (file)
@@ -98,10 +98,15 @@ class QoSDbMixin(qos.QueuePluginBase):
         except exc.NoResultFound:
             raise qos.QueueNotFound(id=queue_id)
 
-    def get_qos_queues(self, context, filters=None, fields=None):
+    def get_qos_queues(self, context, filters=None, fields=None, sorts=None,
+                       limit=None, marker=None, page_reverse=False):
+        marker_obj = self._get_marker_obj(context, 'qos_queue', limit, marker)
         return self._get_collection(context, QoSQueue,
                                     self._make_qos_queue_dict,
-                                    filters=filters, fields=fields)
+                                    filters=filters, fields=fields,
+                                    sorts=sorts, limit=limit,
+                                    marker_obj=marker_obj,
+                                    page_reverse=page_reverse)
 
     def delete_qos_queue(self, context, queue_id):
         qos_queue = self._get_qos_queue(context, queue_id)
index 3d8ea8807ab582fea35a2362726b96af28fc8c52..8280cc273bc044348eb5b9bd89973210ce46aee5 100644 (file)
@@ -213,7 +213,9 @@ class NetworkGatewayPluginBase(object):
         pass
 
     @abstractmethod
-    def get_network_gateways(self, context, filters=None, fields=None):
+    def get_network_gateways(self, context, filters=None, fields=None,
+                             sorts=None, limit=None, marker=None,
+                             page_reverse=False):
         pass
 
     @abstractmethod
@@ -243,5 +245,7 @@ class NetworkGatewayPluginBase(object):
         pass
 
     @abstractmethod
-    def get_gateway_devices(self, context, filters=None, fields=None):
+    def get_gateway_devices(self, context, filters=None, fields=None,
+                            sorts=None, limit=None, marker=None,
+                            page_reverse=False):
         pass
index c300473aa89104707b68ceef213456730a0f4dc7..c9df11b1bfe0ac53d0394872d60546d89bd7cc9f 100644 (file)
@@ -218,5 +218,6 @@ class QueuePluginBase(object):
         pass
 
     @abstractmethod
-    def get_qos_queues(self, context, filters=None, fields=None):
+    def get_qos_queues(self, context, filters=None, fields=None, sorts=None,
+                       limit=None, marker=None, page_reverse=False):
         pass
index 457fa8bc040bd6a3bdfd84f2817c004be188cd61..4e8fcb697d001801462409ca9aed6bbe99a71675 100644 (file)
@@ -117,6 +117,8 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
                                    "security-group"]
 
     __native_bulk_support = True
+    __native_pagination_support = True
+    __native_sorting_support = True
 
     # Map nova zones to cluster for easy retrieval
     novazone_cluster_map = {}
@@ -1082,10 +1084,15 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
             self._extend_network_dict_provider(context, net_result)
         return self._fields(net_result, fields)
 
-    def get_networks(self, context, filters=None, fields=None):
+    def get_networks(self, context, filters=None, fields=None,
+                     sorts=None, limit=None, marker=None,
+                     page_reverse=False):
         filters = filters or {}
         with context.session.begin(subtransactions=True):
-            networks = super(NsxPluginV2, self).get_networks(context, filters)
+            networks = (
+                super(NsxPluginV2, self).get_networks(
+                    context, filters, fields, sorts,
+                    limit, marker, page_reverse))
             for net in networks:
                 self._extend_network_dict_provider(context, net)
         return [self._fields(network, fields) for network in networks]
@@ -2052,15 +2059,14 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
         return super(NsxPluginV2, self).get_network_gateway(context,
                                                             id, fields)
 
-    def get_network_gateways(self, context, filters=None, fields=None):
+    def get_network_gateways(self, context, filters=None, fields=None,
+                             sorts=None, limit=None, marker=None,
+                             page_reverse=False):
         # Ensure the default gateway in the config file is in sync with the db
         self._ensure_default_network_gateway()
         # Ensure the tenant_id attribute is populated on returned gateways
-        net_gateways = super(NsxPluginV2,
-                             self).get_network_gateways(context,
-                                                        filters,
-                                                        fields)
-        return net_gateways
+        return super(NsxPluginV2, self).get_network_gateways(
+            context, filters, fields, sorts, limit, marker, page_reverse)
 
     def update_network_gateway(self, context, id, network_gateway):
         # Ensure the default gateway in the config file is in sync with the db
index b181baf5992e4170e95c14812c6b492c9d8945c2..24be47f6f61d1678ff3e9ca371a63c896a0c0ad9 100644 (file)
@@ -92,6 +92,9 @@ class NsxAdvancedPlugin(sr_db.ServiceRouter_mixin,
             "lbaas",
             "vpnaas"
         ])
+    # The service plugin cannot currently support pagination
+    __native_pagination_support = False
+    __native_sorting_support = False
 
     def __init__(self):
         super(NsxAdvancedPlugin, self).__init__()
index 6c81f9c33c41bbe3192bdd2ab8fd79dd79c7839f..d77b777fdebe90adcd15299ea54cdcb83656a00f 100644 (file)
@@ -939,14 +939,15 @@ class TestNetworkGateway(NsxPluginV2TestCase,
             with self._network_gateway(name='test_gw_2') as gw2:
                 req = self.new_list_request(networkgw.NETWORK_GATEWAYS)
                 res = self.deserialize('json', req.get_response(self.ext_api))
+                # Ensure we always get the list in the same order
+                gateways = sorted(
+                    res[self.gw_resource + 's'], key=lambda k: k['name'])
+                self.assertEqual(len(gateways), 3)
                 # We expect the default gateway too
-                key = self.gw_resource + 's'
-                self.assertEqual(len(res[key]), 3)
-                self.assertEqual(res[key][0]['default'],
-                                 True)
-                self.assertEqual(res[key][1]['name'],
+                self.assertEqual(gateways[0]['default'], True)
+                self.assertEqual(gateways[1]['name'],
                                  gw1[self.gw_resource]['name'])
-                self.assertEqual(res[key][2]['name'],
+                self.assertEqual(gateways[2]['name'],
                                  gw2[self.gw_resource]['name'])
 
     def test_list_network_gateway_with_multiple_connections(self):