nsr_id, vnf_member_index
)
await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index)
+ await self.healing_service.delete_healing_alarms(nsr_id, vnf_member_index)
await self.autoscaling_service.configure_scaling_groups(
nsr_id, vnf_member_index
)
await self.alarming_service.configure_vnf_alarms(nsr_id, vnf_member_index)
+ await self.healing_service.configure_healing_alarms(
+ nsr_id, vnf_member_index
+ )
else:
log.info(
"Network service is not in COMPLETED or PARTIALLY_COMPLETED state. "
##
import logging
import datetime
+import functools
+import operator
from osm_policy_module.common.common_db_client import CommonDbClient
from osm_policy_module.common.lcm_client import LcmClient
self.lcm_client = LcmClient(config)
log.info("Constructor created for HealingService")
- async def configure_healing_alarms(self, nsr_id: str):
+ async def configure_healing_alarms(self, nsr_id: str, vnf_member_index=None):
"""
Configuring the Healing alarms
:param nsr_id: Network service record id
+ :param vnf_member_index: Member VNF Index of VNF
"""
log.info("Configuring Healing alarm for NS %s", nsr_id)
alarms_created = []
database.db.connect()
try:
with database.db.atomic():
- vnfrs = self.db_client.get_vnfrs(nsr_id)
+ if vnf_member_index is None:
+ vnfrs = self.db_client.get_vnfrs(nsr_id)
+ else:
+ vnfrs = []
+ vnfr = self.db_client.get_vnfr(nsr_id, vnf_member_index)
+ vnfrs.append(vnfr)
for vnfr in vnfrs:
vnfd = self.db_client.get_vnfd(vnfr["vnfd-id"])
df = vnfd.get("df", [{}])[0]
finally:
database.db.close()
- async def delete_healing_alarms(self, nsr_id):
+ async def delete_healing_alarms(self, nsr_id, vnf_member_index=None):
"""
Deleting the healing alarms
:param nsr_id: Network service record id
+ :param vnf_member_index: Member VNF Index of VNF
"""
log.info("Deleting healing vnf alarms for network service %s", nsr_id)
database.db.connect()
try:
with database.db.atomic():
- for alarm in HealingActionRepository.list(
- HealingAction.nsr_id == nsr_id
- ):
+ if vnf_member_index is None:
+ heal_conditions = HealingAction.nsr_id == nsr_id
+ else:
+ query_list = [
+ HealingAction.nsr_id == nsr_id,
+ HealingAction.vnf_member_index == vnf_member_index,
+ ]
+ heal_conditions = functools.reduce(operator.and_, query_list)
+ for alarm in HealingActionRepository.list(heal_conditions):
try:
await self.mon_client.delete_alarm(
alarm.nsr_id,
@mock.patch("osm_policy_module.alarming.service.LcmClient")
@mock.patch("osm_policy_module.autoscaling.service.MonClient")
@mock.patch("osm_policy_module.autoscaling.service.LcmClient")
+ @mock.patch("osm_policy_module.healing.service.MonClient")
+ @mock.patch("osm_policy_module.healing.service.LcmClient")
+ @mock.patch.object(HealingService, "configure_healing_alarms")
@mock.patch.object(AutoscalingService, "configure_scaling_groups")
@mock.patch.object(AlarmingService, "configure_vnf_alarms")
+ @mock.patch.object(HealingService, "delete_healing_alarms")
@mock.patch.object(AutoscalingService, "delete_scaling_groups")
@mock.patch.object(AlarmingService, "delete_vnf_alarms")
def test_handle_policy_update(
self,
delete_vnf_alarms,
delete_scaling_groups,
+ delete_healing_alarms,
configure_vnf_alarms,
configure_scaling_groups,
+ configure_healing_alarms,
+ healing_lcm_client,
+ healing_mon_client,
autoscaling_lcm_client,
autoscaling_mon_client,
alarming_lcm_client,
async def mock_delete_vnf_alarms(nsr_id, vnf_member_index):
pass
+ async def mock_delete_healing_alarms(nsr_id, vnf_member_index):
+ pass
+
async def mock_configure_scaling_groups(nsr_id, vnf_member_index):
pass
async def mock_configure_vnf_alarms(nsr_id, vnf_member_index):
pass
+ async def mock_configure_healing_alarms(nsr_id, vnf_member_index):
+ pass
+
config = Config()
agent = PolicyModuleAgent(config)
assert autoscaling_lcm_client.called
assert autoscaling_mon_client.called
assert alarming_lcm_client.called
assert alarming_mon_client.called
+ assert healing_lcm_client.called
+ assert healing_mon_client.called
content = {
"nsr_id": "test_nsr_id",
"vnf_member_index": "1",
}
configure_scaling_groups.side_effect = mock_configure_scaling_groups
configure_vnf_alarms.side_effect = mock_configure_vnf_alarms
+ configure_healing_alarms.side_effect = mock_configure_healing_alarms
delete_scaling_groups.side_effect = mock_delete_scaling_groups
delete_vnf_alarms.side_effect = mock_delete_vnf_alarms
+ delete_healing_alarms.side_effect = mock_delete_healing_alarms
self.loop.run_until_complete(agent._handle_policy_update(content))
configure_scaling_groups.assert_called_with("test_nsr_id", "1")