Adds deletion of orphaned alarms after an scalein operation 81/6981/1 v5.0 v5.0.0 v5.0.1 v5.0.2 v5.0.3 v5.0.4 v5.0.5
authorBenjamin Diaz <bdiaz@whitestack.com>
Tue, 27 Nov 2018 20:40:30 +0000 (17:40 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Tue, 27 Nov 2018 20:40:30 +0000 (17:40 -0300)
Change-Id: Ic461abb88d5514367c284ae79b4ed8914bc0281e
Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
osm_policy_module/common/common_db_client.py
osm_policy_module/core/agent.py
osm_policy_module/core/exceptions.py

index 41ce975..2be3693 100644 (file)
@@ -24,6 +24,7 @@
 from osm_common import dbmongo
 
 from osm_policy_module.core.config import Config
+from osm_policy_module.core.exceptions import VdurNotFound
 
 
 class CommonDbClient:
@@ -56,3 +57,11 @@ class CommonDbClient:
         nslcmop = self.common_db.get_one("nslcmops",
                                          {"_id": nslcmop_id})
         return nslcmop
+
+    def get_vdur(self, nsr_id, member_index, vdur_name):
+        vnfr = self.get_vnfr(nsr_id, member_index)
+        for vdur in vnfr['vdur']:
+            if vdur['name'] == vdur_name:
+                return vdur
+        raise VdurNotFound('vdur not found for nsr-id %s, member_index %s and vdur_name %s', nsr_id, member_index,
+                           vdur_name)
index 3e64652..f7cd679 100644 (file)
@@ -36,6 +36,7 @@ from osm_policy_module.common.mon_client import MonClient
 from osm_policy_module.core import database
 from osm_policy_module.core.config import Config
 from osm_policy_module.core.database import ScalingGroup, ScalingAlarm, ScalingPolicy, ScalingCriteria, DatabaseManager
+from osm_policy_module.core.exceptions import VdurNotFound
 from osm_policy_module.utils.vnfd import VnfdUtils
 
 log = logging.getLogger(__name__)
@@ -144,6 +145,8 @@ class PolicyModuleAgent:
             nsr_id = nslcmop['nsInstanceId']
             log.info("Configuring scaling groups for network service with nsr_id: %s", nsr_id)
             await self._configure_scaling_groups(nsr_id)
+            log.info("Checking for orphaned alarms to be deleted for network service with nsr_id: %s", nsr_id)
+            await self._delete_orphaned_alarms(nsr_id)
         else:
             log.info(
                 "Network service is not in COMPLETED or PARTIALLY_COMPLETED state. "
@@ -363,3 +366,29 @@ class PolicyModuleAgent:
                 log.exception("Error deleting scaling groups and alarms:")
                 tx.rollback()
                 raise e
+
+    async def _delete_orphaned_alarms(self, nsr_id):
+        with database.db.atomic() as tx:
+            try:
+                for scaling_group in ScalingGroup.select().where(ScalingGroup.nsr_id == nsr_id):
+                    for scaling_policy in scaling_group.scaling_policies:
+                        for scaling_criteria in scaling_policy.scaling_criterias:
+                            for alarm in scaling_criteria.scaling_alarms:
+                                try:
+                                    self.db_client.get_vdur(nsr_id, alarm.vnf_member_index, alarm.vdu_name)
+                                except VdurNotFound:
+                                    log.info("Deleting orphaned alarm %s", alarm.alarm_uuid)
+                                    try:
+                                        await self.mon_client.delete_alarm(
+                                            alarm.scaling_criteria.scaling_policy.scaling_group.nsr_id,
+                                            alarm.vnf_member_index,
+                                            alarm.vdu_name,
+                                            alarm.alarm_uuid)
+                                    except ValueError:
+                                        log.exception("Error deleting alarm in MON %s", alarm.alarm_uuid)
+                                    alarm.delete_instance()
+
+            except Exception as e:
+                log.exception("Error deleting orphaned alarms:")
+                tx.rollback()
+                raise e
index 906bb03..f88cc96 100644 (file)
@@ -25,3 +25,7 @@
 
 class ManagementVduNotFound(Exception):
     pass
+
+
+class VdurNotFound(Exception):
+    pass