Enable sorting and pagination for segments

It looks the sorting and pagination are natively supported in
segment db layer but the segment controller doesn't mark these
features as supported. This patch fixes it.

Change-Id: I325396bb0256196ee6c6fc42cc812a0c75ae3827
Closes-Bug: #1763161
This commit is contained in:
Hongbin Lu 2018-04-13 21:47:02 +00:00
parent f2dced777a
commit 43d451d86f
3 changed files with 56 additions and 1 deletions

View File

@ -117,7 +117,9 @@ class Segment(api_extensions.ExtensionDescriptor):
SEGMENTS,
SEGMENT,
directory.get_plugin(SEGMENTS),
resource_attributes)
resource_attributes,
allow_pagination=True,
allow_sorting=True)
return [extensions.ResourceExtension(SEGMENTS,
controller,
attr_map=resource_attributes)]

View File

@ -60,6 +60,9 @@ class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase):
supported_extension_aliases = ["segment", "ip_allocation",
l2adj_apidef.ALIAS]
__native_pagination_support = True
__native_sorting_support = True
def __init__(self):
self.nova_updater = NovaSegmentNotifier()

View File

@ -347,6 +347,56 @@ class TestSegment(SegmentTestCase):
res = self._list('segments')
self.assertEqual(2, len(res['segments']))
def test_list_segments_with_sort(self):
with self.network() as network:
network = network['network']
s1 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net1',
segmentation_id=200)
s2 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net2',
segmentation_id=201)
self._test_list_with_sort('segment',
(s2, s1),
[('physical_network', 'desc')],
query_params='network_id=%s' % network['id'])
def test_list_segments_with_pagination(self):
with self.network() as network:
network = network['network']
s1 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net1',
segmentation_id=200)
s2 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net2',
segmentation_id=201)
s3 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net3',
segmentation_id=202)
self._test_list_with_pagination(
'segment',
(s1, s2, s3),
('physical_network', 'asc'), 2, 2,
query_params='network_id=%s' % network['id'])
def test_list_segments_with_pagination_reverse(self):
with self.network() as network:
network = network['network']
s1 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net1',
segmentation_id=200)
s2 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net2',
segmentation_id=201)
s3 = self._test_create_segment(network_id=network['id'],
physical_network='phys_net3',
segmentation_id=202)
self._test_list_with_pagination_reverse(
'segment',
(s1, s2, s3),
('physical_network', 'asc'), 2, 2,
query_params='network_id=%s' % network['id'])
def test_update_segments(self):
with self.network() as network:
net = network['network']