Fix bug 875: VIM gets deleted when the Instance is Running 99/8199/5
authordelacruzramo <pedro.delacruzramos@altran.com>
Thu, 21 Nov 2019 10:09:16 +0000 (11:09 +0100)
committerdelacruzramo <pedro.delacruzramos@altran.com>
Thu, 5 Dec 2019 09:01:21 +0000 (10:01 +0100)
Change-Id: I74f942e3ad17e1d61bbe507ddf6ad2e9755be66c
Signed-off-by: delacruzramo <pedro.delacruzramos@altran.com>
osm_nbi/admin_topics.py
osm_nbi/tests/test_admin_topics.py

index ada9c7b..5b37bf0 100644 (file)
@@ -368,6 +368,21 @@ class VimAccountTopic(CommonVimWimSdn):
     config_to_encrypt = {"1.1": ("admin_password", "nsx_password", "vcenter_password"),
                          "default": ("admin_password", "nsx_password", "vcenter_password", "vrops_password")}
 
+    def check_conflict_on_del(self, session, _id, db_content):
+        """
+        Check if deletion can be done because of dependencies if it is not force. To override
+        :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
+        :param _id: internal _id
+        :param db_content: The database content of this item _id
+        :return: None if ok or raises EngineException with the conflict
+        """
+        if session["force"]:
+            return
+        # check if used by VNF
+        if self.db.get_list("vnfrs", {"vim-account-id": _id}):
+            raise EngineException("There is at least one VNF using this VIM account", http_code=HTTPStatus.CONFLICT)
+        super().check_conflict_on_del(session, _id, db_content)
+
 
 class WimAccountTopic(CommonVimWimSdn):
     topic = "wim_accounts"
index 5597979..04a64f1 100755 (executable)
@@ -716,6 +716,7 @@ class Test_CommonVimWimSdn(TestCase):
         ro_pid = str(uuid4())
         rw_pid = str(uuid4())
         cvws = {"_id": cid, "name": self.test_name}
+        self.db.get_list.return_value = []
         with self.subTest(i=1):
             cvws["_admin"] = {"projects_read": [test_pid, ro_pid, rw_pid], "projects_write": [test_pid, rw_pid]}
             self.db.get_one.return_value = cvws
@@ -729,7 +730,7 @@ class Test_CommonVimWimSdn(TestCase):
                              "Wrong read-only projects update")
             self.assertEqual(self.db.set_one.call_args[1]["update_dict"]["_admin.projects_write"], [rw_pid],
                              "Wrong read/write projects update")
-        with self.subTest(i=3):
+        with self.subTest(i=2):
             now = time()
             cvws["_admin"] = {"projects_read": [test_pid], "projects_write": [test_pid], "operations": []}
             self.db.get_one.return_value = cvws