From d1220a3c22fccc1d86eaafeebe7ef9c074d4fcb9 Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Tue, 12 Nov 2013 19:05:26 +0400 Subject: [PATCH] Fix MeteringLabel model to not clear router's tenant id on deletion foreign_keys parameter of orm.relationship should point to local columns. Currently for MeteringLabel it points to Router.tenant_id column which causes routers tenant_id clearing on label deletion. Closes-Bug: #1249188 Change-Id: Iccc0daf4f6edd537fd7f9e4b2fc4be094543ca5d --- neutron/db/metering/metering_db.py | 3 ++- .../unit/services/metering/test_metering_plugin.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/neutron/db/metering/metering_db.py b/neutron/db/metering/metering_db.py index 8bdaa7c0c..e97d90ea5 100644 --- a/neutron/db/metering/metering_db.py +++ b/neutron/db/metering/metering_db.py @@ -52,7 +52,8 @@ class MeteringLabel(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): routers = orm.relationship( l3_db.Router, primaryjoin="MeteringLabel.tenant_id==Router.tenant_id", - foreign_keys='Router.tenant_id') + foreign_keys='MeteringLabel.tenant_id', + uselist=True) class MeteringDbMixin(metering.MeteringPluginBase, diff --git a/neutron/tests/unit/services/metering/test_metering_plugin.py b/neutron/tests/unit/services/metering/test_metering_plugin.py index ac250fcce..7644e3db4 100644 --- a/neutron/tests/unit/services/metering/test_metering_plugin.py +++ b/neutron/tests/unit/services/metering/test_metering_plugin.py @@ -248,6 +248,18 @@ class TestMeteringPlugin(test_db_plugin.NeutronDbPluginV2TestCase, expected_del, topic=self.topic) + def test_delete_metering_label_does_not_clear_router_tenant_id(self): + tenant_id = '654f6b9d-0f36-4ae5-bd1b-01616794ca60' + with self.metering_label(tenant_id=tenant_id, + no_delete=True) as metering_label: + with self.router(tenant_id=tenant_id, set_context=True) as r: + router = self._show('routers', r['router']['id']) + self.assertEqual(tenant_id, router['router']['tenant_id']) + metering_label_id = metering_label['metering_label']['id'] + self._delete('metering-labels', metering_label_id, 204) + router = self._show('routers', r['router']['id']) + self.assertEqual(tenant_id, router['router']['tenant_id']) + class TestRouteIntPlugin(l3_agentschedulers_db.L3AgentSchedulerDbMixin, test_l3_plugin.TestL3NatIntPlugin):