From f639788c59c8bbb5c6a08c7f193fd1d23c7ce956 Mon Sep 17 00:00:00 2001 From: openstack Date: Fri, 26 Apr 2013 14:31:06 +0200 Subject: [PATCH] Fix port_id filter not honored Add dict. to map API params to DB columns Change-Id: I5f10eea77533e91afeb690e39301d7282e1b1620 Fixes: bug #1169706 --- quantum/db/l3_db.py | 10 ++++++++++ quantum/tests/unit/test_l3_plugin.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/quantum/db/l3_db.py b/quantum/db/l3_db.py index 953756ac72..b5cc2c086f 100644 --- a/quantum/db/l3_db.py +++ b/quantum/db/l3_db.py @@ -43,6 +43,11 @@ DEVICE_OWNER_ROUTER_INTF = l3_constants.DEVICE_OWNER_ROUTER_INTF DEVICE_OWNER_ROUTER_GW = l3_constants.DEVICE_OWNER_ROUTER_GW DEVICE_OWNER_FLOATINGIP = l3_constants.DEVICE_OWNER_FLOATINGIP +# Maps API field to DB column +# API parameter name and Database column names may differ. +# Useful to keep the filtering between API and Database. +API_TO_DB_COLUMN_MAP = {'port_id': 'fixed_port_id'} + class Router(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): """Represents a v2 quantum router.""" @@ -713,6 +718,11 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): page_reverse=False): marker_obj = self._get_marker_obj(context, 'floatingip', limit, marker) + if filters is not None: + for key, val in API_TO_DB_COLUMN_MAP.iteritems(): + if key in filters: + filters[val] = filters.pop(key) + return self._get_collection(context, FloatingIP, self._make_floatingip_dict, filters=filters, fields=fields, diff --git a/quantum/tests/unit/test_l3_plugin.py b/quantum/tests/unit/test_l3_plugin.py index 0152830fac..47d7b74350 100644 --- a/quantum/tests/unit/test_l3_plugin.py +++ b/quantum/tests/unit/test_l3_plugin.py @@ -1328,6 +1328,15 @@ class L3NatDBTestCase(L3NatTestCaseBase): self._delete('floatingips', fp2['floatingip']['id']) self._delete('floatingips', fp3['floatingip']['id']) + def test_floatingip_list_with_port_id(self): + with self.floatingip_with_assoc() as fip: + port_id = fip['floatingip']['port_id'] + res = self._list('floatingips', + query_params="port_id=%s" % port_id) + self.assertEqual(len(res['floatingips']), 1) + res = self._list('floatingips', query_params="port_id=aaa") + self.assertEqual(len(res['floatingips']), 0) + def test_floatingip_list_with_pagination(self): with contextlib.nested(self.subnet(cidr="10.0.0.0/24"), self.subnet(cidr="11.0.0.0/24"),