@@ -253,6 +253,9 @@ def subscribe(self):
253253 registry .subscribe (self ._create_security_group ,
254254 resources .SECURITY_GROUP ,
255255 events .AFTER_CREATE )
256+ registry .subscribe (self ._delete_security_group_precommit ,
257+ resources .SECURITY_GROUP ,
258+ events .PRECOMMIT_DELETE )
256259 registry .subscribe (self ._delete_security_group ,
257260 resources .SECURITY_GROUP ,
258261 events .AFTER_DELETE )
@@ -265,9 +268,6 @@ def subscribe(self):
265268 registry .subscribe (self ._process_sg_rule_notification ,
266269 resources .SECURITY_GROUP_RULE ,
267270 events .BEFORE_DELETE )
268- registry .subscribe (self ._process_sg_rule_after_del_notification ,
269- resources .SECURITY_GROUP_RULE ,
270- events .AFTER_DELETE )
271271
272272 def _clean_hash_ring (self , * args , ** kwargs ):
273273 admin_context = n_context .get_admin_context ()
@@ -384,6 +384,14 @@ def _create_security_group(self, resource, event, trigger, payload):
384384 self ._ovn_client .create_security_group (context ,
385385 security_group )
386386
387+ def _delete_security_group_precommit (self , resource , event , trigger ,
388+ payload ):
389+ context = n_context .get_admin_context ()
390+ security_group_id = payload .resource_id
391+ for sg_rule in self ._plugin .get_security_group_rules (
392+ context , filters = {'remote_group_id' : [security_group_id ]}):
393+ self ._ovn_client .delete_security_group_rule (context , sg_rule )
394+
387395 def _delete_security_group (self , resource , event , trigger , payload ):
388396 context = payload .context
389397 security_group_id = payload .resource_id
@@ -441,12 +449,6 @@ def _process_sg_rule_notification(
441449 context ,
442450 sg_rule )
443451
444- def _process_sg_rule_after_del_notification (
445- self , resource , event , trigger , payload ):
446- context = payload .context
447- sg_rule = payload .metadata ['rule' ]
448- self ._ovn_client .delete_security_group_rule (context , sg_rule )
449-
450452 def _sg_has_rules_with_same_normalized_cidr (self , sg_rule ):
451453 compare_keys = [
452454 'ethertype' , 'direction' , 'protocol' ,
0 commit comments