X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fro_main.py;h=39fc8434251cdc9af34dc601fd134898e929e3ae;hb=24a2b5184371649bff2806b9a72473f315787ef2;hp=376c087ee894ef10f162e51fe9d577eebf40ffe3;hpb=1ac189e7d842e8aa09133b769097e8703ec1352c;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ro_main.py b/NG-RO/osm_ng_ro/ro_main.py index 376c087e..39fc8434 100644 --- a/NG-RO/osm_ng_ro/ro_main.py +++ b/NG-RO/osm_ng_ro/ro_main.py @@ -35,6 +35,7 @@ from osm_common.fsbase import FsException from osm_common.msgbase import MsgException from osm_ng_ro import version as ro_version, version_date as ro_version_date import osm_ng_ro.html_out as html +from osm_ng_ro.monitor import start_monitoring, stop_monitoring from osm_ng_ro.ns import Ns, NsException from osm_ng_ro.validation import ValidationError from osm_ng_ro.vim_admin import VimAdminThread @@ -227,9 +228,7 @@ class Server(object): cherrypy.request.headers.pop("Content-File-MD5", None) elif "application/yaml" in cherrypy.request.headers["Content-Type"]: error_text = "Invalid yaml format " - indata = yaml.load( - cherrypy.request.body, Loader=yaml.SafeLoader - ) + indata = yaml.safe_load(cherrypy.request.body) cherrypy.request.headers.pop("Content-File-MD5", None) elif ( "application/binary" in cherrypy.request.headers["Content-Type"] @@ -262,13 +261,11 @@ class Server(object): # "Only 'Content-Type' of type 'application/json' or # 'application/yaml' for input format are available") error_text = "Invalid yaml format " - indata = yaml.load( - cherrypy.request.body, Loader=yaml.SafeLoader - ) + indata = yaml.safe_load(cherrypy.request.body) cherrypy.request.headers.pop("Content-File-MD5", None) else: error_text = "Invalid yaml format " - indata = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader) + indata = yaml.safe_load(cherrypy.request.body) cherrypy.request.headers.pop("Content-File-MD5", None) if not indata: @@ -284,9 +281,11 @@ class Server(object): kwargs[k] = None elif format_yaml: try: - kwargs[k] = yaml.load(v, Loader=yaml.SafeLoader) - except Exception: - pass + kwargs[k] = yaml.safe_load(v) + except Exception as yaml_error: + logging.exception( + f"{yaml_error} occured while parsing the yaml" + ) elif ( k.endswith(".gt") or k.endswith(".lt") @@ -298,8 +297,10 @@ class Server(object): except Exception: try: kwargs[k] = float(v) - except Exception: - pass + except Exception as keyword_error: + logging.exception( + f"{keyword_error} occured while getting the keyword arguments" + ) elif v.find(",") > 0: kwargs[k] = v.split(",") elif isinstance(v, (list, tuple)): @@ -308,9 +309,11 @@ class Server(object): v[index] = None elif format_yaml: try: - v[index] = yaml.load(v[index], Loader=yaml.SafeLoader) - except Exception: - pass + v[index] = yaml.safe_load(v[index]) + except Exception as error: + logging.exception( + f"{error} occured while parsing the yaml" + ) return indata except (ValueError, yaml.YAMLError) as exc: @@ -564,18 +567,14 @@ class Server(object): try: if cherrypy.request.method == "POST": - to_send = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader) + to_send = yaml.safe_load(cherrypy.request.body) for k, v in to_send.items(): self.ns.msg.write(main_topic, k, v) return_text += " {}: {}\n".format(k, v) elif cherrypy.request.method == "GET": for k, v in kwargs.items(): - self.ns.msg.write( - main_topic, k, yaml.load(v, Loader=yaml.SafeLoader) - ) - return_text += " {}: {}\n".format( - k, yaml.load(v, Loader=yaml.SafeLoader) - ) + self.ns.msg.write(main_topic, k, yaml.safe_load(v)) + return_text += " {}: {}\n".format(k, yaml.safe_load(v)) except Exception as e: return_text += "Error: " + str(e) @@ -931,6 +930,8 @@ def _start_service(): # # start subscriptions thread: vim_admin_thread = VimAdminThread(config=engine_config, engine=ro_server.ns) vim_admin_thread.start() + start_monitoring(config=engine_config) + # # Do not capture except SubscriptionException # backend = engine_config["authentication"]["backend"] @@ -948,7 +949,7 @@ def _stop_service(): # terminate vim_admin_thread if vim_admin_thread: vim_admin_thread.terminate() - + stop_monitoring() vim_admin_thread = None cherrypy.tree.apps["/ro"].root.ns.stop() cherrypy.log.error("Stopping osm_ng_ro") @@ -990,7 +991,7 @@ if __name__ == "__main__": elif o in ("-c", "--config"): config_file = a else: - assert False, "Unhandled option" + raise ValueError("Unhandled option") if config_file: if not path.isfile(config_file):