X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_policy_module%2Ftests%2Fintegration%2Ftest_policy_agent.py;h=73db3049c12c5e852e40a23e78da088ef5e7ff66;hb=be42d54170ca40d8d52e2c9fc8d888621585d6cf;hp=2c86b12796a5fee9b2e961e6565762870d7e3ccb;hpb=4584f8e86a492d67d120bfea1195eff1475c0a65;p=osm%2FPOL.git diff --git a/osm_policy_module/tests/integration/test_policy_agent.py b/osm_policy_module/tests/integration/test_policy_agent.py index 2c86b12..73db304 100644 --- a/osm_policy_module/tests/integration/test_policy_agent.py +++ b/osm_policy_module/tests/integration/test_policy_agent.py @@ -45,6 +45,7 @@ from osm_policy_module.core.database import ( ScalingCriteria, VnfAlarm, AlarmAction, + HealingAction, ) log = logging.getLogger() @@ -183,6 +184,7 @@ vnfr_record_mocks = [ "ip-address": "192.168.160.2", } ], + "count-index": 0, "status": "ACTIVE", "vim-id": "63a65636-9fc8-4022-b070-980823e6266a", "name": "cirros_ns-1-cirros_vnfd-VM-1", @@ -218,6 +220,7 @@ vnfr_record_mocks = [ "ip-address": "192.168.160.10", } ], + "count-index": 0, "status": "ACTIVE", "vim-id": "a154b8d3-2b10-421a-a51d-4b391d9bd366", "name": "cirros_ns-2-cirros_vnfd-VM-1", @@ -362,6 +365,21 @@ vnfd_record_mock = { "vdu-configuration-id": "cirros_vnfd-VM-vdu-configuration", } ], + "healing-aspect": [ + { + "id": "cirros_vnfd-VM-autoheal", + "healing-policy": [ + { + "vdu-id": "cirros_vnfd-VM", + "event-name": "heal-alarm", + "recovery-type": "automatic", + "action-on-recovery": "REDEPLOY_ONLY", + "cooldown-time": 180, + "day1": False, + } + ], + } + ], "instantiation-level": [ { "id": "default-instantiation-level", @@ -444,6 +462,7 @@ MODELS = [ ScalingAlarm, VnfAlarm, AlarmAction, + HealingAction, ] @@ -505,6 +524,7 @@ class PolicyModuleAgentTest(unittest.TestCase): threshold=80, vdu_name="cirros_ns-1-cirros_vnfd-VM-1", vnf_member_index="1", + action="scale_out", ) create_alarm.assert_not_called_with( metric_name="average_memory_utilization", @@ -513,6 +533,7 @@ class PolicyModuleAgentTest(unittest.TestCase): threshold=20, vdu_name="cirros_ns-1-cirros_vnfd-VM-1", vnf_member_index="1", + action="scale_out", ) create_alarm.assert_any_call( metric_name="average_memory_utilization", @@ -521,6 +542,7 @@ class PolicyModuleAgentTest(unittest.TestCase): threshold=80, vdu_name="cirros_ns-2-cirros_vnfd-VM-1", vnf_member_index="2", + action="scale_out", ) create_alarm.assert_not_called_with( metric_name="average_memory_utilization", @@ -529,6 +551,7 @@ class PolicyModuleAgentTest(unittest.TestCase): threshold=20, vdu_name="cirros_ns-2-cirros_vnfd-VM-1", vnf_member_index="2", + action="scale_out", ) scaling_record = ScalingGroup.get() self.assertEqual(scaling_record.name, "scale_cirros_vnfd-VM") @@ -569,6 +592,7 @@ class PolicyModuleAgentTest(unittest.TestCase): 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", @@ -577,6 +601,54 @@ class PolicyModuleAgentTest(unittest.TestCase): 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) + 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", )