Fix bug 1432: No support for alternative images for sol006
[osm/LCM.git] / osm_lcm / ns.py
index a90f4e8..e08e2d6 100644 (file)
@@ -783,8 +783,23 @@ class NsLcm(LcmBase):
                 ns_flavor = target["flavor"][int(vdur["ns-flavor-id"])]
                 if target_vim not in ns_flavor["vim_info"]:
                     ns_flavor["vim_info"][target_vim] = {}
-                # image
-                ns_image = target["image"][int(vdur["ns-image-id"])]
+
+                # deal with images
+                # in case alternative images are provided we must check if they should be applied
+                # for the vim_type, modify the vim_type taking into account
+                ns_image_id = int(vdur["ns-image-id"])
+                if vdur.get("alt-image-ids"):
+                    db_vim = get_vim_account(vnfr["vim-account-id"])
+                    vim_type = db_vim["vim_type"]
+                    for alt_image_id in vdur.get("alt-image-ids"):
+                        ns_alt_image = target["image"][int(alt_image_id)]
+                        if vim_type == ns_alt_image.get("vim-type"):
+                            # must use alternative image
+                            self.logger.debug("use alternative image id: {}".format(alt_image_id))
+                            ns_image_id = alt_image_id
+                            vdur["ns-image-id"] = ns_image_id
+                            break
+                ns_image = target["image"][int(ns_image_id)]
                 if target_vim not in ns_image["vim_info"]:
                     ns_image["vim_info"][target_vim] = {}
 
@@ -1202,7 +1217,7 @@ class NsLcm(LcmBase):
                 )
 
                 step = "create execution environment"
-                self.logger.debug(logging_text + step)
+                self.logger.debug(logging_text + step)                
 
                 ee_id = None
                 credentials = None
@@ -1215,15 +1230,16 @@ 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,
                         db_dict=db_dict,
-                        cloud_name=vca_cloud,
-                        credential_name=vca_cloud_credential,
+                        config=osm_config,
+                        artifact_path=artifact_path,
+                        vca_type=vca_type
                     )
-                else:
+                else:                    
                     ee_id, credentials = await self.vca_map[vca_type].create_execution_environment(
                         namespace=namespace,
                         reuse_ee_id=ee_id,
@@ -1686,7 +1702,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
@@ -1843,7 +1859,7 @@ class NsLcm(LcmBase):
                             )
                 for kdud in get_kdu_list(vnfd):
                     kdu_name = kdud["name"]
-                    descriptor_config = get_kdu_configuration(vnfd, kdu_name)
+                    descriptor_config = kdud.get('kdu-configuration')
                     if descriptor_config:
                         vdu_id = None
                         vdu_index = 0
@@ -1885,7 +1901,7 @@ class NsLcm(LcmBase):
                 vdu_name = None
 
                 # Get additional parameters
-                deploy_params = {"OSM": get_osm_params(db_vnfr)}
+                deploy_params = {"OSM": {"vim_account_id": ns_params["vimAccountId"]}}
                 if db_nsr.get("additionalParamsForNs"):
                     deploy_params.update(parse_yaml_strings(db_nsr["additionalParamsForNs"].copy()))
                 base_folder = nsd["_admin"]["storage"]
@@ -2308,7 +2324,8 @@ 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"]
@@ -2326,7 +2343,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,
@@ -2376,9 +2394,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"])
@@ -3441,9 +3459,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.get("initial-config-primitive", []):
+                    actions.add(primitive["name"])
+                for primitive in kdu_configuration.get("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):