Fix bug 1412: Generate kdu instance from LCM 16/10416/1
authorDavid Garcia <david.garcia@canonical.com>
Thu, 25 Feb 2021 19:19:18 +0000 (20:19 +0100)
committergarciadav <david.garcia@canonical.com>
Tue, 2 Mar 2021 08:08:51 +0000 (09:08 +0100)
Change-Id: Ic8fbcd1d78eeef60ec0c943bcd233f8d8ee4f166
Signed-off-by: David Garcia <david.garcia@canonical.com>
(cherry picked from commit d64e274c9164f8b57d08df5b80d516eb69def066)

osm_lcm/lcm_helm_conn.py
osm_lcm/ns.py
osm_lcm/tests/test_lcm_helm_conn.py
osm_lcm/tests/test_ns.py

index 27c330f..978b061 100644 (file)
@@ -233,17 +233,27 @@ class LCMHelmConn(N2VCConnector, LcmBase):
 
             self.log.debug("install helm chart: {}".format(full_path))
             if vca_type == "helm":
-                helm_id = await self._k8sclusterhelm2.install(system_cluster_uuid, kdu_model=full_path,
-                                                              namespace=self._KUBECTL_OSM_NAMESPACE,
-                                                              params=config,
-                                                              db_dict=db_dict,
-                                                              timeout=progress_timeout)
+                helm_id = self._k8sclusterhelm2.generate_kdu_instance_name(
+                    db_dict=db_dict,
+                    kdu_model=full_path,
+                )
+                await self._k8sclusterhelm2.install(system_cluster_uuid, kdu_model=full_path,
+                                                    kdu_instance=helm_id,
+                                                    namespace=self._KUBECTL_OSM_NAMESPACE,
+                                                    params=config,
+                                                    db_dict=db_dict,
+                                                    timeout=progress_timeout)
             else:
-                helm_id = await self._k8sclusterhelm3.install(system_cluster_uuid, kdu_model=full_path,
-                                                              namespace=self._KUBECTL_OSM_NAMESPACE,
-                                                              params=config,
-                                                              db_dict=db_dict,
-                                                              timeout=progress_timeout)
+                helm_id = self._k8sclusterhelm2.generate_kdu_instance_name(
+                    db_dict=db_dict,
+                    kdu_model=full_path,
+                )
+                await self._k8sclusterhelm3.install(system_cluster_uuid, kdu_model=full_path,
+                                                    kdu_instance=helm_id,
+                                                    namespace=self._KUBECTL_OSM_NAMESPACE,
+                                                    params=config,
+                                                    db_dict=db_dict,
+                                                    timeout=progress_timeout)
 
             ee_id = "{}:{}.{}".format(vca_type, self._KUBECTL_OSM_NAMESPACE, helm_id)
             return ee_id, None
index e08e2d6..26eed85 100644 (file)
@@ -1230,7 +1230,7 @@ class NsLcm(LcmBase):
                         cloud_name=vca_k8s_cloud,
                         credential_name=vca_k8s_cloud_credential,
                     )
-                elif vca_type == "helm" or vca_type == "helm-v3":                    
+                elif vca_type == "helm" or vca_type == "helm-v3":     
                     ee_id, credentials = await self.vca_map[vca_type].create_execution_environment(
                         namespace=namespace,
                         reuse_ee_id=ee_id,
@@ -2190,7 +2190,12 @@ class NsLcm(LcmBase):
                                "filter": {"_id": nsr_id},
                                "path": nsr_db_path}
 
-            kdu_instance = await self.k8scluster_map[k8sclustertype].install(
+            kdu_instance = self.k8scluster_map[k8sclustertype].generate_kdu_instance_name(
+                db_dict=db_dict_install,
+                kdu_model=k8s_instance_info["kdu-model"],
+            )
+            self.update_db_2("nsrs", nsr_id, {nsr_db_path + ".kdu-instance": kdu_instance})
+            await self.k8scluster_map[k8sclustertype].install(
                 cluster_uuid=k8s_instance_info["k8scluster-uuid"],
                 kdu_model=k8s_instance_info["kdu-model"],
                 atomic=True,
@@ -2198,7 +2203,9 @@ class NsLcm(LcmBase):
                 db_dict=db_dict_install,
                 timeout=timeout,
                 kdu_name=k8s_instance_info["kdu-name"],
-                namespace=k8s_instance_info["namespace"])
+                namespace=k8s_instance_info["namespace"],
+                kdu_instance=kdu_instance,
+            )
             self.update_db_2("nsrs", nsr_id, {nsr_db_path + ".kdu-instance": kdu_instance})
 
             # Obtain services to obtain management service ip
index db9f47d..47838b3 100644 (file)
@@ -67,7 +67,12 @@ class TestLcmHelmConn(asynctest.TestCase):
         db_dict = {}
         artifact_path = "helm_sample_charm"
         helm_chart_id = "helm_sample_charm_0001"
-        self.helm_conn._k8sclusterhelm3.install = asynctest.CoroutineMock(return_value=helm_chart_id)
+        self.helm_conn._k8sclusterhelm3.install = asynctest.CoroutineMock(return_value=None)
+        self.helm_conn._k8sclusterhelm3.generate_kdu_instance_name = Mock()
+        self.helm_conn._k8sclusterhelm3.generate_kdu_instance_name.return_value = helm_chart_id        
+        self.helm_conn._k8sclusterhelm2.generate_kdu_instance_name = Mock()
+        self.helm_conn._k8sclusterhelm2.generate_kdu_instance_name.return_value = helm_chart_id
+
         self.db.get_one.return_value = {"_admin": {"helm-chart-v3": {"id": "myk8s_id"}}}
         ee_id, _ = await self.helm_conn.create_execution_environment(namespace,
                                                                      db_dict,
@@ -77,6 +82,7 @@ class TestLcmHelmConn(asynctest.TestCase):
                          "Check ee_id format: <helm-version>:<default namespace>.<helm_chart-id>")
         self.helm_conn._k8sclusterhelm3.install.assert_called_once_with("myk8s_id",
                                                                         kdu_model="/helm_sample_charm",
+                                                                        kdu_instance=helm_chart_id,
                                                                         namespace="osm", db_dict=db_dict,
                                                                         params=None, timeout=None)
 
index 6a609dc..c0dda15 100644 (file)
@@ -532,7 +532,9 @@ class TestMyNS(asynctest.TestCase):
         db_vnfds = [db_vnfd]
         task_register = {}
         logging_text = "KDU"
-        self.my_ns.k8sclusterhelm3.install = asynctest.CoroutineMock(return_value="k8s_id")
+        self.my_ns.k8sclusterhelm3.generate_kdu_instance_name = asynctest.mock.Mock()
+        self.my_ns.k8sclusterhelm3.generate_kdu_instance_name.return_value = "k8s_id"
+        self.my_ns.k8sclusterhelm3.install = asynctest.CoroutineMock()
         self.my_ns.k8sclusterhelm3.synchronize_repos = asynctest.CoroutineMock(return_value=("", ""))
         self.my_ns.k8sclusterhelm3.get_services = asynctest.CoroutineMock(return_value=([]))
         await self.my_ns.deploy_kdus(logging_text, nsr_id, nslcmop_id, db_vnfrs, db_vnfds, task_register)