From: Gianpietro Lavado Date: Fri, 6 Dec 2019 15:46:23 +0000 (+0000) Subject: Fix metric name at VNF Alarms feature X-Git-Tag: v7.0.0rc1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=419349473f3a0e0c310886dc2a9c3075274f53ab;p=osm%2FPOL.git Fix metric name at VNF Alarms feature Change-Id: Ia996a26befe7bc871b2801c4758fe1deaf2eb987 Signed-off-by: Gianpietro Lavado --- diff --git a/osm_policy_module/alarming/service.py b/osm_policy_module/alarming/service.py index 9be0467..e45787e 100644 --- a/osm_policy_module/alarming/service.py +++ b/osm_policy_module/alarming/service.py @@ -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']) diff --git a/osm_policy_module/tests/integration/test_policy_agent.py b/osm_policy_module/tests/integration/test_policy_agent.py index 65a657d..1470b25 100644 --- a/osm_policy_module/tests/integration/test_policy_agent.py +++ b/osm_policy_module/tests/integration/test_policy_agent.py @@ -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__':