Syncronize with fs before deploy package with ee
[osm/LCM.git] / osm_lcm / lcm_helm_conn.py
index 146da9d..e204185 100644 (file)
@@ -20,6 +20,7 @@ import yaml
 import asyncio
 import socket
 import uuid
+import os
 
 from grpclib.client import Channel
 
@@ -123,6 +124,7 @@ class LCMHelmConn(N2VCConnector):
                                            reuse_ee_id: str = None,
                                            progress_timeout: float = None,
                                            total_timeout: float = None,
+                                           config: dict = None,
                                            artifact_path: str = None,
                                            vca_type: str = None) -> (str, dict):
         """
@@ -137,8 +139,9 @@ class LCMHelmConn(N2VCConnector):
         :param str reuse_ee_id: ee id from an older execution. TODO - right now this params is not used
         :param float progress_timeout:
         :param float total_timeout:
-        :param str artifact_path  path of package content
-        :param str vca_type  Type of vca, not used as assumed of type helm
+        :param dict config:  General variables to instantiate KDU
+        :param str artifact_path:  path of package content
+        :param str vca_type:  Type of vca, not used as assumed of type helm
         :returns str, dict: id of the new execution environment including namespace.helm_id
         and credentials object set to None as all credentials should be osm kubernetes .kubeconfig
         """
@@ -155,7 +158,9 @@ class LCMHelmConn(N2VCConnector):
                 message="artifact_path is mandatory", bad_args=["artifact_path"]
             )
 
-        # Validate artifact-path exists
+        # Validate artifact-path exists and sync path
+        from_path = os.path.split(artifact_path)[0]
+        self.fs.sync(from_path)
 
         # remove / in charm path
         while artifact_path.find("//") >= 0:
@@ -177,15 +182,23 @@ class LCMHelmConn(N2VCConnector):
             # Call helm conn install
             # Obtain system cluster id from database
             system_cluster_uuid = self._get_system_cluster_id()
+            # Add parameter osm if exist to global
+            if config and config.get("osm"):
+                if not config.get("global"):
+                    config["global"] = {}
+                config["global"]["osm"] = config.get("osm")
 
             self.log.debug("install helm chart: {}".format(full_path))
             helm_id = await self._k8sclusterhelm.install(system_cluster_uuid, kdu_model=full_path,
                                                          namespace=self._KUBECTL_OSM_NAMESPACE,
+                                                         params=config,
                                                          db_dict=db_dict,
                                                          timeout=progress_timeout)
 
             ee_id = "{}.{}".format(self._KUBECTL_OSM_NAMESPACE, helm_id)
             return ee_id, None
+        except N2VCException:
+            raise
         except Exception as e:
             self.log.error("Error deploying chart ee: {}".format(e), exc_info=True)
             raise N2VCException("Error deploying chart ee: {}".format(e))
@@ -391,6 +404,8 @@ class LCMHelmConn(N2VCConnector):
             # Uninstall chart
             await self._k8sclusterhelm.uninstall(system_cluster_uuid, helm_id)
             self.log.info("ee_id: {} deleted".format(ee_id))
+        except N2VCException:
+            raise
         except Exception as e:
             self.log.error("Error deleting ee id: {}: {}".format(ee_id, e), exc_info=True)
             raise N2VCException("Error deleting ee id {}: {}".format(ee_id, e))
@@ -478,6 +493,10 @@ class LCMHelmConn(N2VCConnector):
         if not self._system_cluster_id:
             db_k8cluster = self.db.get_one("k8sclusters", {"name": self._KUBECTL_OSM_CLUSTER_NAME})
             k8s_hc_id = deep_get(db_k8cluster, ("_admin", "helm-chart", "id"))
+            if not k8s_hc_id:
+                self.log.error("osm system cluster has not been properly initialized for helm connector, "
+                               "helm-chart id is not defined")
+                raise N2VCException("osm system cluster has not been properly initialized for helm connector")
             self._system_cluster_id = k8s_hc_id
         return self._system_cluster_id