diff --git a/gbpservice/neutron/tests/unit/nfp/config_orchestrator/modules/test_config_orch.py b/gbpservice/neutron/tests/unit/nfp/config_orchestrator/modules/test_config_orch.py index eafcf1e157..1f6b4adbc8 100644 --- a/gbpservice/neutron/tests/unit/nfp/config_orchestrator/modules/test_config_orch.py +++ b/gbpservice/neutron/tests/unit/nfp/config_orchestrator/modules/test_config_orch.py @@ -141,8 +141,7 @@ def verify_loadbalancer_structure(self, blob_data, resource): if context['service_info']: data = context['service_info'] if all(k in data for k in ["pools", "vips", "members", - "health_monitors", - "subnets", "ports"]): + "health_monitors"]): return True except AttributeError: return False diff --git a/gbpservice/nfp/config_orchestrator/modules/config_orch.py b/gbpservice/nfp/config_orchestrator/modules/config_orch.py index 7b8d412bb3..72c914e32e 100644 --- a/gbpservice/nfp/config_orchestrator/modules/config_orch.py +++ b/gbpservice/nfp/config_orchestrator/modules/config_orch.py @@ -18,8 +18,6 @@ from gbpservice.nfp.config_orchestrator.handlers.config import ( loadbalancerv2 as lbv2) from gbpservice.nfp.config_orchestrator.handlers.config import vpn -from gbpservice.nfp.config_orchestrator.handlers.event import ( - handler as v_handler) from gbpservice.nfp.config_orchestrator.handlers.notification import ( handler as notif_handler) @@ -107,22 +105,11 @@ def rpc_init(sc, conf): sc.register_rpc_agents([fwagent, lbagent, lbv2agent, vpnagent, rpcagent]) -def events_init(sc, conf): - """Register event with its handler.""" - evs = v_handler.event_init(sc, conf) - sc.register_events(evs) - - def nfp_module_init(sc, conf): rpc_init(sc, conf) - events_init(sc, conf) def nfp_module_post_init(sc, conf): - ev = sc.new_event(id='SERVICE_OPERATION_POLL_EVENT', - key='SERVICE_OPERATION_POLL_EVENT') - sc.post_event(ev) - uptime = time.strftime("%c") body = {'eventdata': {'uptime': uptime, 'module': 'config_orchestrator'}, diff --git a/gbpservice/nfp/config_orchestrator/handlers/event/__init__.py b/gbpservice/nfp/config_orchestrator/modules/event/__init__.py similarity index 100% rename from gbpservice/nfp/config_orchestrator/handlers/event/__init__.py rename to gbpservice/nfp/config_orchestrator/modules/event/__init__.py diff --git a/gbpservice/nfp/config_orchestrator/handlers/event/handler.py b/gbpservice/nfp/config_orchestrator/modules/event/handler.py similarity index 98% rename from gbpservice/nfp/config_orchestrator/handlers/event/handler.py rename to gbpservice/nfp/config_orchestrator/modules/event/handler.py index d1c3b40098..67939a2347 100644 --- a/gbpservice/nfp/config_orchestrator/handlers/event/handler.py +++ b/gbpservice/nfp/config_orchestrator/modules/event/handler.py @@ -56,7 +56,22 @@ def event_init(sc, conf): handler=EventsHandler(sc, conf)), Event(id='SERVICE_CREATE_PENDING', handler=EventsHandler(sc, conf))] - return evs + + sc.register_events(evs) + + +def nfp_module_init(sc, conf): + event_init(sc, conf) + + +def nfp_module_post_init(sc, conf): + try: + ev = sc.new_event(id='SERVICE_OPERATION_POLL_EVENT', + key='SERVICE_OPERATION_POLL_EVENT') + sc.post_event(ev) + except Exception as e: + msg = ("%s" % (e)) + LOG.error(msg) """Periodic Class to service events for visiblity.""" diff --git a/gbpservice/nfp/core/controller.py b/gbpservice/nfp/core/controller.py index 3e3f67709c..202a5ee741 100644 --- a/gbpservice/nfp/core/controller.py +++ b/gbpservice/nfp/core/controller.py @@ -102,7 +102,7 @@ def post_event_graph(self, event): """ event.desc.type = nfp_event.EVENT_GRAPH event.desc.flag = '' - event.desc.pid = os.getpid() + event.desc.pid = os.getpid() return event def post_event(self, event): @@ -216,7 +216,8 @@ def decompress(self, event): def pipe_recv(self, pipe): event = pipe.recv() - if event: self.decompress(event) + if event: + self.decompress(event) return event def pipe_send(self, pipe, event): @@ -499,34 +500,48 @@ def load_nfp_modules(conf, controller): base_module = __import__(conf.nfp_modules_path, globals(), locals(), ['modules'], -1) modules_dir = base_module.__path__[0] - try: - files = os.listdir(modules_dir) - for pyfile in set([f for f in files if f.endswith(".py")]): - try: - pymodule = __import__(conf.nfp_modules_path, - globals(), locals(), - [pyfile[:-3]], -1) - pymodule = eval('pymodule.%s' % (pyfile[:-3])) + modules_dir_list = [modules_dir] + while modules_dir_list: + current_path = modules_dir_list.pop(0) + tmp_path = current_path[1:] + tmp_path = tmp_path.replace('/', '.') + index = tmp_path.index('gbpservice.nfp') + nfp_formatted_path = tmp_path[index:] + try: + files = os.listdir(current_path) + for f in files: + test_path = os.path.join(current_path, f) + if os.path.isdir(test_path): + modules_dir_list.append(test_path) + for pyfile in set([f for f in files if f.endswith(".py") and + not f.startswith('__init__')]): try: - pymodule.nfp_module_init(controller, conf) - pymodules += [pymodule] - LOG.debug("(module - %s) - Initialized" % - (identify(pymodule))) - except AttributeError as e: - import sys - import traceback - exc_type, exc_value, exc_traceback = sys.exc_info() - print traceback.format_exception(exc_type, exc_value, - exc_traceback) - LOG.warn("(module - %s) - " - "does not implement" - "nfp_module_init()" % (identify(pymodule))) - except ImportError: - LOG.error( - "Failed to import module %s" % (pyfile)) - except OSError: - LOG.error( - "Failed to read files from %s" % (modules_dir)) + pymodule = __import__(nfp_formatted_path, + globals(), locals(), + [pyfile[:-3]], -1) + pymodule = eval('pymodule.%s' % (pyfile[:-3])) + try: + pymodule.nfp_module_init(controller, conf) + pymodules += [pymodule] + LOG.debug("(module - %s) - Initialized" % + (identify(pymodule))) + except AttributeError as e: + import sys + import traceback + exc_type, exc_value, exc_traceback = sys.exc_info() + print traceback.format_exception(exc_type, + exc_value, + exc_traceback) + LOG.warn("(module - %s) - " + "does not implement" + "nfp_module_init()" + % (identify(pymodule))) + except ImportError: + LOG.error( + "Failed to import module %s" % (pyfile)) + except OSError: + LOG.error( + "Failed to read files from %s" % (current_path)) except ImportError: LOG.error( "Failed to import module from path %s" % (conf.nfp_modules_path))