Fix bug 1368 and 1369 93/10093/6
authorDavid Garcia <david.garcia@canonical.com>
Thu, 10 Dec 2020 11:52:52 +0000 (12:52 +0100)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 11 Dec 2020 07:46:46 +0000 (08:46 +0100)
Change-Id: I3c88b3a9295ce0b105410a76356e88da0f1e24a5
Signed-off-by: David Garcia <david.garcia@canonical.com>
osm_lcm/ns.py
osm_lcm/tests/test_db_descriptors.py
osm_lcm/tests/test_ns.py

index 8cde03a..c7e0184 100644 (file)
@@ -1687,7 +1687,7 @@ class NsLcm(LcmBase):
                     vnfd = self.db.get_one("vnfds", {"_id": vnfd_id})
 
                     # store vnfd
-                    db_vnfds.append(vnfd)          # vnfd's indexed by id
+                    db_vnfds.append(vnfd)
 
             # Get or generates the _admin.deployed.VCA list
             vca_deployed_list = None
@@ -2309,17 +2309,18 @@ class NsLcm(LcmBase):
                     # Step 0: Prepare and set parameters
                     desc_params = parse_yaml_strings(kdur.get("additionalParams"))
                     vnfd_id = vnfr_data.get('vnfd-id')
-                    kdud = next(kdud for kdud in db_vnfds[vnfd_id]["kdu"] if kdud["name"] == kdur["kdu-name"])
+                    vnfd_with_id = find_in_list(db_vnfds, lambda vnfd: vnfd["_id"] == vnfd_id)
+                    kdud = next(kdud for kdud in vnfd_with_id["kdu"] if kdud["name"] == kdur["kdu-name"])
                     namespace = kdur.get("k8s-namespace")
                     if kdur.get("helm-chart"):
-                        kdumodel = kdur["helm-chart"]
+                        kdumodel = kdur["helm-chart"]["kdu-model-locator"]
                         # Default version: helm3, if helm-version is v2 assign v2
                         k8sclustertype = "helm-chart-v3"
                         self.logger.debug("kdur: {}".format(kdur))
                         if kdur.get("helm-version") and kdur.get("helm-version") == "v2":
                             k8sclustertype = "helm-chart"
                     elif kdur.get("juju-bundle"):
-                        kdumodel = kdur["juju-bundle"]
+                        kdumodel = kdur["juju-bundle"]["kdu-model-locator"]
                         k8sclustertype = "juju-bundle"
                     else:
                         raise LcmException("kdu type for kdu='{}.{}' is neither helm-chart nor "
@@ -2327,7 +2328,8 @@ class NsLcm(LcmBase):
                                            format(vnfr_data["member-vnf-index-ref"], kdur["kdu-name"]))
                     # check if kdumodel is a file and exists
                     try:
-                        storage = deep_get(db_vnfds.get(vnfd_id), ('_admin', 'storage'))
+                        vnfd_with_id = find_in_list(db_vnfds, lambda vnfd: vnfd["_id"] == vnfd_id)
+                        storage = deep_get(vnfd_with_id, ('_admin', 'storage'))
                         if storage and storage.get('pkg-dir'):  # may be not present if vnfd has not artifacts
                             # path format: /vnfdid/pkkdir/helm-charts|juju-bundles/kdumodel
                             filename = '{}/{}/{}s/{}'.format(storage["folder"], storage["pkg-dir"], k8sclustertype,
@@ -2377,9 +2379,9 @@ class NsLcm(LcmBase):
                     db_path = "_admin.deployed.K8s.{}".format(index)
                     db_nsr_update[db_path] = k8s_instance_info
                     self.update_db_2("nsrs", nsr_id, db_nsr_update)
-
+                    vnfd_with_id = find_in_list(db_vnfds, lambda vnf: vnf["_id"] == vnfd_id)
                     task = asyncio.ensure_future(
-                        self._install_kdu(nsr_id, db_path, vnfr_data, kdu_index, kdud, db_vnfds[vnfd_id],
+                        self._install_kdu(nsr_id, db_path, vnfr_data, kdu_index, kdud, vnfd_with_id,
                                           k8s_instance_info, k8params=desc_params, timeout=600))
                     self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "instantiate_KDU-{}".format(index), task)
                     task_instantiation_info[task] = "Deploying KDU {}".format(kdur["kdu-name"])
@@ -3442,9 +3444,14 @@ class NsLcm(LcmBase):
                     desc_params = parse_yaml_strings(db_vnfr.get("additionalParamsForVnf"))
             else:
                 desc_params = parse_yaml_strings(db_nsr.get("additionalParamsForNs"))
-
-            if kdu_name and get_kdu_configuration(db_vnfd):
-                kdu_action = True if not get_kdu_configuration(db_vnfd)["juju"] else False
+            if kdu_name and get_kdu_configuration(db_vnfd, kdu_name):
+                kdu_configuration = get_kdu_configuration(db_vnfd, kdu_name)
+                actions = set()
+                for primitive in kdu_configuration["initial-config-primitive"]:
+                    actions.add(primitive["name"])
+                for primitive in kdu_configuration["config-primitive"]:
+                    actions.add(primitive["name"])
+                kdu_action = True if primitive_name in actions else False
 
             # TODO check if ns is in a proper status
             if kdu_name and (primitive_name in ("upgrade", "rollback", "status") or kdu_action):
index 080d88d..2a346b0 100644 (file)
@@ -1254,12 +1254,16 @@ db_vnfrs_text = """
         k8s-cluster:
             id: e7169dab-f71a-4f1f-b82b-432605e8c4b3
         kdu-name: ldap
-        helm-chart: stable/openldap:1.2.1
+        helm-chart:
+          kdu-model-locator:
+            stable/openldap:1.2.1
     -   ip-address: null
         k8s-cluster:
             id: e7169dab-f71a-4f1f-b82b-432605e8c4b3
         kdu-name: mongo
-        helm-chart: stable/mongodb
+        helm-chart:
+          kdu-model-locator:
+            stable/mongodb
     member-vnf-index-ref: multikdu
     nsr-id-ref: 0bcb701c-ee4d-41ab-8ee6-f4156f7f114d
     vdur: []
index 2a1b125..6a609dc 100644 (file)
@@ -529,7 +529,7 @@ class TestMyNS(asynctest.TestCase):
         db_vnfr = self.db.get_one("vnfrs", {"nsr-id-ref": nsr_id, "member-vnf-index-ref": "multikdu"})
         db_vnfrs = {"multikdu": db_vnfr}
         db_vnfd = self.db.get_one("vnfds", {"_id": db_vnfr["vnfd-id"]})
-        db_vnfds = {db_vnfd["_id"]: db_vnfd}
+        db_vnfds = [db_vnfd]
         task_register = {}
         logging_text = "KDU"
         self.my_ns.k8sclusterhelm3.install = asynctest.CoroutineMock(return_value="k8s_id")