Bug 1959 fixed: added the functionality of obtaining the KDU status for KNFs based... 20/11820/9
authorPedro Escaleira <escaleira@av.it.pt>
Fri, 1 Apr 2022 00:49:22 +0000 (01:49 +0100)
committercubag <gcuba@whitestack.com>
Tue, 26 Apr 2022 02:55:12 +0000 (04:55 +0200)
Also added the feature of updating the K8s namespace in the
_on_update_k8s_db method.

Change-Id: I7f3115091916c661eb0b7051a9ec7854bf63b81d
Signed-off-by: Pedro Escaleira <escaleira@av.it.pt>
osm_lcm/ns.py

index 69f2d07..3eca8aa 100644 (file)
@@ -328,43 +328,49 @@ class NsLcm(LcmBase):
             self.logger.warn("Error updating NS state for ns={}: {}".format(nsr_id, e))
 
     async def _on_update_k8s_db(
-        self, cluster_uuid, kdu_instance, filter=None, vca_id=None
+        self, cluster_uuid, kdu_instance, filter=None, vca_id=None, cluster_type="juju"
     ):
         """
         Updating vca status in NSR record
         :param cluster_uuid: UUID of a k8s cluster
         :param kdu_instance: The unique name of the KDU instance
         :param filter: To get nsr_id
+        :cluster_type: The cluster type (juju, k8s)
         :return: none
         """
 
         # self.logger.debug("_on_update_k8s_db(cluster_uuid={}, kdu_instance={}, filter={}"
         #                   .format(cluster_uuid, kdu_instance, filter))
 
+        nsr_id = filter.get("_id")
         try:
-            nsr_id = filter.get("_id")
-
-            # get vca status for NS
-            vca_status = await self.k8sclusterjuju.status_kdu(
-                cluster_uuid,
-                kdu_instance,
-                complete_status=True,
+            vca_status = await self.k8scluster_map[cluster_type].status_kdu(
+                cluster_uuid=cluster_uuid,
+                kdu_instance=kdu_instance,
                 yaml_format=False,
+                complete_status=True,
                 vca_id=vca_id,
             )
+
             # vcaStatus
             db_dict = dict()
             db_dict["vcaStatus"] = {nsr_id: vca_status}
 
-            await self.k8sclusterjuju.update_vca_status(
-                db_dict["vcaStatus"],
-                kdu_instance,
-                vca_id=vca_id,
+            if cluster_type in ("juju-bundle", "juju"):
+                # TODO -> this should be done in a more uniform way, I think in N2VC, in order to update the K8s VCA
+                #  status in a similar way between Juju Bundles and Helm Charts on this side
+                await self.k8sclusterjuju.update_vca_status(
+                    db_dict["vcaStatus"],
+                    kdu_instance,
+                    vca_id=vca_id,
+                )
+
+            self.logger.debug(
+                f"Obtained VCA status for cluster type '{cluster_type}': {vca_status}"
             )
 
             # write to database
             self.update_db_2("nsrs", nsr_id, db_dict)
-
         except (asyncio.CancelledError, asyncio.TimeoutError):
             raise
         except Exception as e:
@@ -4654,10 +4660,18 @@ class NsLcm(LcmBase):
         db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
         vca_id = self.get_vca_id({}, db_nsr)
         if db_nsr["_admin"]["deployed"]["K8s"]:
-            for k8s_index, k8s in enumerate(db_nsr["_admin"]["deployed"]["K8s"]):
-                cluster_uuid, kdu_instance = k8s["k8scluster-uuid"], k8s["kdu-instance"]
+            for _, k8s in enumerate(db_nsr["_admin"]["deployed"]["K8s"]):
+                cluster_uuid, kdu_instance, cluster_type = (
+                    k8s["k8scluster-uuid"],
+                    k8s["kdu-instance"],
+                    k8s["k8scluster-type"],
+                )
                 await self._on_update_k8s_db(
-                    cluster_uuid, kdu_instance, filter={"_id": nsr_id}, vca_id=vca_id
+                    cluster_uuid=cluster_uuid,
+                    kdu_instance=kdu_instance,
+                    filter={"_id": nsr_id},
+                    vca_id=vca_id,
+                    cluster_type=cluster_type,
                 )
         else:
             for vca_index, _ in enumerate(db_nsr["_admin"]["deployed"]["VCA"]):