From 90f60060ee3d8559a3ab3f50f49a9dcda7399d68 Mon Sep 17 00:00:00 2001 From: gongysh Date: Wed, 24 Oct 2012 16:13:09 +0800 Subject: [PATCH] Delete the child object via setting the parent's attribute to None. Bug #1070335 We should not operate the foreigh key attribute of parent attribute directly. Change-Id: I98dc8eae78fdf67f0e7189e73afba77c6affcc0e --- quantum/db/l3_db.py | 2 +- quantum/tests/unit/test_l3_plugin.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/quantum/db/l3_db.py b/quantum/db/l3_db.py index 6585733ad..d03d9501d 100644 --- a/quantum/db/l3_db.py +++ b/quantum/db/l3_db.py @@ -186,7 +186,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): # figure out if we need to delete existing port if gw_port and gw_port['network_id'] != network_id: with context.session.begin(subtransactions=True): - router.update({'gw_port_id': None}) + router.gw_port = None context.session.add(router) self.delete_port(context.elevated(), gw_port['id'], l3_port_check=False) diff --git a/quantum/tests/unit/test_l3_plugin.py b/quantum/tests/unit/test_l3_plugin.py index 29ca27d9f..6482a9f3e 100644 --- a/quantum/tests/unit/test_l3_plugin.py +++ b/quantum/tests/unit/test_l3_plugin.py @@ -574,6 +574,30 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase): gw_info = body['router']['external_gateway_info'] self.assertEquals(gw_info, None) + def test_router_update_gateway(self): + with self.router() as r: + with self.subnet() as s1: + with self.subnet() as s2: + self._set_net_external(s1['subnet']['network_id']) + self._add_external_gateway_to_router( + r['router']['id'], + s1['subnet']['network_id']) + body = self._show('routers', r['router']['id']) + net_id = (body['router'] + ['external_gateway_info']['network_id']) + self.assertEquals(net_id, s1['subnet']['network_id']) + self._set_net_external(s2['subnet']['network_id']) + self._add_external_gateway_to_router( + r['router']['id'], + s2['subnet']['network_id']) + body = self._show('routers', r['router']['id']) + net_id = (body['router'] + ['external_gateway_info']['network_id']) + self.assertEquals(net_id, s2['subnet']['network_id']) + self._remove_external_gateway_from_router( + r['router']['id'], + s2['subnet']['network_id']) + def test_router_add_gateway_invalid_network(self): with self.router() as r: self._add_external_gateway_to_router( -- 2.45.2