Fix Bug 2009 use existing volumes as instantiation parameters
[osm/NBI.git] / osm_nbi / instance_topics.py
index 7bfff0b..62df4f8 100644 (file)
@@ -27,6 +27,7 @@ from osm_nbi.validation import (
     ns_action,
     ns_scale,
     ns_update,
+    ns_heal,
     nsi_instantiate,
     ns_migrate,
 )
@@ -557,6 +558,9 @@ class NsrTopic(BaseTopic):
             "image": [],
             "affinity-or-anti-affinity-group": [],
         }
+        if "revision" in nsd["_admin"]:
+            nsr_descriptor["revision"] = nsd["_admin"]["revision"]
+
         ns_request["nsr_id"] = nsr_id
         if ns_request and ns_request.get("config-units"):
             nsr_descriptor["config-units"] = ns_request["config-units"]
@@ -1160,6 +1164,7 @@ class NsLcmOpTopic(BaseTopic):
         "action": ns_action,
         "update": ns_update,
         "scale": ns_scale,
+        "heal": ns_heal,
         "terminate": ns_terminate,
         "migrate": ns_migrate,
     }
@@ -1172,7 +1177,7 @@ class NsLcmOpTopic(BaseTopic):
         """
         Check that user has enter right parameters for the operation
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
-        :param operation: it can be: instantiate, terminate, action, update. TODO: heal
+        :param operation: it can be: instantiate, terminate, action, update, heal
         :param indata: descriptor with the parameters of the operation
         :return: None
         """
@@ -1182,6 +1187,8 @@ class NsLcmOpTopic(BaseTopic):
             self._check_scale_ns_operation(indata, nsr)
         elif operation == "update":
             self._check_update_ns_operation(indata, nsr)
+        elif operation == "heal":
+            self._check_heal_ns_operation(indata, nsr)
         elif operation == "instantiate":
             self._check_instantiate_ns_operation(indata, nsr, session)
 
@@ -1384,6 +1391,9 @@ class NsLcmOpTopic(BaseTopic):
                 )
             )
 
+    def _check_heal_ns_operation(self, indata, nsr):
+        return
+
     def _check_instantiate_ns_operation(self, indata, nsr, session):
         vnf_member_index_to_vnfd = {}  # map between vnf_member_index to vnf descriptor.
         vim_accounts = []
@@ -1478,7 +1488,7 @@ class NsLcmOpTopic(BaseTopic):
                 if in_vdu["id"] == vdu["id"]:
                     for volume in get_iterable(in_vdu.get("volume")):
                         for volumed in get_iterable(vdu.get("virtual-storage-desc")):
-                            if volumed["id"] == volume["name"]:
+                            if volumed == volume["name"]:
                                 break
                         else:
                             raise EngineException(
@@ -1498,7 +1508,7 @@ class NsLcmOpTopic(BaseTopic):
                         ):
                             vdu_if_names.add(iface.get("name"))
 
-                    for in_iface in get_iterable(in_vdu["interface"]):
+                    for in_iface in get_iterable(in_vdu.get("interface")):
                         if in_iface["name"] in vdu_if_names:
                             break
                         else:
@@ -2233,39 +2243,39 @@ class NsLcmOpTopic(BaseTopic):
                 nsd = self.db.get_one("nsds", {"_id": nsr["nsd-id"]})
                 ns_request = nsr["instantiate_params"]
                 vnfr = self.db.get_one("vnfrs", {"_id": indata["changeVnfPackageData"]["vnfInstanceId"]})
-                latest_vnfd_revision = vnfd["_admin"].get("revision")
-                vnfr_vnfd_revision = vnfr.get("revision")
-                old_vnfd_id = vnfd_id + ":" + str(vnfr_vnfd_revision)
-                old_db_vnfd = self.db.get_one("vnfds_revisions", {"_id": old_vnfd_id})
-                old_sw_version = old_db_vnfd["software-version"]
-                new_sw_version = vnfd["software-version"]
-                if new_sw_version != old_sw_version:
-                    vnf_index = vnfr["member-vnf-index-ref"]
-                    self.logger.info("nsr {}".format(nsr))
-                    for vdu in vnfd["vdu"]:
-                        self.nsrtopic._add_flavor_to_nsr(vdu, vnfd, nsr)
-                        sw_image_id = vdu.get("sw-image-desc")
-                        if sw_image_id:
-                            image_data = self.nsrtopic._get_image_data_from_vnfd(vnfd, sw_image_id)
-                            self.nsrtopic._add_image_to_nsr(nsr, image_data)
-                        for alt_image in vdu.get("alternative-sw-image-desc", ()):
-                            image_data = self.nsrtopic._get_image_data_from_vnfd(vnfd, alt_image)
-                            self.nsrtopic._add_image_to_nsr(nsr, image_data)
-                    nsr_update["image"] = nsr["image"]
-                    nsr_update["flavor"] = nsr["flavor"]
-                    self.db.set_one("nsrs", {"_id": nsr["_id"]}, nsr_update)
-                    ns_k8s_namespace = self.nsrtopic._get_ns_k8s_namespace(nsd, ns_request, session)
-                    vnfr_descriptor = self.nsrtopic._create_vnfr_descriptor_from_vnfd(
-                        nsd,
-                        vnfd,
-                        vnfd_id,
-                        vnf_index,
-                        nsr,
-                        ns_request,
-                        ns_k8s_namespace,
-                    )
-                    indata["newVdur"] = vnfr_descriptor["vdur"]
-                    # self.logger.info("vnfr_descriptor {}".format(vnfr_descriptor))
+                latest_vnfd_revision = vnfd["_admin"].get("revision", 1)
+                vnfr_vnfd_revision = vnfr.get("revision", 1)
+                if latest_vnfd_revision != vnfr_vnfd_revision:
+                    old_vnfd_id = vnfd_id + ":" + str(vnfr_vnfd_revision)
+                    old_db_vnfd = self.db.get_one("vnfds_revisions", {"_id": old_vnfd_id})
+                    old_sw_version = old_db_vnfd.get("software-version", "1.0")
+                    new_sw_version = vnfd.get("software-version", "1.0")
+                    if new_sw_version != old_sw_version:
+                        vnf_index = vnfr["member-vnf-index-ref"]
+                        self.logger.info("nsr {}".format(nsr))
+                        for vdu in vnfd["vdu"]:
+                            self.nsrtopic._add_flavor_to_nsr(vdu, vnfd, nsr)
+                            sw_image_id = vdu.get("sw-image-desc")
+                            if sw_image_id:
+                                image_data = self.nsrtopic._get_image_data_from_vnfd(vnfd, sw_image_id)
+                                self.nsrtopic._add_image_to_nsr(nsr, image_data)
+                            for alt_image in vdu.get("alternative-sw-image-desc", ()):
+                                image_data = self.nsrtopic._get_image_data_from_vnfd(vnfd, alt_image)
+                                self.nsrtopic._add_image_to_nsr(nsr, image_data)
+                        nsr_update["image"] = nsr["image"]
+                        nsr_update["flavor"] = nsr["flavor"]
+                        self.db.set_one("nsrs", {"_id": nsr["_id"]}, nsr_update)
+                        ns_k8s_namespace = self.nsrtopic._get_ns_k8s_namespace(nsd, ns_request, session)
+                        vnfr_descriptor = self.nsrtopic._create_vnfr_descriptor_from_vnfd(
+                            nsd,
+                            vnfd,
+                            vnfd_id,
+                            vnf_index,
+                            nsr,
+                            ns_request,
+                            ns_k8s_namespace,
+                        )
+                        indata["newVdur"] = vnfr_descriptor["vdur"]
             nslcmop_desc = self._create_nslcmop(nsInstanceId, operation, indata)
             _id = nslcmop_desc["_id"]
             self.format_on_new(