ML2: Fix release of network segments to allocation pools

The recent merge of https://review.openstack.org/#/c/115025/ broke the
release of network segments to allocation pools on network delete,
resulting in network creates eventually failing with
NoNetworkAvailable exceptions. The network_delete() code is rearranged
to properly release the network segments, and a unit test is updated
to verify that the type drivers' release_segment() method is called.

Partially implements: Blueprint ml2-type-driver-refactor

Change-Id: Ica5f11b2012dedfcc097f34f1515f5f3ca208fd2
This commit is contained in:
Robert Kukura 2014-09-01 07:27:10 -04:00
parent f3305bbd7e
commit 335caab8ef
2 changed files with 7 additions and 3 deletions

View File

@ -612,10 +612,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
self.mechanism_manager.delete_network_precommit(
mech_context)
self.type_manager.release_network_segments(session, id)
record = self._get_network(context, id)
LOG.debug(_("Deleting network record %s"), record)
session.delete(record)
self.type_manager.release_network_segments(session, id)
# The segment records are deleted via cascade from the
# network record, so explicit removal is not necessary.

View File

@ -33,6 +33,7 @@ from neutron.plugins.ml2 import config
from neutron.plugins.ml2 import db as ml2_db
from neutron.plugins.ml2 import driver_api
from neutron.plugins.ml2 import driver_context
from neutron.plugins.ml2.drivers import type_vlan
from neutron.plugins.ml2 import plugin as ml2_plugin
from neutron.tests.unit import _test_extension_portbindings as test_bindings
from neutron.tests.unit.ml2.drivers import mechanism_logger as mech_logger
@ -590,8 +591,11 @@ class TestMultiSegmentNetworks(Ml2PluginV2TestCase):
dynamic_segment[driver_api.PHYSICAL_NETWORK])
self.assertTrue(dynamic_segment[driver_api.SEGMENTATION_ID] > 0)
req = self.new_delete_request('networks', network_id)
res = req.get_response(self.api)
with mock.patch.object(type_vlan.VlanTypeDriver,
'release_segment') as rs:
req = self.new_delete_request('networks', network_id)
res = req.get_response(self.api)
self.assertEqual(2, rs.call_count)
self.assertEqual(ml2_db.get_network_segments(
self.context.session, network_id), [])
self.assertIsNone(ml2_db.get_dynamic_segment(