Bug 2361: Fix for VM is not getting deleted from openstack after Scale In operation 57/14457/9
authorjegan <jegan.s@tataelxsi.co.in>
Mon, 1 Jul 2024 16:47:53 +0000 (16:47 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Sun, 23 Mar 2025 21:10:14 +0000 (22:10 +0100)
Change-Id: Id4323de23909a233e40c194716d341836ec30edb
Signed-off-by: jegan <jegan.s@tataelxsi.co.in>
osm_lcm/ns.py

index d98472f..4ed36cf 100644 (file)
@@ -1218,6 +1218,43 @@ class NsLcm(LcmBase):
         else:  # timeout_ns_deploy
             raise NgRoException("Timeout waiting ns to deploy")
 
+    def rollback_scaling(self, nsr_id, nslcmop_id):
+        try:
+            db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
+            db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
+            vnf_index = db_nslcmop["operationParams"]["scaleVnfData"][
+                "scaleByStepData"
+            ]["member-vnf-index"]
+            db_vnfr = self.db.get_one(
+                "vnfrs", {"member-vnf-index-ref": vnf_index, "nsr-id-ref": nsr_id}
+            )
+            vim_id = "vim:{}".format(db_vnfr["vim-account-id"])
+            db_vnfr_update = {"vdur": db_vnfr["vdur"]}
+            counter = len(db_vnfr_update["vdur"])
+            updated_db_vnfr = []
+            for index, vdur in enumerate(db_vnfr_update["vdur"]):
+                if vdur["vim_info"][vim_id].get("vim_status") == "ACTIVE":
+                    updated_db_vnfr.append(vdur)
+            db_vnfr_update["vdur"] = updated_db_vnfr
+            self.update_db_2("vnfrs", db_vnfr["_id"], db_vnfr_update)
+            scaling_group = db_nslcmop["operationParams"]["scaleVnfData"][
+                "scaleByStepData"
+            ]["scaling-group-descriptor"]
+            counter -= len(updated_db_vnfr)
+            db_nsr_update = {
+                "_admin.scaling-group": db_nsr["_admin"].get("scaling-group")
+            }
+            if db_nsr["_admin"].get("scaling-group"):
+                for index, group in enumerate(db_nsr_update["_admin.scaling-group"]):
+                    if (
+                        group["name"] == scaling_group
+                        and group["vnf_index"] == vnf_index
+                    ):
+                        group["nb-scale-op"] -= counter
+                self.update_db_2("nsrs", nsr_id, db_nsr_update)
+        except Exception as e:
+            self.logger.info(f"There is an error in updating the database. Error {e}")
+
     async def _terminate_ng_ro(
         self, logging_text, nsr_deployed, nsr_id, nslcmop_id, stage
     ):
@@ -6444,6 +6481,8 @@ class NsLcm(LcmBase):
         old_config_status = ""
         nsi_id = None
         prom_job_name = ""
+        exe = None
+        nb_scale_op_update = False
         try:
             # wait for any previous tasks in process
             step = "Waiting for previous operations to terminate"
@@ -7005,6 +7044,7 @@ class NsLcm(LcmBase):
             db_nsr_update[
                 "_admin.scaling-group.{}.time".format(admin_scale_index)
             ] = time()
+            nb_scale_op_update = True
 
             # SCALE-IN VCA - BEGIN
             if vca_scaling_info:
@@ -7440,9 +7480,14 @@ class NsLcm(LcmBase):
             return
         except (
             ROclient.ROClientException,
+            NgRoException,
+        ) as e:
+            exe = "RO exception"
+            self.logger.error(logging_text + "Exit Exception {}".format(e))
+            exc = e
+        except (
             DbException,
             LcmException,
-            NgRoException,
         ) as e:
             self.logger.error(logging_text + "Exit Exception {}".format(e))
             exc = e
@@ -7538,6 +7583,13 @@ class NsLcm(LcmBase):
                     current_operation_id=None,
                     other_update=db_nsr_update,
                 )
+            if exe:
+                if (
+                    scaling_type == "SCALE_OUT"
+                    and nb_scale_op_update
+                    and exe == "RO exception"
+                ):
+                    self.rollback_scaling(nsr_id, nslcmop_id)
 
             if nslcmop_operation_state:
                 try: