X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fro_main.py;h=51c22bf5e40a1d854d63c7d1378a23a149730375;hb=HEAD;hp=86e839c6a2aa5248b61490f5eb1356fe7f9b5ea3;hpb=2f99505fff582e1213d5cafe9c87d06c87d9af7d;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 86e839c6..51c22bf5 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 @@ -214,7 +215,6 @@ class Server(object): } def _format_in(self, kwargs): - error_text = "" try: indata = None @@ -254,9 +254,9 @@ class Server(object): indata = filecontent.file # .read() if filecontent.content_type.value: - cherrypy.request.headers[ - "Content-Type" - ] = filecontent.content_type.value + cherrypy.request.headers["Content-Type"] = ( + filecontent.content_type.value + ) else: # raise cherrypy.HTTPError(HTTPStatus.Not_Acceptable, # "Only 'Content-Type' of type 'application/json' or @@ -356,9 +356,9 @@ class Server(object): if accept: if "application/json" in accept: - cherrypy.response.headers[ - "Content-Type" - ] = "application/json; charset=utf-8" + cherrypy.response.headers["Content-Type"] = ( + "application/json; charset=utf-8" + ) a = json.dumps(data, indent=4) + "\n" return a.encode("utf8") @@ -539,15 +539,15 @@ class Server(object): return ",".join(folders) + " folders deleted\n" elif args and args[0] == "login": if not cherrypy.request.headers.get("Authorization"): - cherrypy.response.headers[ - "WWW-Authenticate" - ] = 'Basic realm="Access to OSM site", charset="UTF-8"' + cherrypy.response.headers["WWW-Authenticate"] = ( + 'Basic realm="Access to OSM site", charset="UTF-8"' + ) cherrypy.response.status = HTTPStatus.UNAUTHORIZED.value elif args and args[0] == "login2": if not cherrypy.request.headers.get("Authorization"): - cherrypy.response.headers[ - "WWW-Authenticate" - ] = 'Bearer realm="Access to OSM site"' + cherrypy.response.headers["WWW-Authenticate"] = ( + 'Bearer realm="Access to OSM site"' + ) cherrypy.response.status = HTTPStatus.UNAUTHORIZED.value elif args and args[0] == "sleep": sleep_time = 5 @@ -687,7 +687,7 @@ class Server(object): **kwargs, ): token_info = None - outdata = None + outdata = {} _format = None method = "DONE" rollback = [] @@ -743,9 +743,11 @@ class Server(object): cherrypy.response.status = ( HTTPStatus.ACCEPTED.value if not done - else HTTPStatus.OK.value - if outdata is not None - else HTTPStatus.NO_CONTENT.value + else ( + HTTPStatus.OK.value + if outdata is not None + else HTTPStatus.NO_CONTENT.value + ) ) return self._format_out(outdata, token_info, _format) @@ -766,9 +768,9 @@ class Server(object): http_code_name = e.http_code.name cherrypy.log("Exception {}".format(e)) else: - http_code_value = ( - cherrypy.response.status - ) = HTTPStatus.BAD_REQUEST.value # INTERNAL_SERVER_ERROR + http_code_value = cherrypy.response.status = ( + HTTPStatus.BAD_REQUEST.value + ) # INTERNAL_SERVER_ERROR cherrypy.log("CRITICAL: Exception {}".format(e), traceback=True) http_code_name = HTTPStatus.BAD_REQUEST.name @@ -931,6 +933,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 +952,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")