From d64e274c9164f8b57d08df5b80d516eb69def066 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Thu, 25 Feb 2021 20:19:18 +0100 Subject: [PATCH] Fix bug 1412: Generate kdu instance from LCM Change-Id: Ic8fbcd1d78eeef60ec0c943bcd233f8d8ee4f166 Signed-off-by: David Garcia --- osm_lcm/lcm_helm_conn.py | 30 +++++++++++++++++++---------- osm_lcm/ns.py | 13 ++++++++++--- osm_lcm/tests/test_lcm_helm_conn.py | 8 +++++++- osm_lcm/tests/test_ns.py | 4 +++- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/osm_lcm/lcm_helm_conn.py b/osm_lcm/lcm_helm_conn.py index 27c330f..978b061 100644 --- a/osm_lcm/lcm_helm_conn.py +++ b/osm_lcm/lcm_helm_conn.py @@ -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 diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index e5b1060..75db8e5 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -1232,7 +1232,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, @@ -2192,7 +2192,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, @@ -2200,7 +2205,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 diff --git a/osm_lcm/tests/test_lcm_helm_conn.py b/osm_lcm/tests/test_lcm_helm_conn.py index db9f47d..47838b3 100644 --- a/osm_lcm/tests/test_lcm_helm_conn.py +++ b/osm_lcm/tests/test_lcm_helm_conn.py @@ -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: :.") 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) diff --git a/osm_lcm/tests/test_ns.py b/osm_lcm/tests/test_ns.py index 6a609dc..c0dda15 100644 --- a/osm_lcm/tests/test_ns.py +++ b/osm_lcm/tests/test_ns.py @@ -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) -- 2.17.1