Merge "Skip segment checks during network delete operations"

This commit is contained in:
Jenkins 2017-02-22 09:29:24 +00:00 committed by Gerrit Code Review
commit c9f83dcaa8
3 changed files with 14 additions and 5 deletions

View File

@ -291,8 +291,12 @@ def is_dhcp_active_on_any_subnet(context, subnet_ids):
def _prevent_segment_delete_with_port_bound(resource, event, trigger,
context, segment):
context, segment,
for_net_delete=False):
"""Raise exception if there are any ports bound with segment_id."""
if for_net_delete:
# don't check for network deletes
return
segment_id = segment['id']
query = context.session.query(models_v2.Port)
query = query.join(

View File

@ -169,13 +169,13 @@ class SegmentDbMixin(common_db_mixin.CommonDbMixin):
return list({mapping.segment_id for mapping in segment_host_mapping})
@log_helpers.log_method_call
def delete_segment(self, context, uuid):
def delete_segment(self, context, uuid, for_net_delete=False):
"""Delete an existing segment."""
segment = self.get_segment(context, uuid)
# Do some preliminary operations before deleting the segment
registry.notify(resources.SEGMENT, events.BEFORE_DELETE,
self.delete_segment, context=context,
segment=segment)
segment=segment, for_net_delete=for_net_delete)
# Delete segment in DB
with context.session.begin(subtransactions=True):
@ -312,7 +312,8 @@ def _delete_segments_for_network(resource, event, trigger,
segments = segments_plugin.get_segments(
admin_ctx, filters={'network_id': [network_id]})
for segment in segments:
segments_plugin.delete_segment(admin_ctx, segment['id'])
segments_plugin.delete_segment(admin_ctx, segment['id'],
for_net_delete=True)
def subscribe():

View File

@ -98,8 +98,12 @@ class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase):
return cls._instance
def _prevent_segment_delete_with_subnet_associated(
self, resource, event, trigger, context, segment):
self, resource, event, trigger, context, segment,
for_net_delete=False):
"""Raise exception if there are any subnets associated with segment."""
if for_net_delete:
# don't check if this is a part of a network delete operation
return
segment_id = segment['id']
query = context.session.query(models_v2.Subnet.id)
query = query.filter(models_v2.Subnet.segment_id == segment_id)