Fix metric name at VNF Alarms feature 43/8343/3 sol006 v7.0.0 v7.0.0rc1 v7.0.1 v7.0.1rc1 v7.0.1rc2 v7.0.1rc3
authorGianpietro Lavado <glavado@whitestack.com>
Fri, 6 Dec 2019 15:46:23 +0000 (15:46 +0000)
committerGianpietro Lavado <glavado@whitestack.com>
Fri, 6 Dec 2019 23:20:11 +0000 (23:20 +0000)
Change-Id: Ia996a26befe7bc871b2801c4758fe1deaf2eb987
Signed-off-by: Gianpietro Lavado <glavado@whitestack.com>
osm_policy_module/alarming/service.py
osm_policy_module/tests/integration/test_policy_agent.py

index 9be0467..e45787e 100644 (file)
@@ -86,8 +86,9 @@ class AlarmingService:
                                         lambda param: param['id'] == alarm_descriptor['vnf-monitoring-param-ref'],
                                         vnfd['monitoring-param'])
                                 )
+                                metric_name = self._get_metric_name(vnf_monitoring_param, vdur, vnfd)
                                 alarm_uuid = await self.mon_client.create_alarm(
-                                    metric_name=alarm_descriptor['vnf-monitoring-param-ref'],
+                                    metric_name=metric_name,
                                     ns_id=nsr_id,
                                     vdu_name=vdur['name'],
                                     vnf_member_index=vnfr['member-vnf-index-ref'],
@@ -191,3 +192,21 @@ class AlarmingService:
             log.debug("There is no alarming action configured for alarm %s.", alarm_uuid)
         finally:
             database.db.close()
+
+    def _get_metric_name(self, vnf_monitoring_param: dict, vdur: dict, vnfd: dict):
+        vdu = next(
+            filter(lambda vdu: vdu['id'] == vdur['vdu-id-ref'], vnfd['vdu'])
+        )
+        if 'vdu-monitoring-param' in vnf_monitoring_param:
+            vdu_monitoring_param = next(filter(
+                lambda param: param['id'] == vnf_monitoring_param['vdu-monitoring-param'][
+                    'vdu-monitoring-param-ref'], vdu['monitoring-param']))
+            nfvi_metric = vdu_monitoring_param['nfvi-metric']
+            return nfvi_metric
+        if 'vdu-metric' in vnf_monitoring_param:
+            vnf_metric_name = vnf_monitoring_param['vdu-metric']['vdu-metric-name-ref']
+            return vnf_metric_name
+        if 'vnf-metric' in vnf_monitoring_param:
+            vnf_metric_name = vnf_monitoring_param['vnf-metric']['vnf-metric-name-ref']
+            return vnf_metric_name
+        raise ValueError('No metric name found for vnf_monitoring_param %s' % vnf_monitoring_param['id'])
index 65a657d..1470b25 100644 (file)
@@ -545,20 +545,20 @@ class PolicyModuleAgentTest(unittest.TestCase):
         config = Config()
         agent = PolicyModuleAgent(config, self.loop)
         self.loop.run_until_complete(agent.alarming_service.configure_vnf_alarms("test_nsr_id"))
-        create_alarm.assert_any_call(metric_name='cirros_vnf_memory_util',
+        create_alarm.assert_any_call(metric_name='average_memory_utilization',
                                      ns_id='test_nsr_id',
-                                     operation='LT',
-                                     statistic='AVERAGE',
-                                     threshold=20.0,
                                      vdu_name='cirros_ns-1-cirros_vnfd-VM-1',
-                                     vnf_member_index='1')
-        create_alarm.assert_any_call(metric_name='cirros_vnf_memory_util',
-                                     ns_id='test_nsr_id',
-                                     operation='LT',
-                                     statistic='AVERAGE',
+                                     vnf_member_index='1',
                                      threshold=20.0,
+                                     operation='LT',
+                                     statistic='AVERAGE')
+        create_alarm.assert_any_call(metric_name='average_memory_utilization',
+                                     ns_id='test_nsr_id',
                                      vdu_name='cirros_ns-2-cirros_vnfd-VM-1',
-                                     vnf_member_index='2')
+                                     vnf_member_index='2',
+                                     threshold=20.0,
+                                     operation='LT',
+                                     statistic='AVERAGE')
 
 
 if __name__ == '__main__':