Disable pubsub when getting nb_api in external apps

The pubsub creates different problems, and every external app
specifically disables it before getting the nb_api instance.
We should hide this behaviour inside the get_instance method.
Also, I called the argument is_external_app as in the future we may want
to add more behavioural differences between the cases.

Change-Id: I25a55737351f8fe14bddafa7c78e60fe096db43e
This commit is contained in:
Shachar Snapiri 2018-02-19 17:00:36 +02:00
parent 95fedab302
commit c33a4953c2
5 changed files with 11 additions and 11 deletions

View File

@ -179,7 +179,7 @@ def add_object_from_json(json_str, table):
:param table: table name where object should be added
:return: None
"""
nb_api = api_nb.NbApi.get_instance(False)
nb_api = api_nb.NbApi.get_instance(False, True)
try:
model = model_framework.get_model(table)
except KeyError:

View File

@ -81,8 +81,7 @@ def main():
config.init(sys.argv[1:])
config.setup_logging()
environment_setup()
cfg.CONF.set_override('enable_df_pub_sub', False, group='df')
nb_api = api_nb.NbApi.get_instance(False)
nb_api = api_nb.NbApi.get_instance(False, True)
service_instance = metadata_service.DFMetadataProxyHandler(
cfg.CONF, nb_api)
df_service.register_service(

View File

@ -165,10 +165,7 @@ class BGPService(service.Service):
def main():
df_config.init(sys.argv)
# BGP dynamic route is not a service that needs real time response.
# So disable pubsub here and use period task to do BGP job.
cfg.CONF.set_override('enable_df_pub_sub', False, group='df')
nb_api = api_nb.NbApi.get_instance(False)
nb_api = api_nb.NbApi.get_instance(False, True)
server = BGPService(nb_api)
df_service.register_service('df-bgp-service', nb_api, server)
service.launch(cfg.CONF, server).wait()

View File

@ -147,8 +147,7 @@ class PublisherService(object):
def main():
df_config.init(sys.argv)
cfg.CONF.set_override('enable_df_pub_sub', False, group='df')
nb_api = api_nb.NbApi.get_instance(False)
nb_api = api_nb.NbApi.get_instance(False, True)
service = PublisherService(nb_api)
df_service.register_service('df-publisher-service', nb_api, service)
service.initialize()

View File

@ -60,15 +60,20 @@ class NbApi(object):
self.pub_sub_use_multiproc = cfg.CONF.df.pub_sub_use_multiproc
@staticmethod
def get_instance(is_neutron_server):
def get_instance(is_neutron_server, is_external_app=False):
global _nb_api
if _nb_api is None:
nb_driver = df_utils.load_driver(
cfg.CONF.df.nb_db_class,
df_utils.DF_NB_DB_DRIVER_NAMESPACE)
# Do not use pubsub for external apps - this causes issues with
# threads and other issues.
use_pubsub = cfg.CONF.df.enable_df_pub_sub
if is_external_app:
use_pubsub = False
nb_api = NbApi(
nb_driver,
use_pubsub=cfg.CONF.df.enable_df_pub_sub,
use_pubsub=use_pubsub,
is_neutron_server=is_neutron_server)
nb_api.initialize(db_ip=cfg.CONF.df.remote_db_ip,
db_port=cfg.CONF.df.remote_db_port)