bug 1092 fixing deletion of items referenced by several projects 36/9136/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 22 Jun 2020 12:17:22 +0000 (12:17 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 22 Jun 2020 14:34:36 +0000 (14:34 +0000)
It is only deletes if it the last project referencing it.
Depends on this change at common:  https://osm.etsi.org/gerrit/9134

Change-Id: Id167c0ae3309212b97f59d47a9f3cee7f53fd263
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_nbi/admin_topics.py
osm_nbi/base_topic.py
osm_nbi/tests/test_admin_topics.py
osm_nbi/tests/test_descriptor_topics.py
osm_nbi/tests/test_instance_topics.py

index 6342ba2..f831b63 100644 (file)
@@ -325,14 +325,14 @@ class CommonVimWimSdn(BaseTopic):
         # do not remove reference, but order via kafka to delete it
         if session["project_id"] and session["project_id"]:
             other_projects_referencing = next((p for p in db_content["_admin"]["projects_read"]
         # do not remove reference, but order via kafka to delete it
         if session["project_id"] and session["project_id"]:
             other_projects_referencing = next((p for p in db_content["_admin"]["projects_read"]
-                                               if p not in session["project_id"]), None)
+                                               if p not in session["project_id"] and p != "ANY"), None)
 
             # check if there are projects referencing it (apart from ANY, that means, public)....
             if other_projects_referencing:
                 # remove references but not delete
 
             # check if there are projects referencing it (apart from ANY, that means, public)....
             if other_projects_referencing:
                 # remove references but not delete
-                update_dict_pull = {"_admin.projects_read.{}".format(p): None for p in session["project_id"]}
-                update_dict_pull.update({"_admin.projects_write.{}".format(p): None for p in session["project_id"]})
-                self.db.set_one(self.topic, filter_q, update_dict=None, pull=update_dict_pull)
+                update_dict_pull = {"_admin.projects_read": session["project_id"],
+                                    "_admin.projects_write": session["project_id"]}
+                self.db.set_one(self.topic, filter_q, update_dict=None, pull_list=update_dict_pull)
                 return None
             else:
                 can_write = next((p for p in db_content["_admin"]["projects_write"] if p == "ANY" or
                 return None
             else:
                 can_write = next((p for p in db_content["_admin"]["projects_write"] if p == "ANY" or
index 130d4fc..daa7a6b 100644 (file)
@@ -497,14 +497,14 @@ class BaseTopic:
             # remove reference from project_read if there are more projects referencing it. If it last one,
             # do not remove reference, but delete
             other_projects_referencing = next((p for p in item_content["_admin"]["projects_read"]
             # remove reference from project_read if there are more projects referencing it. If it last one,
             # do not remove reference, but delete
             other_projects_referencing = next((p for p in item_content["_admin"]["projects_read"]
-                                               if p not in session["project_id"]), None)
+                                               if p not in session["project_id"] and p != "ANY"), None)
 
             # check if there are projects referencing it (apart from ANY, that means, public)....
             if other_projects_referencing:
                 # remove references but not delete
 
             # check if there are projects referencing it (apart from ANY, that means, public)....
             if other_projects_referencing:
                 # remove references but not delete
-                update_dict_pull = {"_admin.projects_read.{}".format(p): None for p in session["project_id"]}
-                update_dict_pull.update({"_admin.projects_write.{}".format(p): None for p in session["project_id"]})
-                self.db.set_one(self.topic, filter_q, update_dict=None, pull=update_dict_pull)
+                update_dict_pull = {"_admin.projects_read": session["project_id"],
+                                    "_admin.projects_write": session["project_id"]}
+                self.db.set_one(self.topic, filter_q, update_dict=None, pull_list=update_dict_pull)
                 return None
             else:
                 can_write = next((p for p in item_content["_admin"]["projects_write"] if p == "ANY" or
                 return None
             else:
                 can_write = next((p for p in item_content["_admin"]["projects_write"] if p == "ANY" or
index dce8710..a26d576 100755 (executable)
@@ -734,8 +734,8 @@ class Test_CommonVimWimSdn(TestCase):
             self.assertEqual(self.db.set_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier")
             self.assertEqual(self.db.set_one.call_args[1]["update_dict"], None,
                              "Wrong read-only projects update")
             self.assertEqual(self.db.set_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier")
             self.assertEqual(self.db.set_one.call_args[1]["update_dict"], None,
                              "Wrong read-only projects update")
-            self.assertEqual(self.db.set_one.call_args[1]["pull"], {"_admin.projects_read." + test_pid: None,
-                                                                    "_admin.projects_write." + test_pid: None},
+            self.assertEqual(self.db.set_one.call_args[1]["pull_list"],
+                             {"_admin.projects_read": (test_pid,), "_admin.projects_write": (test_pid,)},
                              "Wrong read/write projects update")
             self.topic._send_msg.assert_not_called()
         with self.subTest(i=2):
                              "Wrong read/write projects update")
             self.topic._send_msg.assert_not_called()
         with self.subTest(i=2):
index 260104a..3853f76 100755 (executable)
@@ -510,8 +510,9 @@ class Test_VnfdTopic(TestCase):
             self.assertEqual(db_s1_args[0][1]["_id"], did, "Wrong DB ID")
             self.assertIn(p_id, db_s1_args[0][1]["_admin.projects_write.cont"], "Wrong DB filter")
             self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
             self.assertEqual(db_s1_args[0][1]["_id"], did, "Wrong DB ID")
             self.assertIn(p_id, db_s1_args[0][1]["_admin.projects_write.cont"], "Wrong DB filter")
             self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
-            self.assertIn("_admin.projects_read." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
-            self.assertIn("_admin.projects_write." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
+            self.assertEqual(db_s1_args[1]["pull_list"],
+                             {"_admin.projects_read": (p_id,), "_admin.projects_write": (p_id,)},
+                             "Wrong DB pull_list dictionary")
             self.fs.file_delete.assert_not_called()
         return
 
             self.fs.file_delete.assert_not_called()
         return
 
@@ -841,8 +842,9 @@ class Test_NsdTopic(TestCase):
             self.assertEqual(db_s1_args[0][1]["_id"], did, "Wrong DB ID")
             self.assertIn(p_id, db_s1_args[0][1]["_admin.projects_write.cont"], "Wrong DB filter")
             self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
             self.assertEqual(db_s1_args[0][1]["_id"], did, "Wrong DB ID")
             self.assertIn(p_id, db_s1_args[0][1]["_admin.projects_write.cont"], "Wrong DB filter")
             self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
-            self.assertIn("_admin.projects_read." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
-            self.assertIn("_admin.projects_write." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
+            self.assertEqual(db_s1_args[1]["pull_list"],
+                             {"_admin.projects_read": (p_id,), "_admin.projects_write": (p_id,)},
+                             "Wrong DB pull_list dictionary")
             self.fs.file_delete.assert_not_called()
         return
 
             self.fs.file_delete.assert_not_called()
         return
 
index 6d82b0f..14abde7 100644 (file)
@@ -276,8 +276,9 @@ class TestNsrTopic(unittest.TestCase):
             self.assertEqual(db_s1_args[0][0], self.nsr_topic.topic, "Wrong DB topic")
             self.assertEqual(db_s1_args[0][1]["_id"], self.nsr_id, "Wrong DB ID")
             self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
             self.assertEqual(db_s1_args[0][0], self.nsr_topic.topic, "Wrong DB topic")
             self.assertEqual(db_s1_args[0][1]["_id"], self.nsr_id, "Wrong DB ID")
             self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
-            self.assertIn("_admin.projects_read." + p_other, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
-            self.assertIn("_admin.projects_write." + p_other, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
+            self.assertEqual(db_s1_args[1]["pull_list"],
+                             {"_admin.projects_read": [p_other], "_admin.projects_write": [p_other]},
+                             "Wrong DB pull_list dictionary")
             self.fs.file_delete.assert_not_called()
         with self.subTest(i=4, t='Delete with force and admin'):
             self.db.del_one.reset_mock()
             self.fs.file_delete.assert_not_called()
         with self.subTest(i=4, t='Delete with force and admin'):
             self.db.del_one.reset_mock()