From 4cd875d2a38488b5e717258d548eeb8e557ec9a8 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Tue, 14 Feb 2023 19:05:34 +0100 Subject: [PATCH] Replace yaml.load by yaml.safe_load Change-Id: I4f6c3802e40d763fc2175dbb2bd94dbc79b813c2 Signed-off-by: garciadeblas --- osm_nbi/admin_topics.py | 2 -- osm_nbi/auth.py | 2 +- osm_nbi/authconn_keystone.py | 1 - osm_nbi/descriptor_topics.py | 6 +--- osm_nbi/engine.py | 2 +- osm_nbi/instance_topics.py | 2 -- osm_nbi/nbi.py | 20 +++++------ osm_nbi/notifications.py | 2 -- osm_nbi/osm_vnfm/vnf_instances.py | 1 - osm_nbi/subscriptions.py | 1 - osm_nbi/tests/run_test.py | 14 ++------ osm_nbi/tests/test_instance_topics.py | 50 ++++++++++++--------------- osm_nbi/tests/test_osm_vnfm.py | 28 +++++++-------- osm_nbi/tests/test_pmjobs_topic.py | 20 +++++------ tox.ini | 2 +- 15 files changed, 60 insertions(+), 93 deletions(-) diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index fa75853..9f6f6d7 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -345,7 +345,6 @@ class CommonVimWimSdn(BaseTopic): schema_version ) or self.config_to_encrypt.get("default") if edit_content.get("config") and config_to_encrypt_keys: - for p in config_to_encrypt_keys: if edit_content["config"].get(p): final_content["config"][p] = self.db.encrypt( @@ -1074,7 +1073,6 @@ class UserTopicAuth(UserTopic): mapping["role"], mapping["role_name"], ): - if mapping in mappings_to_remove: # do not remove mappings_to_remove.remove(mapping) break # do not add, it is already at user diff --git a/osm_nbi/auth.py b/osm_nbi/auth.py index 139c165..0b3264f 100644 --- a/osm_nbi/auth.py +++ b/osm_nbi/auth.py @@ -283,7 +283,7 @@ class Authenticator: (r for r in records if r["name"] == "system_admin"), None ): with open(self.roles_to_operations_file, "r") as stream: - roles_to_operations_yaml = yaml.load(stream, Loader=yaml.Loader) + roles_to_operations_yaml = yaml.safe_load(stream) role_names = [] for role_with_operations in roles_to_operations_yaml["roles"]: diff --git a/osm_nbi/authconn_keystone.py b/osm_nbi/authconn_keystone.py index 5e34485..a84b3d9 100644 --- a/osm_nbi/authconn_keystone.py +++ b/osm_nbi/authconn_keystone.py @@ -328,7 +328,6 @@ class AuthconnKeystone(Authconn): :return: returns the id of the user in keystone. """ try: - if ( user_info.get("domain_name") and user_info["domain_name"] in self.user_domain_ro_list diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index 2814653..ca10c42 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -437,7 +437,7 @@ class DescriptorTopic(BaseTopic): indata = json.load(content) else: error_text = "Invalid yaml format " - indata = yaml.load(content, Loader=yaml.SafeLoader) + indata = yaml.safe_load(content) # Need to close the file package here so it can be copied from the # revision to the current, unrevisioned record @@ -1323,11 +1323,9 @@ class VnfdTopic(DescriptorTopic): with self.fs.file_open( (old_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as old_descriptor_file: - with self.fs.file_open( (new_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as new_descriptor_file: - old_content = yaml.safe_load(old_descriptor_file.read()) new_content = yaml.safe_load(new_descriptor_file.read()) @@ -1719,11 +1717,9 @@ class NsdTopic(DescriptorTopic): with self.fs.file_open( (old_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as old_descriptor_file: - with self.fs.file_open( (new_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as new_descriptor_file: - old_content = yaml.safe_load(old_descriptor_file.read()) new_content = yaml.safe_load(new_descriptor_file.read()) diff --git a/osm_nbi/engine.py b/osm_nbi/engine.py index e9b1549..9b17402 100644 --- a/osm_nbi/engine.py +++ b/osm_nbi/engine.py @@ -205,7 +205,7 @@ class Engine(object): # "resources_to_operations file missing") # # with open(resources_to_operations_file, 'r') as f: - # resources_to_operations = yaml.load(f, Loader=yaml.Loader) + # resources_to_operations = yaml.safeload(f) # # self.operations = [] # diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index 2eefb96..f9539dd 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -1313,7 +1313,6 @@ class NsLcmOpTopic(BaseTopic): vnfd_id_2update = indata["changeVnfPackageData"]["vnfdId"] if vnf_instance_id not in nsr["constituent-vnfr-ref"]: - raise EngineException( f"Error in validating ns-update request: vnf {vnf_instance_id} does not " f"belong to NS {ns_instance_id}", @@ -1333,7 +1332,6 @@ class NsLcmOpTopic(BaseTopic): # Check the given vnfd-id belongs to given vnf instance if constituent_vnfd_id and (vnfd_id_2update != constituent_vnfd_id): - raise EngineException( f"Error in validating ns-update request: vnfd-id {vnfd_id_2update} does not " f"match with the vnfd-id: {constituent_vnfd_id} of VNF instance: {vnf_instance_id}", diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index fa414f0..8fa6152 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -672,9 +672,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"] @@ -704,13 +702,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: indata = {} @@ -725,7 +721,7 @@ class Server(object): kwargs[k] = None elif format_yaml: try: - kwargs[k] = yaml.load(v, Loader=yaml.SafeLoader) + kwargs[k] = yaml.safe_load(v) except Exception: pass elif ( @@ -749,7 +745,7 @@ class Server(object): v[index] = None elif format_yaml: try: - v[index] = yaml.load(v[index], Loader=yaml.SafeLoader) + v[index] = yaml.safe_load(v[index]) except Exception: pass @@ -977,7 +973,7 @@ class Server(object): return self._format_out(str(alarm_list)) # to handle patch request for alarm update elif cherrypy.request.method == "PATCH": - data = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader) + data = yaml.safe_load(cherrypy.request.body) try: # check if uuid is valid self.engine.db.get_one("alarms", {"uuid": data.get("uuid")}) @@ -1171,13 +1167,13 @@ class Server(object): return_text = "
{} ->\n".format(main_topic)
             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.engine.msg.write(main_topic, k, v)
                         return_text += "  {}: {}\n".format(k, v)
                 elif cherrypy.request.method == "GET":
                     for k, v in kwargs.items():
-                        v_dict = yaml.load(v, Loader=yaml.SafeLoader)
+                        v_dict = yaml.safe_load(v)
                         self.engine.msg.write(main_topic, k, v_dict)
                         return_text += "  {}: {}\n".format(k, v_dict)
             except Exception as e:
diff --git a/osm_nbi/notifications.py b/osm_nbi/notifications.py
index bcaa0d0..a62670b 100644
--- a/osm_nbi/notifications.py
+++ b/osm_nbi/notifications.py
@@ -41,7 +41,6 @@ class NotificationException(Exception):
 
 
 class NotificationBase:
-
     response_models = None
     # Common HTTP payload header for all notifications.
     payload_header = {"Content-Type": "application/json", "Accept": "application/json"}
@@ -239,7 +238,6 @@ class NotificationBase:
 
 
 class NsLcmNotification(NotificationBase):
-
     # SOL005 response model for nslcm notifications
     response_models = {
         "NsLcmOperationOccurrenceNotification": {
diff --git a/osm_nbi/osm_vnfm/vnf_instances.py b/osm_nbi/osm_vnfm/vnf_instances.py
index aab528a..d65f1e0 100644
--- a/osm_nbi/osm_vnfm/vnf_instances.py
+++ b/osm_nbi/osm_vnfm/vnf_instances.py
@@ -80,7 +80,6 @@ class VnfInstances2NsInstances:
 
 
 class NewVnfInstance(BaseMethod):
-
     # sample ns descriptor
     sample_nsd = {
         "nsd": {
diff --git a/osm_nbi/subscriptions.py b/osm_nbi/subscriptions.py
index 91d2f2d..b178e5b 100644
--- a/osm_nbi/subscriptions.py
+++ b/osm_nbi/subscriptions.py
@@ -187,7 +187,6 @@ class SubscriptionThread(threading.Thread):
         self.logger.debug("Starting")
         while not self.to_terminate:
             try:
-
                 self.loop.run_until_complete(
                     asyncio.ensure_future(self.start_kafka(), loop=self.loop)
                 )
diff --git a/osm_nbi/tests/run_test.py b/osm_nbi/tests/run_test.py
index b7eb986..b7768ba 100755
--- a/osm_nbi/tests/run_test.py
+++ b/osm_nbi/tests/run_test.py
@@ -2003,7 +2003,6 @@ class TestFakeVim:
         ]
 
     def run(self, engine, test_osm, manual_check, test_params=None):
-
         vim_bad = self.vim.copy()
         vim_bad.pop("name")
 
@@ -2622,7 +2621,6 @@ class TestDeploy:
         keys=None,
         timeout=0,
     ):
-
         r = engine.test(
             "GET VNFR IDs",
             "GET",
@@ -2783,7 +2781,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"]), Loader=yaml.Loader)
+                ns_data.update(yaml.safe_load(test_params["ns-config"]))
             else:
                 ns_data.update(test_params["ns-config"])
         self.instantiate(engine, ns_data)
@@ -3349,7 +3347,7 @@ class TestDeployHackfest3Charmed3(TestDeployHackfest3Charmed):
             "2": ["ls -lrt /home/ubuntu/first-touch-2"],
         }
         self.descriptor_edit = {
-            "vnfd0": yaml.load(
+            "vnfd0": yaml.safe_load(
                 """
                 scaling-group-descriptor:
                     -   name: "scale_dataVM"
@@ -3399,7 +3397,6 @@ class TestDeployHackfest3Charmed3(TestDeployHackfest3Charmed):
                                 "$[0]":
                                     default-value: ""
                 """,
-                Loader=yaml.Loader,
             )
         }
         self.ns_params = {
@@ -3812,7 +3809,7 @@ class TestDeployHnfd(TestDeployHackfest3Charmed):
         }
         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"]), Loader=yaml.Loader)
+                ns_data.update(yaml.safe_load(test_params["ns-config"]))
             else:
                 ns_data.update(test_params["ns-config"])
 
@@ -5045,7 +5042,6 @@ class TestNbiQuotas:
         test_user_id = engine.last_id if res else None
 
         if test_project_id and test_user_id:
-
             # Get user access
             engine.token = None
             engine.user = test_username
@@ -5113,7 +5109,6 @@ class TestNbiQuotas:
             test_vim_ids += [engine.last_id if res else None]
 
             if test_vim_ids[0]:
-
                 # Download descriptor files (if required)
                 test_dir = "/tmp/" + test_username + "/"
                 test_url = "https://osm-download.etsi.org/ftp/osm-6.0-six/7th-hackfest/packages/"
@@ -5140,7 +5135,6 @@ class TestNbiQuotas:
                                 file.write(res.content)
 
                 if all([os.path.exists(test_dir + p) for p in desc_filenames]):
-
                     # Test VNFD Quotas
                     res = engine.test(
                         "Create test VNFD #1",
@@ -5206,7 +5200,6 @@ class TestNbiQuotas:
                                 test_vnfd_ids[i] = None
 
                     if test_vnfd_ids[0] and test_vnfd_ids[1]:
-
                         # Test NSD Quotas
                         res = engine.test(
                             "Create test NSD #1",
@@ -5272,7 +5265,6 @@ class TestNbiQuotas:
                                     test_nsd_ids[i] = None
 
                         if test_nsd_ids[0] and test_nsd_ids[1]:
-
                             # Test NSR Quotas
                             res = engine.test(
                                 "Create test NSR #1",
diff --git a/osm_nbi/tests/test_instance_topics.py b/osm_nbi/tests/test_instance_topics.py
index 0d4adec..b12a330 100644
--- a/osm_nbi/tests/test_instance_topics.py
+++ b/osm_nbi/tests/test_instance_topics.py
@@ -49,13 +49,11 @@ class TestNsLcmOpTopic(unittest.TestCase):
         self.nslcmop_topic = NsLcmOpTopic(self.db, self.fs, self.msg, None)
         self.nslcmop_topic.check_quota = Mock(return_value=None)  # skip quota
 
-        self.db.create_list(
-            "vim_accounts", yaml.load(db_vim_accounts_text, Loader=yaml.Loader)
-        )
-        self.db.create_list("nsds", yaml.load(db_nsds_text, Loader=yaml.Loader))
-        self.db.create_list("vnfds", yaml.load(db_vnfds_text, Loader=yaml.Loader))
-        self.db.create_list("vnfrs", yaml.load(db_vnfrs_text, Loader=yaml.Loader))
-        self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader))
+        self.db.create_list("vim_accounts", yaml.safe_load(db_vim_accounts_text))
+        self.db.create_list("nsds", yaml.safe_load(db_nsds_text))
+        self.db.create_list("vnfds", yaml.safe_load(db_vnfds_text))
+        self.db.create_list("vnfrs", yaml.safe_load(db_vnfrs_text))
+        self.db.create_list("nsrs", yaml.safe_load(db_nsrs_text))
         self.db.create = Mock(return_value="created_id")
         self.nsd = self.db.get_list("nsds")[0]
         self.nsd_id = self.nsd["_id"]
@@ -389,8 +387,8 @@ class TestNsLcmOpTopicWithMock(unittest.TestCase):
         self.nslcmop_topic = NsLcmOpTopic(self.db, self.fs, self.msg, None)
 
     def test_get_vnfd_from_vnf_member_revision(self):
-        test_vnfr = yaml.load(db_vnfrs_text, Loader=yaml.Loader)[0]
-        test_vnfd = yaml.load(db_vnfds_text, Loader=yaml.Loader)
+        test_vnfr = yaml.safe_load(db_vnfrs_text)[0]
+        test_vnfd = yaml.safe_load(db_vnfds_text)
         self.db.get_one.side_effect = [test_vnfr, test_vnfd]
         _ = self.nslcmop_topic._get_vnfd_from_vnf_member_index("1", test_vnfr["_id"])
         self.assertEqual(
@@ -405,9 +403,9 @@ class TestNsLcmOpTopicWithMock(unittest.TestCase):
         )
 
     def test_get_vnfd_from_vnf_member_no_revision(self):
-        test_vnfr = yaml.load(db_vnfrs_text, Loader=yaml.Loader)[0]
+        test_vnfr = yaml.safe_load(db_vnfrs_text)[0]
         test_vnfr["revision"] = 3
-        test_vnfd = yaml.load(db_vnfds_text, Loader=yaml.Loader)
+        test_vnfd = yaml.safe_load(db_vnfds_text)
         self.db.get_one.side_effect = [test_vnfr, test_vnfd]
         _ = self.nslcmop_topic._get_vnfd_from_vnf_member_index("1", test_vnfr["_id"])
         self.assertEqual(
@@ -434,9 +432,9 @@ class TestNsLcmOpTopicWithMock(unittest.TestCase):
         session = {}
 
         with self.subTest(i=1, t="VNF instance does not belong to NS"):
-            test_vnfr = yaml.load(db_vnfrs_text, Loader=yaml.Loader)
+            test_vnfr = yaml.safe_load(db_vnfrs_text)
             test_vnfr[0]["revision"] = 2
-            test_nsr = yaml.load(db_nsrs_text, Loader=yaml.Loader)
+            test_nsr = yaml.safe_load(db_nsrs_text)
             test_nsr[0]["constituent-vnfr-ref"][
                 0
             ] = "99d90b0c-faff-4b9f-bccd-017f33985984"
@@ -460,9 +458,9 @@ class TestNsLcmOpTopicWithMock(unittest.TestCase):
             )
 
         with self.subTest(i=2, t="Ns update request validated with no exception"):
-            test_vnfr = yaml.load(db_vnfrs_text, Loader=yaml.Loader)
+            test_vnfr = yaml.safe_load(db_vnfrs_text)
             test_vnfr[0]["revision"] = 2
-            test_nsr = yaml.load(db_nsrs_text, Loader=yaml.Loader)
+            test_nsr = yaml.safe_load(db_nsrs_text)
             self.db.create_list("vnfrs", test_vnfr)
             self.db.create_list("nsrs", test_nsr)
             nsrs = self.db.get_list("nsrs")[1]
@@ -498,9 +496,9 @@ class TestNsLcmOpTopicWithMock(unittest.TestCase):
             )
 
         with self.subTest(i=4, t="wrong vnfdid is given as an update parameter"):
-            test_vnfr = yaml.load(db_vnfrs_text, Loader=yaml.Loader)
+            test_vnfr = yaml.safe_load(db_vnfrs_text)
             test_vnfr[0]["revision"] = 2
-            test_nsr = yaml.load(db_nsrs_text, Loader=yaml.Loader)
+            test_nsr = yaml.safe_load(db_nsrs_text)
             self.db.create_list("vnfrs", test_vnfr)
             self.db.create_list("nsrs", test_nsr)
             nsrs = self.db.get_list("nsrs")[2]
@@ -524,9 +522,9 @@ class TestNsLcmOpTopicWithMock(unittest.TestCase):
         with self.subTest(
             i=5, t="Ns update REMOVE_VNF request validated with no exception"
         ):
-            test_vnfr = yaml.load(db_vnfrs_text, Loader=yaml.Loader)
+            test_vnfr = yaml.safe_load(db_vnfrs_text)
             test_vnfr[0]["revision"] = 2
-            test_nsr = yaml.load(db_nsrs_text, Loader=yaml.Loader)
+            test_nsr = yaml.safe_load(db_nsrs_text)
             self.db.create_list("vnfrs", test_vnfr)
             self.db.create_list("nsrs", test_nsr)
             nsrs = self.db.get_list("nsrs")[1]
@@ -550,11 +548,9 @@ class TestNsrTopic(unittest.TestCase):
         self.nsr_topic = NsrTopic(self.db, self.fs, self.msg, None)
         self.nsr_topic.check_quota = Mock(return_value=None)  # skip quota
 
-        self.db.create_list(
-            "vim_accounts", yaml.load(db_vim_accounts_text, Loader=yaml.Loader)
-        )
-        self.db.create_list("nsds", yaml.load(db_nsds_text, Loader=yaml.Loader))
-        self.db.create_list("vnfds", yaml.load(db_vnfds_text, Loader=yaml.Loader))
+        self.db.create_list("vim_accounts", yaml.safe_load(db_vim_accounts_text))
+        self.db.create_list("nsds", yaml.safe_load(db_nsds_text))
+        self.db.create_list("vnfds", yaml.safe_load(db_vnfds_text))
         self.db.create = Mock(return_value="created_id")
         self.nsd = self.db.get_list("nsds")[0]
         self.nsd_id = self.nsd["_id"]
@@ -717,7 +713,7 @@ class TestNsrTopic(unittest.TestCase):
         }
         filter_q = {}
         for refresh_status in ("true", "false"):
-            self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader))
+            self.db.create_list("nsrs", yaml.safe_load(db_nsrs_text))
             actual_nsr = self.db.get_list("nsrs")[0]
             nsr_id = actual_nsr["_id"]
             filter_q["vcaStatus-refresh"] = refresh_status
@@ -739,7 +735,7 @@ class TestNsrTopic(unittest.TestCase):
         }
         filter_q = {"vcaStatus-refresh": "true"}
         time_delta = 120
-        self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader))
+        self.db.create_list("nsrs", yaml.safe_load(db_nsrs_text))
         nsr = self.db.get_list("nsrs")[0]
 
         # When vcaStatus-refresh is true
@@ -774,7 +770,7 @@ class TestNsrTopic(unittest.TestCase):
         )
 
     def test_delete_ns(self):
-        self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader))
+        self.db.create_list("nsrs", yaml.safe_load(db_nsrs_text))
         self.nsr = self.db.get_list("nsrs")[0]
         self.nsr_id = self.nsr["_id"]
         self.db_set_one = self.db.set_one
diff --git a/osm_nbi/tests/test_osm_vnfm.py b/osm_nbi/tests/test_osm_vnfm.py
index b298828..f4e6e63 100644
--- a/osm_nbi/tests/test_osm_vnfm.py
+++ b/osm_nbi/tests/test_osm_vnfm.py
@@ -41,10 +41,8 @@ class TestVnfInstances(unittest.TestCase):
         self.msg = Mock(MsgBase())
         self.vnfinstances = VnfInstances(self.db, self.fs, self.msg, None)
         self.nsrtopic = NsrTopic(self.db, self.fs, self.msg, None)
-        self.db.create_list(
-            "vim_accounts", yaml.load(db_vim_accounts_text, Loader=yaml.Loader)
-        )
-        self.db.create_list("vnfds", yaml.load(db_vnfm_vnfd_text, Loader=yaml.Loader))
+        self.db.create_list("vim_accounts", yaml.safe_load(db_vim_accounts_text))
+        self.db.create_list("vnfds", yaml.safe_load(db_vnfm_vnfd_text))
         self.vnfd = self.db.get_list("vnfds")[0]
         self.vnfd_id = self.vnfd["id"]
         self.vnfd_project = self.vnfd["_admin"]["projects_read"][0]
@@ -108,7 +106,7 @@ class TestVnfInstances(unittest.TestCase):
             "method": "write",
         }
         filter_q = {}
-        self.db.create_list("vnfrs", yaml.load(db_vnfrs_text, Loader=yaml.Loader))
+        self.db.create_list("vnfrs", yaml.safe_load(db_vnfrs_text))
         actual_vnfr = self.db.get_list("vnfrs")[0]
         id = actual_vnfr["_id"]
         expected_vnfr = self.vnfinstances.show(session, id, filter_q)
@@ -126,9 +124,9 @@ class TestVnfInstances(unittest.TestCase):
             "project_id": [self.vnfd_project],
             "method": "delete",
         }
-        self.db.create_list("vnfrs", yaml.load(db_vnfrs_text, Loader=yaml.Loader))
-        self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader))
-        self.db.create_list("nsds", yaml.load(db_nsds_text, Loader=yaml.Loader))
+        self.db.create_list("vnfrs", yaml.safe_load(db_vnfrs_text))
+        self.db.create_list("nsrs", yaml.safe_load(db_nsrs_text))
+        self.db.create_list("nsds", yaml.safe_load(db_nsds_text))
 
         self.vnfr = self.db.get_list("vnfrs")[0]
         self.vnfr_id = self.vnfr["_id"]
@@ -151,13 +149,11 @@ class TestVnfLcmOpTopic(unittest.TestCase):
         self.vnflcmop_topic = VnfLcmOpTopic(self.db, self.fs, self.msg, None)
         self.vnflcmop_topic.check_quota = Mock(return_value=None)  # skip quota
 
-        self.db.create_list(
-            "vim_accounts", yaml.load(db_vim_accounts_text, Loader=yaml.Loader)
-        )
-        self.db.create_list("nsds", yaml.load(db_nsds_text, Loader=yaml.Loader))
-        self.db.create_list("vnfds", yaml.load(db_vnfm_vnfd_text, Loader=yaml.Loader))
-        self.db.create_list("vnfrs", yaml.load(db_vnfrs_text, Loader=yaml.Loader))
-        self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader))
+        self.db.create_list("vim_accounts", yaml.safe_load(db_vim_accounts_text))
+        self.db.create_list("nsds", yaml.safe_load(db_nsds_text))
+        self.db.create_list("vnfds", yaml.safe_load(db_vnfm_vnfd_text))
+        self.db.create_list("vnfrs", yaml.safe_load(db_vnfrs_text))
+        self.db.create_list("nsrs", yaml.safe_load(db_nsrs_text))
 
         self.vnfd = self.db.get_list("vnfds")[0]
         self.vnfd_id = self.vnfd["_id"]
@@ -209,7 +205,7 @@ class TestVnfLcmOpTopic(unittest.TestCase):
             "project_id": [self.vnfd_project],
             "method": "write",
         }
-        self.db.create_list("nslcmops", yaml.load(db_nslcmops_text, Loader=yaml.Loader))
+        self.db.create_list("nslcmops", yaml.safe_load(db_nslcmops_text))
         filter_q = {}
         actual_lcmop = self.db.get_list("nslcmops")[0]
         id = actual_lcmop["_id"]
diff --git a/osm_nbi/tests/test_pmjobs_topic.py b/osm_nbi/tests/test_pmjobs_topic.py
index 231818b..e5605c3 100644
--- a/osm_nbi/tests/test_pmjobs_topic.py
+++ b/osm_nbi/tests/test_pmjobs_topic.py
@@ -43,10 +43,10 @@ class PmJobsTopicTest(asynctest.TestCase):
     def setUp(self):
         self.db = DbMemory()
         self.pmjobs_topic = PmJobsTopic(self.db, host="prometheus", port=9091)
-        self.db.create_list("nsds", yaml.load(db_nsds_text, Loader=yaml.Loader))
-        self.db.create_list("vnfds", yaml.load(db_vnfds_text, Loader=yaml.Loader))
-        self.db.create_list("vnfrs", yaml.load(db_vnfrs_text, Loader=yaml.Loader))
-        self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader))
+        self.db.create_list("nsds", yaml.safe_load(db_nsds_text))
+        self.db.create_list("vnfds", yaml.safe_load(db_vnfds_text))
+        self.db.create_list("vnfrs", yaml.safe_load(db_vnfrs_text))
+        self.db.create_list("nsrs", yaml.safe_load(db_nsrs_text))
         self.nsr = self.db.get_list("nsrs")[0]
         self.nsr_id = self.nsr["_id"]
         project_id = self.nsr["_admin"]["projects_write"]
@@ -80,18 +80,18 @@ class PmJobsTopicTest(asynctest.TestCase):
         for metric in metric_list:
             endpoint = re.sub(r"metric_name", metric, site)
             if metric == "cpu_utilization":
-                response = yaml.load(cpu_utilization, Loader=yaml.Loader)
+                response = yaml.safe_load(cpu_utilization)
             elif metric == "users":
-                response = yaml.load(users, Loader=yaml.Loader)
+                response = yaml.safe_load(users)
             elif metric == "load":
-                response = yaml.load(load, Loader=yaml.Loader)
+                response = yaml.safe_load(load)
             else:
-                response = yaml.load(empty, Loader=yaml.Loader)
+                response = yaml.safe_load(empty)
             mock_res.get(endpoint, payload=response)
 
     async def test_prom_metric_request(self):
         with self.subTest("Test case1 failed in test_prom"):
-            prom_response = yaml.load(prom_res, Loader=yaml.Loader)
+            prom_response = yaml.safe_load(prom_res)
             with aioresponses() as mock_res:
                 self.set_get_mock_res(mock_res, self.nsr_id, self.metric_check_list)
                 result = await self.pmjobs_topic._prom_metric_request(
@@ -109,7 +109,7 @@ class PmJobsTopicTest(asynctest.TestCase):
 
     def test_show(self):
         with self.subTest("Test case1 failed in test_show"):
-            show_response = yaml.load(show_res, Loader=yaml.Loader)
+            show_response = yaml.safe_load(show_res)
             with aioresponses() as mock_res:
                 self.set_get_mock_res(mock_res, self.nsr_id, self.metric_check_list)
                 result = self.pmjobs_topic.show(self.session, self.nsr_id)
diff --git a/tox.ini b/tox.ini
index b26bb35..39aa70d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -48,7 +48,7 @@ commands =
         coverage report --omit='*tests*'
         coverage html -d ./cover --omit='*tests*'
         coverage xml -o coverage.xml --omit=*tests*
-whitelist_externals = sh
+allowlist_externals = sh
 
 
 #######################################################################################
-- 
2.17.1