@@ -229,25 +229,15 @@ def create_port_postcommit(self, context):
229229 def update_port_precommit (self , context ):
230230 pass
231231
232- def update_port_postcommit (self , context ):
233- """Tenant network port cleanup in the UnderCloud infrastructure.
234-
235- This is triggered in the update_port_postcommit call as in the
236- delete_port_postcommit call there is no binding profile information
237- anymore, hence there is no way for us to identify which baremetal port
238- needs cleanup.
232+ def update_port_postcommit (self , context : PortContext ) -> None :
233+ if utils .is_baremetal_port (context ):
234+ self ._update_port_baremetal (context )
239235
240- Only in the update_port_postcommit do we have access to the original
241- context, from which we can access the binding information.
242- """
243- baremetal_vnic = context .current ["binding:vnic_type" ] == "baremetal"
236+ def _update_port_baremetal (self , context : PortContext ) -> None :
244237 current_vif_unbound = context .vif_type == portbindings .VIF_TYPE_UNBOUND
245238 original_vif_other = context .original_vif_type == portbindings .VIF_TYPE_OTHER
246239 current_vif_other = context .vif_type == portbindings .VIF_TYPE_OTHER
247240
248- if not baremetal_vnic :
249- return
250-
251241 vlan_group_name = self .ironic_client .baremetal_port_physical_network (
252242 context .current ["mac_address" ]
253243 )
@@ -260,6 +250,16 @@ def update_port_postcommit(self, context):
260250 self .invoke_undersync (vlan_group_name )
261251
262252 def _tenant_network_port_cleanup (self , context : PortContext ):
253+ """Tenant network port cleanup in the UnderCloud infrastructure.
254+
255+ This is triggered in the update_port_postcommit call as in the
256+ delete_port_postcommit call there is no binding profile information
257+ anymore, hence there is no way for us to identify which baremetal port
258+ needs cleanup.
259+
260+ Only in the update_port_postcommit do we have access to the original
261+ context, from which we can access the binding information.
262+ """
263263 trunk_details = context .current .get ("trunk_details" , {})
264264 segment_id = context .original_top_bound_segment ["id" ]
265265 original_binding = context .original ["binding:profile" ]
@@ -293,13 +293,13 @@ def _tenant_network_port_cleanup(self, context: PortContext):
293293 def delete_port_precommit (self , context ):
294294 pass
295295
296- def delete_port_postcommit (self , context ) :
297- # Only clean up provisioning ports. Everything else is left to get
298- # cleaned up upon the next change in that cabinet.
296+ def delete_port_postcommit (self , context : PortContext ) -> None :
297+ if utils . is_baremetal_port ( context ):
298+ self . _delete_port_baremetal ( context )
299299
300- baremetal_vnic = context . current [ "binding:vnic_type" ] == "baremetal"
301- if not baremetal_vnic :
302- return
300+ def _delete_port_baremetal ( self , context : PortContext ) -> None :
301+ # Only clean up provisioning ports. Ports with tenant networks are cleaned
302+ # up in _tenant_network_port_cleanup
303303
304304 vlan_group_name = self .ironic_client .baremetal_port_physical_network (
305305 context .current ["mac_address" ]
0 commit comments