cluster name check dependency with profiles 99/14899/3
authorshrinithi <shrinithi.r@tataelxsi.co.in>
Wed, 29 Jan 2025 06:01:31 +0000 (06:01 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 11 Feb 2025 15:12:58 +0000 (16:12 +0100)
Change-Id: If50cb85abfe967bcfe554e739c579859e66f49df
Signed-off-by: shrinithi <shrinithi.r@tataelxsi.co.in>
osm_nbi/acm_topic.py

index 27273f9..12ee1a8 100644 (file)
@@ -263,14 +263,24 @@ class ACMTopic(BaseTopic, ACMOperationTopic):
         return
 
     def cluster_unique_name_check(self, session, name):
+        # First check using the method you have for unique name validation
         self.check_unique_name(session, name)
         _filter = {"name": name}
-        topic = "k8sclusters"
-        if self.db.get_one(topic, _filter, fail_on_empty=False, fail_on_more=False):
-            raise EngineException(
-                "name '{}' already exists".format(name),
-                HTTPStatus.CONFLICT,
-            )
+        topics = [
+            "k8sclusters",
+            "k8sapp",
+            "k8sinfra_config",
+            "k8sinfra_controller",
+            "k8sresource",
+        ]
+
+        # Loop through each topic to check if the name already exists in any of them
+        for item in topics:
+            if self.db.get_one(item, _filter, fail_on_empty=False, fail_on_more=False):
+                raise EngineException(
+                    f"name '{name}' already exists in topic '{item}'",
+                    HTTPStatus.CONFLICT,
+                )
 
     def list_both(self, session, filter_q=None, api_req=False):
         """List all clusters from both new and old APIs"""