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
This commit is contained in:
armando-migliaccio 2014-03-21 14:48:19 -07:00 committed by Gerrit Code Review
parent 2913b49028
commit e7d47f53fd
7 changed files with 58 additions and 23 deletions

View File

@ -294,10 +294,17 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
context.session.delete(gw_db) context.session.delete(gw_db)
LOG.debug(_("Network gateway '%s' was destroyed."), id) 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, return self._get_collection(context, NetworkGateway,
self._make_network_gateway_dict, 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, def connect_network(self, context, network_gateway_id,
network_mapping_info): network_mapping_info):
@ -437,10 +444,18 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
fields, include_nsx_id) fields, include_nsx_id)
def get_gateway_devices(self, context, filters=None, fields=None, 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, query = self._get_collection_query(context,
NetworkGatewayDevice, 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) return [self._make_gateway_device_dict(row, fields, include_nsx_id)
for row in query] for row in query]

View File

@ -98,10 +98,15 @@ class QoSDbMixin(qos.QueuePluginBase):
except exc.NoResultFound: except exc.NoResultFound:
raise qos.QueueNotFound(id=queue_id) 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, return self._get_collection(context, QoSQueue,
self._make_qos_queue_dict, 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): def delete_qos_queue(self, context, queue_id):
qos_queue = self._get_qos_queue(context, queue_id) qos_queue = self._get_qos_queue(context, queue_id)

View File

@ -213,7 +213,9 @@ class NetworkGatewayPluginBase(object):
pass pass
@abstractmethod @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 pass
@abstractmethod @abstractmethod
@ -243,5 +245,7 @@ class NetworkGatewayPluginBase(object):
pass pass
@abstractmethod @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 pass

View File

@ -218,5 +218,6 @@ class QueuePluginBase(object):
pass pass
@abstractmethod @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 pass

View File

@ -117,6 +117,8 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
"security-group"] "security-group"]
__native_bulk_support = True __native_bulk_support = True
__native_pagination_support = True
__native_sorting_support = True
# Map nova zones to cluster for easy retrieval # Map nova zones to cluster for easy retrieval
novazone_cluster_map = {} novazone_cluster_map = {}
@ -1082,10 +1084,15 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self._extend_network_dict_provider(context, net_result) self._extend_network_dict_provider(context, net_result)
return self._fields(net_result, fields) 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 {} filters = filters or {}
with context.session.begin(subtransactions=True): 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: for net in networks:
self._extend_network_dict_provider(context, net) self._extend_network_dict_provider(context, net)
return [self._fields(network, fields) for network in networks] 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, return super(NsxPluginV2, self).get_network_gateway(context,
id, fields) 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 # Ensure the default gateway in the config file is in sync with the db
self._ensure_default_network_gateway() self._ensure_default_network_gateway()
# Ensure the tenant_id attribute is populated on returned gateways # Ensure the tenant_id attribute is populated on returned gateways
net_gateways = super(NsxPluginV2, return super(NsxPluginV2, self).get_network_gateways(
self).get_network_gateways(context, context, filters, fields, sorts, limit, marker, page_reverse)
filters,
fields)
return net_gateways
def update_network_gateway(self, context, id, network_gateway): def update_network_gateway(self, context, id, network_gateway):
# Ensure the default gateway in the config file is in sync with the db # Ensure the default gateway in the config file is in sync with the db

View File

@ -92,6 +92,9 @@ class NsxAdvancedPlugin(sr_db.ServiceRouter_mixin,
"lbaas", "lbaas",
"vpnaas" "vpnaas"
]) ])
# The service plugin cannot currently support pagination
__native_pagination_support = False
__native_sorting_support = False
def __init__(self): def __init__(self):
super(NsxAdvancedPlugin, self).__init__() super(NsxAdvancedPlugin, self).__init__()

View File

@ -939,14 +939,15 @@ class TestNetworkGateway(NsxPluginV2TestCase,
with self._network_gateway(name='test_gw_2') as gw2: with self._network_gateway(name='test_gw_2') as gw2:
req = self.new_list_request(networkgw.NETWORK_GATEWAYS) req = self.new_list_request(networkgw.NETWORK_GATEWAYS)
res = self.deserialize('json', req.get_response(self.ext_api)) 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 # We expect the default gateway too
key = self.gw_resource + 's' self.assertEqual(gateways[0]['default'], True)
self.assertEqual(len(res[key]), 3) self.assertEqual(gateways[1]['name'],
self.assertEqual(res[key][0]['default'],
True)
self.assertEqual(res[key][1]['name'],
gw1[self.gw_resource]['name']) gw1[self.gw_resource]['name'])
self.assertEqual(res[key][2]['name'], self.assertEqual(gateways[2]['name'],
gw2[self.gw_resource]['name']) gw2[self.gw_resource]['name'])
def test_list_network_gateway_with_multiple_connections(self): def test_list_network_gateway_with_multiple_connections(self):