@@ -277,51 +277,48 @@ def update_port_postcommit(self, context):
277277 anymore, hence there is no way for us to identify which baremetal port
278278 needs cleanup.
279279
280- Only in the update_port_postcommit we have access to the original context,
281- from which we can access the binding information.
280+ Only in the update_port_postcommit do we have access to the original
281+ context, from which we can access the binding information.
282282
283283 # TODO: garbage collection of unused VLAN-type network segments. We
284284 # create these dynamic segments on the fly so they might get left behind
285285 # as the ports dissappear. If a VLAN is left in a cabinet with nobody
286286 # using it, it can be deleted.
287287 """
288- if (
289- context .current ["binding:vnic_type" ] == "baremetal"
290- and context .vif_type == portbindings .VIF_TYPE_UNBOUND
291- and context .original_vif_type == portbindings .VIF_TYPE_OTHER
292- ):
293- network_id = context .current ["network_id" ]
294- trunk_details = context .current .get ("trunk_details" , {})
295- connected_interface_uuid = utils .fetch_connected_interface_uuid (
296- context .original ["binding:profile" ], LOG
297- )
288+ vlan_group_name = self ._vlan_group_name (context )
298289
299- networks_to_remove = set (self ._fetch_subports_network_ids (trunk_details ))
300- networks_to_remove .add (network_id )
290+ baremetal_vnic = context .current ["binding:vnic_type" ] == "baremetal"
291+ current_vif_unbound = context .vif_type == portbindings .VIF_TYPE_UNBOUND
292+ original_vif_other = context .original_vif_type == portbindings .VIF_TYPE_OTHER
293+ current_vif_other = context .vif_type == portbindings .VIF_TYPE_OTHER
301294
302- LOG .debug (
303- "update_port_postcommit removing vlans %s from interface %s " ,
304- networks_to_remove ,
305- connected_interface_uuid ,
306- )
295+ if baremetal_vnic and current_vif_unbound and original_vif_other :
296+ self ._tenant_network_port_cleanup (context )
297+ elif current_vif_other and vlan_group_name :
298+ self .invoke_undersync (vlan_group_name )
307299
308- self .nb .remove_port_network_associations (
309- connected_interface_uuid , networks_to_remove
310- )
300+ def _tenant_network_port_cleanup (self , context : PortContext ):
301+ network_id = context .current ["network_id" ]
302+ trunk_details = context .current .get ("trunk_details" , {})
303+ connected_interface_uuid = utils .fetch_connected_interface_uuid (
304+ context .original ["binding:profile" ], LOG
305+ )
306+
307+ networks_to_remove = set (self ._fetch_subports_network_ids (trunk_details ))
308+ networks_to_remove .add (network_id )
309+
310+ # TODO: does this needs to clean up subports too?
311311
312- # Run undersync on every possible port operation. If this transpires to
313- # be causing too much unnecessary work, we can always make this
314- # conditional based on what appears to have changed in the provided
315- # context versus the "original".
316- vlan_group_name = self ._vlan_group_name (context )
317312 LOG .debug (
318- "update_port_postcommit vlan_group=%s vif_type=%s" ,
319- vlan_group_name ,
320- context .vif_type ,
313+ "update_port_postcommit removing vlans %s from interface %s " ,
314+ networks_to_remove ,
315+ connected_interface_uuid ,
316+ )
317+
318+ self .nb .remove_port_network_associations (
319+ connected_interface_uuid , networks_to_remove
321320 )
322321 # TODO: also call this in the case above, i.e. previos vif type was other and current vif type is unbound.
323- if vlan_group_name and context .vif_type == portbindings .VIF_TYPE_OTHER :
324- self .invoke_undersync (vlan_group_name )
325322
326323 def delete_port_precommit (self , context ):
327324 pass
0 commit comments