@@ -267,7 +267,7 @@ def _get_port_dhcp_options(self, port, ip_version):
267267 wait = tenacity .wait_random (min = 2 , max = 3 ),
268268 stop = tenacity .stop_after_attempt (3 ),
269269 reraise = True )
270- def _wait_for_port_bindings_host (self , context , port_id ):
270+ def _wait_for_active_port_bindings_host (self , context , port_id ):
271271 db_port = ml2_db .get_port (context , port_id )
272272 # This is already checked previously but, just to stay on
273273 # the safe side in case the port is deleted mid-operation
@@ -280,11 +280,18 @@ def _wait_for_port_bindings_host(self, context, port_id):
280280 _ ('No port bindings information found for '
281281 'port %s' ) % port_id )
282282
283- if not db_port .port_bindings [0 ].host :
283+ active_binding = p_utils .get_port_binding_by_status_and_host (
284+ db_port .port_bindings , const .ACTIVE )
285+ if not active_binding :
286+ raise RuntimeError (
287+ _ ('No active port bindings information found for '
288+ 'port %s' ) % port_id )
289+
290+ if not active_binding .host :
284291 raise RuntimeError (
285292 _ ('No hosting information found for port %s' ) % port_id )
286293
287- return db_port
294+ return active_binding
288295
289296 def update_lsp_host_info (self , context , db_port , up = True ):
290297 """Update the binding hosting information for the LSP.
@@ -307,24 +314,29 @@ def update_lsp_host_info(self, context, db_port, up=True):
307314 if up :
308315 if not port_up :
309316 LOG .warning ('Logical_Switch_Port %s host information not '
310- 'updated, the port state is down' )
317+ 'updated, the port state is down' , db_port . id )
311318 return
312319
313320 if not db_port .port_bindings :
314321 return
315322
316- if not db_port .port_bindings [0 ].host :
323+ # There could be more than one port binding present, we need
324+ # to find the active one
325+ active_binding = p_utils .get_port_binding_by_status_and_host (
326+ db_port .port_bindings , const .ACTIVE )
327+
328+ if not active_binding or not active_binding .host :
317329 # NOTE(lucasgomes): There might be a sync issue between
318330 # the moment that this port was fetched from the database
319331 # and the hosting information being set, retry a few times
320332 try :
321- db_port = self ._wait_for_port_bindings_host (
333+ active_binding = self ._wait_for_active_port_bindings_host (
322334 context , db_port .id )
323335 except RuntimeError as e :
324336 LOG .warning (e )
325337 return
326338
327- host = db_port . port_bindings [ 0 ] .host
339+ host = active_binding .host
328340 ext_ids = ('external_ids' ,
329341 {ovn_const .OVN_HOST_ID_EXT_ID_KEY : host })
330342 cmd .append (
@@ -333,7 +345,7 @@ def update_lsp_host_info(self, context, db_port, up=True):
333345 else :
334346 if port_up :
335347 LOG .warning ('Logical_Switch_Port %s host information not '
336- 'removed, the port state is up' )
348+ 'removed, the port state is up' , db_port . id )
337349 return
338350
339351 cmd .append (
0 commit comments