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:
parent
2913b49028
commit
e7d47f53fd
@ -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]
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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__()
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user