From b19cadcf9ff2169f34f6db79b866bad91f9c8aed Mon Sep 17 00:00:00 2001 From: delacruzramo Date: Tue, 8 Oct 2019 10:18:02 +0200 Subject: [PATCH] Adapt NBI to YAML V5 Change-Id: Ia768b60b0304d99a24bbfab2795922d54ca9ca0c Signed-off-by: delacruzramo --- osm_nbi/auth.py | 2 +- osm_nbi/descriptor_topics.py | 2 +- osm_nbi/engine.py | 2 +- osm_nbi/nbi.py | 16 ++++++++-------- osm_nbi/tests/test.py | 7 ++++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/osm_nbi/auth.py b/osm_nbi/auth.py index 8bb479d..dc3d386 100644 --- a/osm_nbi/auth.py +++ b/osm_nbi/auth.py @@ -214,7 +214,7 @@ class Authenticator: # Loading permissions to MongoDB if there is not any permission. if not records or (len(records) == 1 and records[0]["name"] == "admin"): with open(self.roles_to_operations_file, "r") as stream: - roles_to_operations_yaml = yaml.load(stream) + roles_to_operations_yaml = yaml.load(stream, Loader=yaml.Loader) role_names = [] for role_with_operations in roles_to_operations_yaml["roles"]: diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index d01dc13..95ced0d 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -264,7 +264,7 @@ class DescriptorTopic(BaseTopic): indata = json.load(content) else: error_text = "Invalid yaml format " - indata = yaml.load(content) + indata = yaml.load(content, Loader=yaml.SafeLoader) current_desc["_admin"]["storage"] = storage current_desc["_admin"]["onboardingState"] = "ONBOARDED" diff --git a/osm_nbi/engine.py b/osm_nbi/engine.py index 67a9233..e36f5c6 100644 --- a/osm_nbi/engine.py +++ b/osm_nbi/engine.py @@ -137,7 +137,7 @@ class Engine(object): raise EngineException("Invalid permission configuration: resources_to_operations file missing") with open(resources_to_operations_file, 'r') as f: - resources_to_operations = yaml.load(f) + resources_to_operations = yaml.load(f, Loader=yaml.Loader) self.operations = [] diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 665df75..8f995f5 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -481,7 +481,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) + indata = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader) cherrypy.request.headers.pop("Content-File-MD5", None) elif "application/binary" in cherrypy.request.headers["Content-Type"] or \ "application/gzip" in cherrypy.request.headers["Content-Type"] or \ @@ -501,11 +501,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) + indata = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader) cherrypy.request.headers.pop("Content-File-MD5", None) else: error_text = "Invalid yaml format " - indata = yaml.load(cherrypy.request.body) + indata = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader) cherrypy.request.headers.pop("Content-File-MD5", None) if not indata: indata = {} @@ -520,7 +520,7 @@ class Server(object): kwargs[k] = None elif format_yaml: try: - kwargs[k] = yaml.load(v) + kwargs[k] = yaml.load(v, Loader=yaml.SafeLoader) except Exception: pass elif k.endswith(".gt") or k.endswith(".lt") or k.endswith(".gte") or k.endswith(".lte"): @@ -539,7 +539,7 @@ class Server(object): v[index] = None elif format_yaml: try: - v[index] = yaml.load(v[index]) + v[index] = yaml.load(v[index], Loader=yaml.SafeLoader) except Exception: pass @@ -755,14 +755,14 @@ class Server(object): return_text = "
{} ->\n".format(main_topic)
             try:
                 if cherrypy.request.method == 'POST':
-                    to_send = yaml.load(cherrypy.request.body)
+                    to_send = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader)
                     for k, v in to_send.items():
                         self.engine.msg.write(main_topic, k, v)
                         return_text += "  {}: {}\n".format(k, v)
                 elif cherrypy.request.method == 'GET':
                     for k, v in kwargs.items():
-                        self.engine.msg.write(main_topic, k, yaml.load(v))
-                        return_text += "  {}: {}\n".format(k, yaml.load(v))
+                        self.engine.msg.write(main_topic, k, yaml.load(v), Loader=yaml.SafeLoader)
+                        return_text += "  {}: {}\n".format(k, yaml.load(v), Loader=yaml.SafeLoader)
             except Exception as e:
                 return_text += "Error: " + str(e)
             return_text += "
\n" diff --git a/osm_nbi/tests/test.py b/osm_nbi/tests/test.py index c9a37d8..3033a34 100755 --- a/osm_nbi/tests/test.py +++ b/osm_nbi/tests/test.py @@ -1342,7 +1342,7 @@ class TestDeploy: ns_data.update(self.ns_params) if test_params and test_params.get("ns-config"): if isinstance(test_params["ns-config"], str): - ns_data.update(yaml.load(test_params["ns-config"])) + ns_data.update(yaml.load(test_params["ns-config"]), Loader=yaml.Loader) else: ns_data.update(test_params["ns-config"]) self.instantiate(engine, ns_data) @@ -1833,7 +1833,8 @@ class TestDeployHackfest3Charmed3(TestDeployHackfest3Charmed): parameter: "$[0]": default-value: "" - """) + """, + Loader=yaml.Loader) } self.ns_params = { "additionalParamsForVnf": [ @@ -2135,7 +2136,7 @@ class TestDeployHnfd(TestDeployHackfest3Charmed): "vimAccountId": self.vim_id} if test_params and test_params.get("ns-config"): if isinstance(test_params["ns-config"], str): - ns_data.update(yaml.load(test_params["ns-config"])) + ns_data.update(yaml.load(test_params["ns-config"]), Loader=yaml.Loader) else: ns_data.update(test_params["ns-config"]) -- 2.25.1