Browse Source

Merge "Improve Network delete performance" into stable/ussuri

changes/16/790916/1
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
eda3c1f5df
4 changed files with 19 additions and 8 deletions
  1. +2
    -1
      neutron/db/db_base_plugin_v2.py
  2. +9
    -3
      neutron/plugins/ml2/plugin.py
  3. +6
    -3
      neutron/services/segments/db.py
  4. +2
    -1
      neutron/tests/unit/extensions/test_segment.py

+ 2
- 1
neutron/db/db_base_plugin_v2.py View File

@ -502,7 +502,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
network_db = self._get_network(context, id)
network = self._make_network_dict(network_db, context=context)
registry.notify(resources.NETWORK, events.PRECOMMIT_DELETE,
self, context=context, network_id=id)
self, context=context, network_id=id,
network=network)
# We expire network_db here because precommit deletion
# might have left the relationship stale, for example,
# if we deleted a segment.


+ 9
- 3
neutron/plugins/ml2/plugin.py View File

@ -1186,7 +1186,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
priority=0)
def _network_delete_precommit_handler(self, rtype, event, trigger,
context, network_id, **kwargs):
network = self.get_network(context, network_id)
network = (kwargs.get('network') or
self.get_network(context, network_id))
mech_context = driver_context.NetworkContext(self,
context,
network)
@ -2256,12 +2257,14 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
# TODO(boden); refactor into _handle_segment_change once all
# event types use payloads
return self._handle_segment_change(
rtype, event, trigger, payload.context, payload.latest_state)
rtype, event, trigger, payload.context, payload.latest_state,
for_net_delete=payload.metadata.get('for_net_delete'))
@registry.receives(resources.SEGMENT, (events.PRECOMMIT_CREATE,
events.PRECOMMIT_DELETE,
events.AFTER_CREATE))
def _handle_segment_change(self, rtype, event, trigger, context, segment):
def _handle_segment_change(self, rtype, event, trigger, context, segment,
for_net_delete=False):
if (event == events.PRECOMMIT_CREATE and
not isinstance(trigger, segments_plugin.Plugin)):
# TODO(xiaohhui): Now, when create network, ml2 will reserve
@ -2282,6 +2285,9 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
elif event == events.PRECOMMIT_DELETE:
self.type_manager.release_network_segment(context, segment)
if for_net_delete:
return
# change in segments could affect resulting network mtu, so let's
# recalculate it
network_db = self._get_network(context, network_id)


+ 6
- 3
neutron/services/segments/db.py View File

@ -201,12 +201,15 @@ class SegmentDbMixin(object):
# Do some preliminary operations before deleting segment in db
registry.notify(resources.SEGMENT, events.PRECOMMIT_DELETE,
self.delete_segment, context=context,
segment=segment_dict)
segment=segment_dict,
for_net_delete=for_net_delete)
registry.publish(resources.SEGMENT, events.AFTER_DELETE,
self.delete_segment,
payload=events.DBEventPayload(
context, states=(segment_dict,),
context, metadata={
FOR_NET_DELETE: for_net_delete},
states=(segment_dict,),
resource_id=uuid))
@ -332,7 +335,7 @@ def _add_segment_host_mapping_for_segment(resource, event, trigger,
def _delete_segments_for_network(resource, event, trigger,
context, network_id):
context, network_id, **kwargs):
admin_ctx = context.elevated()
global segments_plugin
if not segments_plugin:


+ 2
- 1
neutron/tests/unit/extensions/test_segment.py View File

@ -419,7 +419,8 @@ class TestSegment(SegmentTestCase):
events.PRECOMMIT_DELETE,
mock.ANY,
context=mock.ANY,
network_id=mock.ANY)
network_id=mock.ANY,
network=mock.ANY)
class TestSegmentML2(SegmentTestCase):


Loading…
Cancel
Save