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):