From 70df0be32b0eabe0ae97e202ee215752d724ff3e Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Fri, 21 Mar 2014 14:48:19 -0700 Subject: [PATCH] NSX: Fix pagination support 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 | 23 +++++++++++++++---- neutron/plugins/vmware/dbexts/qos_db.py | 9 ++++++-- .../plugins/vmware/extensions/networkgw.py | 8 +++++-- neutron/plugins/vmware/extensions/qos.py | 3 ++- neutron/plugins/vmware/plugins/base.py | 22 +++++++++++------- neutron/plugins/vmware/plugins/service.py | 3 +++ .../unit/vmware/extensions/test_networkgw.py | 13 ++++++----- 7 files changed, 58 insertions(+), 23 deletions(-) diff --git a/neutron/plugins/vmware/dbexts/networkgw_db.py b/neutron/plugins/vmware/dbexts/networkgw_db.py index 6a1c3c21b..17773d963 100644 --- a/neutron/plugins/vmware/dbexts/networkgw_db.py +++ b/neutron/plugins/vmware/dbexts/networkgw_db.py @@ -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] diff --git a/neutron/plugins/vmware/dbexts/qos_db.py b/neutron/plugins/vmware/dbexts/qos_db.py index 4f9ff316e..b094a2293 100644 --- a/neutron/plugins/vmware/dbexts/qos_db.py +++ b/neutron/plugins/vmware/dbexts/qos_db.py @@ -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) diff --git a/neutron/plugins/vmware/extensions/networkgw.py b/neutron/plugins/vmware/extensions/networkgw.py index 3d8ea8807..8280cc273 100644 --- a/neutron/plugins/vmware/extensions/networkgw.py +++ b/neutron/plugins/vmware/extensions/networkgw.py @@ -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 diff --git a/neutron/plugins/vmware/extensions/qos.py b/neutron/plugins/vmware/extensions/qos.py index c300473aa..c9df11b1b 100644 --- a/neutron/plugins/vmware/extensions/qos.py +++ b/neutron/plugins/vmware/extensions/qos.py @@ -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 diff --git a/neutron/plugins/vmware/plugins/base.py b/neutron/plugins/vmware/plugins/base.py index 457fa8bc0..4e8fcb697 100644 --- a/neutron/plugins/vmware/plugins/base.py +++ b/neutron/plugins/vmware/plugins/base.py @@ -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 diff --git a/neutron/plugins/vmware/plugins/service.py b/neutron/plugins/vmware/plugins/service.py index b181baf59..24be47f6f 100644 --- a/neutron/plugins/vmware/plugins/service.py +++ b/neutron/plugins/vmware/plugins/service.py @@ -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__() diff --git a/neutron/tests/unit/vmware/extensions/test_networkgw.py b/neutron/tests/unit/vmware/extensions/test_networkgw.py index 6c81f9c33..d77b777fd 100644 --- a/neutron/tests/unit/vmware/extensions/test_networkgw.py +++ b/neutron/tests/unit/vmware/extensions/test_networkgw.py @@ -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): -- 2.45.2