Cluster name update check unique name and replace in both collection 77/14877/8
authoryshah <shahithya.y@tataelxsi.co.in>
Thu, 16 Jan 2025 12:06:40 +0000 (12:06 +0000)
committeryshah <shahithya.y@tataelxsi.co.in>
Wed, 29 Jan 2025 07:05:30 +0000 (07:05 +0000)
Change-Id: I9ddc891591ec58e8d3cb51118966fb1ebe6ff0f9
Signed-off-by: yshah <shahithya.y@tataelxsi.co.in>
osm_nbi/acm_topic.py
osm_nbi/k8s_topics.py

index 87087b7..27273f9 100644 (file)
@@ -262,22 +262,6 @@ class ACMTopic(BaseTopic, ACMOperationTopic):
         self.db.set_one("k8sclusters", {"_id": item_1["_id"]}, item_1)
         return
 
-    def edit_extra_before(self, session, _id, indata=None, kwargs=None, content=None):
-        check = self.db.get_one(self.topic, {"_id": _id})
-        if self.topic != "clusters":
-            if check["default"] is True:
-                raise EngineException(
-                    "Cannot edit default profiles",
-                    HTTPStatus.UNPROCESSABLE_ENTITY,
-                )
-            if "name" in indata:
-                if check["name"] == indata["name"]:
-                    pass
-                else:
-                    self.check_unique_name(session, indata["name"])
-
-        return True
-
     def cluster_unique_name_check(self, session, name):
         self.check_unique_name(session, name)
         _filter = {"name": name}
@@ -323,6 +307,17 @@ class ProfileTopic(ACMTopic):
     def __init__(self, db, fs, msg, auth):
         super().__init__(db, fs, msg, auth)
 
+    def edit_extra_before(self, session, _id, indata=None, kwargs=None, content=None):
+        check = self.db.get_one(self.topic, {"_id": _id})
+        if check["default"] is True:
+            raise EngineException(
+                "Cannot edit default profiles",
+                HTTPStatus.UNPROCESSABLE_ENTITY,
+            )
+        if "name" in indata and check["name"] != indata["name"]:
+            self.check_unique_name(session, indata["name"])
+        return True
+
     def delete_extra_before(self, session, _id, db_content, not_send_msg=None):
         op_id = self.common_delete(_id, db_content)
         return {"profile_id": _id, "operation_id": op_id}
index d4ff80b..c930472 100644 (file)
@@ -365,6 +365,34 @@ class ClusterTopic(ACMTopic):
                 error_msg = "Add / remove operation is only applicable"
                 raise EngineException(error_msg, HTTPStatus.UNPROCESSABLE_ENTITY)
 
+    def edit_extra_before(self, session, _id, indata=None, kwargs=None, content=None):
+        check = self.db.get_one(self.topic, {"_id": _id})
+        if "name" in indata and check["name"] != indata["name"]:
+            self.check_unique_name(session, indata["name"])
+            _filter = {"name": indata["name"]}
+            topic_list = [
+                "k8sclusters",
+                "k8sinfra_controller",
+                "k8sinfra_config",
+                "k8sapp",
+                "k8sresource",
+            ]
+            # Check unique name for k8scluster and profiles
+            for topic in topic_list:
+                if self.db.get_one(
+                    topic, _filter, fail_on_empty=False, fail_on_more=False
+                ):
+                    raise EngineException(
+                        "name '{}' already exists for {}".format(indata["name"], topic),
+                        HTTPStatus.CONFLICT,
+                    )
+            # Replace name in k8scluster and profiles
+            for topic in topic_list:
+                data = self.db.get_one(topic, {"name": check["name"]})
+                data["name"] = indata["name"]
+                self.db.replace(topic, data["_id"], data)
+        return True
+
     def add_profile(self, session, _id, item, indata=None):
         indata = self._remove_envelop(indata)
         operation_params = indata