summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHongbin Lu <hongbin.lu@huawei.com>2018-04-13 21:47:02 +0000
committerHongbin Lu <hongbin.lu@huawei.com>2018-04-13 21:51:18 +0000
commit43d451d86f8c1f9dff2a8580089a631680bb0c09 (patch)
treef65e641640075e6183a7f286cbe52252ed2b6202
parentf2dced777acb7d87dc7048c3efec59dadf37930d (diff)
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
Notes
Notes (review): Code-Review+2: Brian Haley <haleyb.dev@gmail.com> Code-Review+2: Slawek Kaplonski <skaplons@redhat.com> Workflow+1: Slawek Kaplonski <skaplons@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 23 Apr 2018 12:56:57 +0000 Reviewed-on: https://review.openstack.org/561361 Project: openstack/neutron Branch: refs/heads/master
-rw-r--r--neutron/extensions/segment.py4
-rw-r--r--neutron/services/segments/plugin.py3
-rw-r--r--neutron/tests/unit/extensions/test_segment.py50
3 files changed, 56 insertions, 1 deletions
diff --git a/neutron/extensions/segment.py b/neutron/extensions/segment.py
index 0eb19f4..7d8a4f9 100644
--- a/neutron/extensions/segment.py
+++ b/neutron/extensions/segment.py
@@ -117,7 +117,9 @@ class Segment(api_extensions.ExtensionDescriptor):
117 SEGMENTS, 117 SEGMENTS,
118 SEGMENT, 118 SEGMENT,
119 directory.get_plugin(SEGMENTS), 119 directory.get_plugin(SEGMENTS),
120 resource_attributes) 120 resource_attributes,
121 allow_pagination=True,
122 allow_sorting=True)
121 return [extensions.ResourceExtension(SEGMENTS, 123 return [extensions.ResourceExtension(SEGMENTS,
122 controller, 124 controller,
123 attr_map=resource_attributes)] 125 attr_map=resource_attributes)]
diff --git a/neutron/services/segments/plugin.py b/neutron/services/segments/plugin.py
index 68aef08..0a9e960 100644
--- a/neutron/services/segments/plugin.py
+++ b/neutron/services/segments/plugin.py
@@ -60,6 +60,9 @@ class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase):
60 supported_extension_aliases = ["segment", "ip_allocation", 60 supported_extension_aliases = ["segment", "ip_allocation",
61 l2adj_apidef.ALIAS] 61 l2adj_apidef.ALIAS]
62 62
63 __native_pagination_support = True
64 __native_sorting_support = True
65
63 def __init__(self): 66 def __init__(self):
64 self.nova_updater = NovaSegmentNotifier() 67 self.nova_updater = NovaSegmentNotifier()
65 68
diff --git a/neutron/tests/unit/extensions/test_segment.py b/neutron/tests/unit/extensions/test_segment.py
index fcb6d9f..02b48ef 100644
--- a/neutron/tests/unit/extensions/test_segment.py
+++ b/neutron/tests/unit/extensions/test_segment.py
@@ -347,6 +347,56 @@ class TestSegment(SegmentTestCase):
347 res = self._list('segments') 347 res = self._list('segments')
348 self.assertEqual(2, len(res['segments'])) 348 self.assertEqual(2, len(res['segments']))
349 349
350 def test_list_segments_with_sort(self):
351 with self.network() as network:
352 network = network['network']
353 s1 = self._test_create_segment(network_id=network['id'],
354 physical_network='phys_net1',
355 segmentation_id=200)
356 s2 = self._test_create_segment(network_id=network['id'],
357 physical_network='phys_net2',
358 segmentation_id=201)
359 self._test_list_with_sort('segment',
360 (s2, s1),
361 [('physical_network', 'desc')],
362 query_params='network_id=%s' % network['id'])
363
364 def test_list_segments_with_pagination(self):
365 with self.network() as network:
366 network = network['network']
367 s1 = self._test_create_segment(network_id=network['id'],
368 physical_network='phys_net1',
369 segmentation_id=200)
370 s2 = self._test_create_segment(network_id=network['id'],
371 physical_network='phys_net2',
372 segmentation_id=201)
373 s3 = self._test_create_segment(network_id=network['id'],
374 physical_network='phys_net3',
375 segmentation_id=202)
376 self._test_list_with_pagination(
377 'segment',
378 (s1, s2, s3),
379 ('physical_network', 'asc'), 2, 2,
380 query_params='network_id=%s' % network['id'])
381
382 def test_list_segments_with_pagination_reverse(self):
383 with self.network() as network:
384 network = network['network']
385 s1 = self._test_create_segment(network_id=network['id'],
386 physical_network='phys_net1',
387 segmentation_id=200)
388 s2 = self._test_create_segment(network_id=network['id'],
389 physical_network='phys_net2',
390 segmentation_id=201)
391 s3 = self._test_create_segment(network_id=network['id'],
392 physical_network='phys_net3',
393 segmentation_id=202)
394 self._test_list_with_pagination_reverse(
395 'segment',
396 (s1, s2, s3),
397 ('physical_network', 'asc'), 2, 2,
398 query_params='network_id=%s' % network['id'])
399
350 def test_update_segments(self): 400 def test_update_segments(self):
351 with self.network() as network: 401 with self.network() as network:
352 net = network['network'] 402 net = network['network']