X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Ftests%2Funit%2Fevaluator%2Ftest_evaluator_service.py;h=a72dcaff5e450ae0b7c5601bf29404c61fbcd86f;hb=a2eeb474200b8f9ebcaee6fa68fe52b6e1a5e337;hp=88e3b4d66e86bde7d8bfb040aa543b2680d0a083;hpb=a97bdb3eafa4f3d07d61d32635f7f36f5cc36c58;p=osm%2FMON.git diff --git a/osm_mon/tests/unit/evaluator/test_evaluator_service.py b/osm_mon/tests/unit/evaluator/test_evaluator_service.py index 88e3b4d..a72dcaf 100644 --- a/osm_mon/tests/unit/evaluator/test_evaluator_service.py +++ b/osm_mon/tests/unit/evaluator/test_evaluator_service.py @@ -24,8 +24,8 @@ from unittest import TestCase, mock from osm_mon.core.common_db import CommonDbClient from osm_mon.core.config import Config -from osm_mon.core.database import AlarmRepository from osm_mon.core.message_bus_client import MessageBusClient +from osm_mon.evaluator.backends.prometheus import PrometheusBackend from osm_mon.evaluator.evaluator import AlarmStatus from osm_mon.evaluator.service import EvaluatorService @@ -77,66 +77,93 @@ vnfr_record_mock = { vnfd_record_mock = { "_id": "63f44c41-45ee-456b-b10d-5f08fb1796e0", - "name": "cirros_vdu_scaling_vnf", - "vendor": "OSM", + "id": "cirros_vdu_scaling_vnf", + "_admin": {}, + "product-name": "cirros_vdu_scaling_vnf", + "version": "1.0", "vdu": [ { + "id": "cirros_vnfd-VM", "name": "cirros_vnfd-VM", - "monitoring-param": [ + "int-cpd": [ { - "id": "cirros_vnfd-VM_memory_util", - "nfvi-metric": "average_memory_utilization" + "virtual-network-interface-requirement": [ + { + "name": "vdu-eth0" + } + ], + "id": "vdu-eth0-int" } ], - "vm-flavor": { - "vcpu-count": 1, - "memory-mb": 256, - "storage-gb": 2 - }, - "description": "cirros_vnfd-VM", - "count": 1, - "id": "cirros_vnfd-VM", - "interface": [ + "virtual-compute-desc": "cirros_vnfd-VM-compute", + "virtual-storage-desc": [ + "cirros_vnfd-VM-storage" + ], + "sw-image-desc": "cirros034", + "monitoring-parameter": [ { - "name": "eth0", - "external-connection-point-ref": "eth0", - "type": "EXTERNAL", - "virtual-interface": { - "bandwidth": "0", - "type": "VIRTIO", - "vpci": "0000:00:0a.0" - } + "id": "cirros_vnfd-VM_memory_util", + "name": "cirros_vnfd-VM_memory_util", + "performance-metric": "average_memory_utilization" } - ], - "image": "cirros034" + ] } ], - "monitoring-param": [ + "virtual-compute-desc": [ { - "id": "cirros_vnf_memory_util", - "name": "cirros_vnf_memory_util", - "aggregation-type": "AVERAGE", - "vdu-monitoring-param": { - "vdu-monitoring-param-ref": "cirros_vnfd-VM_memory_util", - "vdu-ref": "cirros_vnfd-VM" + "id": "cirros_vnfd-VM-compute", + "virtual-cpu": { + "num-virtual-cpu": 1 + }, + "virtual-memory": { + "size": 1 } } ], - "description": "Simple VNF example with a cirros and a scaling group descriptor", - "id": "cirros_vdu_scaling_vnf", - "logo": "cirros-64.png", - "version": "1.0", - "connection-point": [ + "virtual-storage-desc": [ { - "name": "eth0", - "type": "VPORT" + "id": "cirros_vnfd-VM-storage", + "size-of-storage": 2 } ], - "mgmt-interface": { - "cp": "eth0" - }, - "short-name": "cirros_vdu_scaling_vnf", - "_admin": {} + "sw-image-desc": [ + { + "id": "cirros034", + "name": "cirros034", + "image": "cirros034" + } + ], + "ext-cpd": [ + { + "int-cpd": { + "vdu-id": "cirros_vnfd-VM", + "cpd": "vdu-eth0-int" + }, + "id": "vnf-cp0-ext" + } + ], + "df": [ + { + "id": "default-df", + "vdu-profile": [ + { + "id": "cirros_vnfd-VM" + } + ], + "instantiation-level": [ + { + "id": "default-instantiation-level", + "vdu-level": [ + { + "vdu-id": "cirros_vnfd-VM" + } + ] + } + ] + } + ], + "description": "Simple VNF example with a cirros and a scaling group descriptor", + "mgmt-cp": "vnf-cp0-ext" } @@ -148,38 +175,38 @@ class EvaluatorTest(TestCase): self.config = Config() @mock.patch.object(EvaluatorService, "_get_metric_value") - @mock.patch('osm_mon.core.database.db') - def test_evaluate_metric(self, db, get_metric_value): + def test_evaluate_metric(self, get_metric_value): mock_alarm = mock.Mock() mock_alarm.operation = 'gt' mock_alarm.threshold = 50.0 + mock_alarm.metric = 'metric_name' get_metric_value.return_value = 100.0 service = EvaluatorService(self.config) service.queue = mock.Mock() - service._evaluate_metric('test_id', 1, 'test_name', 'test_metric_name', mock_alarm) + service._evaluate_metric(mock_alarm) service.queue.put.assert_called_with((mock_alarm, AlarmStatus.ALARM)) service.queue.reset_mock() mock_alarm.operation = 'lt' - service._evaluate_metric('test_id', 1, 'test_name', 'test_metric_name', mock_alarm) + service._evaluate_metric(mock_alarm) service.queue.put.assert_called_with((mock_alarm, AlarmStatus.OK)) service.queue.reset_mock() get_metric_value.return_value = None - service._evaluate_metric('test_id', 1, 'test_name', 'test_metric_name', mock_alarm) + service._evaluate_metric(mock_alarm) service.queue.put.assert_called_with((mock_alarm, AlarmStatus.INSUFFICIENT)) @mock.patch('multiprocessing.Process') @mock.patch.object(EvaluatorService, "_evaluate_metric") @mock.patch.object(CommonDbClient, "get_vnfd") @mock.patch.object(CommonDbClient, "get_vnfr") - @mock.patch.object(AlarmRepository, "list") - @mock.patch('osm_mon.core.database.db') - def test_evaluate(self, db, alarm_list, get_vnfr, get_vnfd, evaluate_metric, proccess): + @mock.patch.object(CommonDbClient, "get_alarms") + def test_evaluate_alarms(self, alarm_list, get_vnfr, get_vnfd, evaluate_metric, process): mock_alarm = mock.Mock() mock_alarm.vdur_name = 'cirros_ns-1-cirros_vnfd-VM-1' mock_alarm.monitoring_param = 'cirros_vnf_memory_util' + mock_alarm.tags = {'name': 'value'} alarm_list.return_value = [mock_alarm] get_vnfr.return_value = vnfr_record_mock get_vnfd.return_value = vnfd_record_mock @@ -187,6 +214,12 @@ class EvaluatorTest(TestCase): evaluator = EvaluatorService(self.config) evaluator.evaluate_alarms() - proccess.assert_called_with(target=evaluate_metric, args=( - '87776f33-b67c-417a-8119-cb08e4098951', '1', 'cirros_ns-1-cirros_vnfd-VM-1', 'average_memory_utilization', - mock_alarm)) + process.assert_called_with(target=evaluate_metric, args=(mock_alarm,)) + + @mock.patch.object(PrometheusBackend, "get_metric_value") + def test_get_metric_value_prometheus(self, get_metric_value): + self.config.set('evaluator', 'backend', 'prometheus') + evaluator = EvaluatorService(self.config) + evaluator._get_metric_value('test', {}) + + get_metric_value.assert_called_with('test', {})