- 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',
- 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',
- threshold=20.0,
- vdu_name='cirros_ns-2-cirros_vnfd-VM-1',
- vnf_member_index='2')
+ agent = PolicyModuleAgent(config)
+ self.loop.run_until_complete(
+ agent.alarming_service.configure_vnf_alarms("test_nsr_id")
+ )
+ create_alarm.assert_any_call(
+ metric_name="average_memory_utilization",
+ ns_id="test_nsr_id",
+ vdu_name="cirros_ns-1-cirros_vnfd-VM-1",
+ vnf_member_index="1",
+ threshold=20.0,
+ operation="LT",
+ action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}",
+ )
+ 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",
+ threshold=20.0,
+ operation="LT",
+ action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}",
+ )
+
+ @patch.object(DbMongo, "db_connect", Mock())
+ @patch.object(KafkaProducer, "__init__")
+ @patch.object(MonClient, "create_alarm")
+ @patch.object(CommonDbClient, "get_vnfd")
+ @patch.object(CommonDbClient, "get_nsr")
+ @patch.object(CommonDbClient, "get_vnfr")
+ def test_configure_healing_alarms(
+ self, get_vnfr, get_nsr, get_vnfd, create_alarm, kafka_producer_init
+ ):
+ def _test_configure_scaling_groups_get_vnfr(*args, **kwargs):
+ if "1" in args[1]:
+ return vnfr_record_mocks[0]
+ if "2" in args[1]:
+ return vnfr_record_mocks[1]
+
+ async def _test_configure_healing_alarms_create_alarm(*args, **kwargs):
+ return uuid.uuid4()
+
+ kafka_producer_init.return_value = None
+ get_vnfr.side_effect = _test_configure_scaling_groups_get_vnfr
+ get_nsr.return_value = nsr_record_mock
+ get_vnfd.return_value = vnfd_record_mock
+ create_alarm.side_effect = _test_configure_healing_alarms_create_alarm
+ config = Config()
+ agent = PolicyModuleAgent(config)
+ self.loop.run_until_complete(
+ agent.healing_service.configure_healing_alarms("test_nsr_id")
+ )
+ create_alarm.assert_any_call(
+ metric_name="vm_status",
+ ns_id="test_nsr_id",
+ vdu_name="cirros_ns-1-cirros_vnfd-VM-1",
+ vnf_member_index="1",
+ threshold=1,
+ operation="LT",
+ statistic="AVERAGE",
+ )
+ create_alarm.assert_any_call(
+ metric_name="vm_status",
+ ns_id="test_nsr_id",
+ vdu_name="cirros_ns-2-cirros_vnfd-VM-1",
+ vnf_member_index="2",
+ threshold=1,
+ operation="LT",
+ statistic="AVERAGE",
+ )