@@ -95,9 +95,13 @@ def setUp(self):
9595 super ().setUp ()
9696 self .get_plugin = mock .patch (
9797 'neutron_lib.plugins.directory.get_plugin' ).start ()
98+ self .get_pb_bsah = mock .patch (
99+ 'neutron_lib.plugins.utils.'
100+ 'get_port_binding_by_status_and_host' ).start ()
98101
99102 # Disable tenacity wait for UT
100- self .ovn_client ._wait_for_port_bindings_host .retry .wait = wait_none ()
103+ self .ovn_client ._wait_for_active_port_bindings_host .retry .wait = (
104+ wait_none ())
101105
102106 def test__add_router_ext_gw_default_route (self ):
103107 plugin = mock .MagicMock ()
@@ -245,8 +249,9 @@ def test_update_lsp_host_info_up(self):
245249 context = mock .MagicMock ()
246250 host_id = 'fake-binding-host-id'
247251 port_id = 'fake-port-id'
248- db_port = mock .Mock (
249- id = port_id , port_bindings = [mock .Mock (host = host_id )])
252+ port_binding = mock .Mock (host = host_id )
253+ db_port = mock .Mock (id = port_id , port_bindings = [port_binding ])
254+ self .get_pb_bsah .return_value = port_binding
250255
251256 self .ovn_client .update_lsp_host_info (context , db_port )
252257
@@ -258,14 +263,16 @@ def test_update_lsp_host_info_up_retry(self):
258263 context = mock .MagicMock ()
259264 host_id = 'fake-binding-host-id'
260265 port_id = 'fake-port-id'
266+ port_binding = mock .Mock (host = host_id )
267+ port_binding_no_host = mock .Mock (host = "" )
261268 db_port_no_host = mock .Mock (
262- id = port_id , port_bindings = [mock .Mock (host = "" )])
263- db_port = mock .Mock (
264- id = port_id , port_bindings = [mock .Mock (host = host_id )])
269+ id = port_id , port_bindings = [port_binding_no_host ])
270+ self .get_pb_bsah .return_value = None
265271
266272 with mock .patch .object (
267- self .ovn_client , '_wait_for_port_bindings_host' ) as mock_wait :
268- mock_wait .return_value = db_port
273+ self .ovn_client ,
274+ '_wait_for_active_port_bindings_host' ) as mock_wait :
275+ mock_wait .return_value = port_binding
269276 self .ovn_client .update_lsp_host_info (context , db_port_no_host )
270277
271278 # Assert _wait_for_port_bindings_host was called
@@ -281,9 +288,11 @@ def test_update_lsp_host_info_up_retry_fail(self):
281288 port_id = 'fake-port-id'
282289 db_port_no_host = mock .Mock (
283290 id = port_id , port_bindings = [mock .Mock (host = "" )])
291+ self .get_pb_bsah .return_value = None
284292
285293 with mock .patch .object (
286- self .ovn_client , '_wait_for_port_bindings_host' ) as mock_wait :
294+ self .ovn_client ,
295+ '_wait_for_active_port_bindings_host' ) as mock_wait :
287296 mock_wait .side_effect = RuntimeError ("boom" )
288297 self .ovn_client .update_lsp_host_info (context , db_port_no_host )
289298
@@ -315,39 +324,45 @@ def test_update_lsp_host_info_trunk_subport(self):
315324 self .nb_idl .db_set .assert_not_called ()
316325
317326 @mock .patch .object (ml2_db , 'get_port' )
318- def test__wait_for_port_bindings_host (self , mock_get_port ):
327+ def test__wait_for_active_port_bindings_host (self , mock_get_port ):
319328 context = mock .MagicMock ()
320329 host_id = 'fake-binding-host-id'
321330 port_id = 'fake-port-id'
331+ port_binding = mock .Mock (host = host_id )
332+ port_binding_no_host = mock .Mock (host = "" )
322333 db_port_no_host = mock .Mock (
323- id = port_id , port_bindings = [mock . Mock ( host = "" ) ])
334+ id = port_id , port_bindings = [port_binding_no_host ])
324335 db_port = mock .Mock (
325- id = port_id , port_bindings = [mock .Mock (host = host_id )])
336+ id = port_id , port_bindings = [port_binding ])
337+ # no active binding, no binding with host, binding with host
338+ self .get_pb_bsah .side_effect = (None , port_binding_no_host ,
339+ port_binding )
326340
327- mock_get_port .side_effect = (db_port_no_host , db_port )
341+ mock_get_port .side_effect = (db_port_no_host , db_port_no_host , db_port )
328342
329- ret = self .ovn_client ._wait_for_port_bindings_host (
343+ ret = self .ovn_client ._wait_for_active_port_bindings_host (
330344 context , port_id )
331345
332- self .assertEqual (ret , db_port )
346+ self .assertEqual (ret , port_binding )
333347
334348 expected_calls = [mock .call (context , port_id ),
335349 mock .call (context , port_id )]
336350 mock_get_port .assert_has_calls (expected_calls )
337351
338352 @mock .patch .object (ml2_db , 'get_port' )
339- def test__wait_for_port_bindings_host_fail (self , mock_get_port ):
353+ def test__wait_for_active_port_bindings_host_fail (self , mock_get_port ):
340354 context = mock .MagicMock ()
341355 port_id = 'fake-port-id'
342356 db_port_no_pb = mock .Mock (id = port_id , port_bindings = [])
343357 db_port_no_host = mock .Mock (
344358 id = port_id , port_bindings = [mock .Mock (host = "" )])
359+ self .get_pb_bsah .return_value = None
345360
346361 mock_get_port .side_effect = (
347362 db_port_no_pb , db_port_no_host , db_port_no_host )
348363
349364 self .assertRaises (
350- RuntimeError , self .ovn_client ._wait_for_port_bindings_host ,
365+ RuntimeError , self .ovn_client ._wait_for_active_port_bindings_host ,
351366 context , port_id )
352367
353368 expected_calls = [mock .call (context , port_id ),
0 commit comments