From 02f3a4cdfcaeb3ad40bba71b26be292e64a1db8c Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Fri, 22 Feb 2013 15:22:36 +0800 Subject: [PATCH] Add pagination parameters for extension extraroute Fixes bug 1131560 Change-Id: Ice84aa90ef8a39efdd9c287cca9b90c4ee355b7f --- quantum/db/extraroute_db.py | 7 +++-- .../tests/unit/test_extension_extraroute.py | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/quantum/db/extraroute_db.py b/quantum/db/extraroute_db.py index 6282cc2119..77e4265609 100644 --- a/quantum/db/extraroute_db.py +++ b/quantum/db/extraroute_db.py @@ -142,10 +142,13 @@ class ExtraRoute_db_mixin(l3_db.L3_NAT_db_mixin): context, id) return router - def get_routers(self, context, filters=None, fields=None): + def get_routers(self, context, filters=None, fields=None, + sorts=None, limit=None, marker=None, + page_reverse=False): with context.session.begin(subtransactions=True): routers = super(ExtraRoute_db_mixin, self).get_routers( - context, filters, fields) + context, filters, fields, sorts=sorts, limit=limit, + marker=marker, page_reverse=page_reverse) for router in routers: router['routes'] = self._get_extra_routes_by_router_id( context, router['id']) diff --git a/quantum/tests/unit/test_extension_extraroute.py b/quantum/tests/unit/test_extension_extraroute.py index f32310a2cd..73eb5d800c 100644 --- a/quantum/tests/unit/test_extension_extraroute.py +++ b/quantum/tests/unit/test_extension_extraroute.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +import contextlib from oslo.config import cfg from webob import exc @@ -447,3 +448,30 @@ class ExtraRouteDBTestCase(test_l3.L3NatDBTestCase): body = self._show('routers', r['router']['id']) gw_info = body['router']['external_gateway_info'] self.assertEquals(gw_info, None) + + def test_router_list_with_sort(self): + with contextlib.nested(self.router(name='router1'), + self.router(name='router2'), + self.router(name='router3') + ) as (router1, router2, router3): + self._test_list_with_sort('router', (router3, router2, router1), + [('name', 'desc')]) + + def test_router_list_with_pagination(self): + with contextlib.nested(self.router(name='router1'), + self.router(name='router2'), + self.router(name='router3') + ) as (router1, router2, router3): + self._test_list_with_pagination('router', + (router1, router2, router3), + ('name', 'asc'), 2, 2) + + def test_router_list_with_pagination_reverse(self): + with contextlib.nested(self.router(name='router1'), + self.router(name='router2'), + self.router(name='router3') + ) as (router1, router2, router3): + self._test_list_with_pagination_reverse('router', + (router1, router2, + router3), + ('name', 'asc'), 2, 2)