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
This commit is contained in:
gongysh
2012-10-24 16:13:09 +08:00
parent a5c1c89aa1
commit 90f60060ee
2 changed files with 25 additions and 1 deletions

View File

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

View File

@@ -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(