33
33
34
34
from neutron .agent .linux import utils
35
35
from neutron .api import extensions as exts
36
+ from neutron .common import utils as n_utils
36
37
from neutron .conf .agent import common as config
37
38
from neutron .conf .agent import ovs_conf
38
39
from neutron .conf .plugins .ml2 import config as ml2_config
@@ -276,6 +277,28 @@ def get_ovsdb_server_protocol(self):
276
277
def _start_ovn_northd (self ):
277
278
if not self .ovsdb_server_mgr :
278
279
return
280
+
281
+ def wait_for_northd ():
282
+ try :
283
+ self .nb_api .nb_global
284
+ except StopIteration :
285
+ LOG .debug ("NB_Global is not ready yet" )
286
+ return False
287
+
288
+ try :
289
+ next (iter (self .sb_api .db_list_rows ('SB_Global' ).execute (
290
+ check_error = True )))
291
+ except StopIteration :
292
+ LOG .debug ("SB_Global is not ready yet" )
293
+ return False
294
+ except KeyError :
295
+ # Maintenance worker doesn't register SB_Global therefore
296
+ # we don't need to wait for it
297
+ LOG .debug ("SB_Global is not registered in this IDL" )
298
+
299
+ return True
300
+
301
+ timeout = 20
279
302
ovn_nb_db = self .ovsdb_server_mgr .get_ovsdb_connection_path ('nb' )
280
303
ovn_sb_db = self .ovsdb_server_mgr .get_ovsdb_connection_path ('sb' )
281
304
LOG .debug ("Starting OVN northd" )
@@ -284,6 +307,11 @@ def _start_ovn_northd(self):
284
307
ovn_nb_db , ovn_sb_db ,
285
308
protocol = self ._ovsdb_protocol ))
286
309
LOG .debug ("OVN northd started: %r" , self .ovn_northd_mgr )
310
+ n_utils .wait_until_true (
311
+ wait_for_northd , timeout , sleep = 1 ,
312
+ exception = Exception (
313
+ "ovn-northd didn't initialize OVN DBs in %d"
314
+ "seconds" % timeout ))
287
315
288
316
def _start_ovsdb_server (self ):
289
317
# Start 2 ovsdb-servers one each for OVN NB DB and OVN SB DB
0 commit comments