From: Edgar Magana Date: Thu, 29 Aug 2013 23:28:26 +0000 (-0700) Subject: Include call to delete_subnet from delete_network at DB level X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d9966eafe16f2a0e4899a1fa651352ee81858732;p=openstack-build%2Fneutron-build.git Include call to delete_subnet from delete_network at DB level Removes an extra lock in bsn plugin that causes a deadlock when delete_subnet is invoked form delete_network, agreed with kevinbenton to remove it Modifies a unit test to cover this change per reviewer request Co-author amirosh Closes-bug: #1197176 Change-Id: Ie3414848a91cc737b16b79399ae19800545e533f --- diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 70827c58a..bebc8b3c5 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -954,8 +954,10 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, self._delete_port(context, port['id']) # clean up subnets - subnets_qry = context.session.query(models_v2.Subnet) - subnets_qry.filter_by(network_id=id).delete() + subnets = self._get_subnets_by_network(context, id) + for subnet in subnets: + self.delete_subnet(context, subnet['id']) + context.session.delete(network) def get_network(self, context, id, fields=None): diff --git a/neutron/plugins/bigswitch/plugin.py b/neutron/plugins/bigswitch/plugin.py index f7f596127..d7b0b678e 100644 --- a/neutron/plugins/bigswitch/plugin.py +++ b/neutron/plugins/bigswitch/plugin.py @@ -863,8 +863,6 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base, self._send_update_network(orig_net, context) return new_subnet - # NOTE(kevinbenton): workaround for eventlet/mysql deadlock - @utils.synchronized('bsn-port-barrier') @put_context_in_serverpool def delete_subnet(self, context, id): LOG.debug(_("NeutronRestProxyV2: delete_subnet() called")) diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index 8a4f3ec5a..465183fcd 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -2648,10 +2648,14 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): res = self._create_network(fmt=self.fmt, name='net', admin_state_up=True) network = self.deserialize(self.fmt, res) - self._make_subnet(self.fmt, network, gateway_ip, cidr, ip_version=4) + subnet = self._make_subnet(self.fmt, network, gateway_ip, cidr, + ip_version=4) req = self.new_delete_request('networks', network['network']['id']) res = req.get_response(self.api) self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code) + req = self.new_show_request('subnets', subnet['subnet']['id']) + res = req.get_response(self.api) + self.assertEqual(webob.exc.HTTPNotFound.code, res.status_int) def test_create_subnet_bad_tenant(self): with self.network() as network: