Skip to content

Commit

Permalink
Fix MeteringLabel model to not clear router's tenant id on deletion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleg Bondarev committed Nov 12, 2013
1 parent 1fa79ce commit d1220a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion neutron/db/metering/metering_db.py
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions neutron/tests/unit/services/metering/test_metering_plugin.py
Expand Up @@ -248,6 +248,18 @@ def test_update_metering_label_rules_rpc_call(self):
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):
Expand Down

0 comments on commit d1220a3

Please sign in to comment.