async def configure_vnf_alarms(self, nsr_id: str):
log.info("Configuring vnf alarms for network service %s", nsr_id)
alarms_created = []
- database.db.connect(reuse_if_open=True)
- with database.db.atomic() as tx:
- try:
+ database.db.connect()
+ try:
+ with database.db.atomic():
vnfrs = self.db_client.get_vnfrs(nsr_id)
for vnfr in vnfrs:
log.debug("Processing vnfr: %s", vnfr)
)
alarms_created.append(alarm)
- except Exception as e:
- log.exception("Error configuring VNF alarms:")
- tx.rollback()
- if len(alarms_created) > 0:
- log.debug("Cleaning alarm resources in MON")
- for alarm in alarms_created:
+ except Exception as e:
+ log.exception("Error configuring VNF alarms:")
+ if len(alarms_created) > 0:
+ log.debug("Cleaning alarm resources in MON")
+ for alarm in alarms_created:
+ try:
await self.mon_client.delete_alarm(alarm.nsr_id,
alarm.vnf_member_index,
alarm.vdu_name,
alarm.alarm_uuid)
- raise e
- database.db.close()
+ except ValueError:
+ log.exception("Error deleting alarm in MON %s", alarm.alarm_uuid)
+ raise e
+ finally:
+ database.db.close()
async def delete_orphaned_alarms(self, nsr_id):
log.info("Deleting orphaned vnf alarms for network service %s", nsr_id)
database.db.connect()
- with database.db.atomic() as tx:
- try:
+ try:
+ with database.db.atomic():
for alarm in VnfAlarmRepository.list(VnfAlarm.nsr_id == nsr_id):
try:
self.db_client.get_vdur(nsr_id, alarm.vnf_member_index, alarm.vdu_name)
except ValueError:
log.exception("Error deleting alarm in MON %s", alarm.alarm_uuid)
alarm.delete_instance()
-
- except Exception as e:
- log.exception("Error deleting orphaned alarms:")
- tx.rollback()
- raise e
- database.db.close()
+ except Exception as e:
+ log.exception("Error deleting orphaned alarms:")
+ raise e
+ finally:
+ database.db.close()
async def delete_vnf_alarms(self, nsr_id):
log.info("Deleting vnf alarms for network service %s", nsr_id)
database.db.connect()
- with database.db.atomic() as tx:
- try:
+ try:
+ with database.db.atomic():
for alarm in VnfAlarmRepository.list(VnfAlarm.nsr_id == nsr_id):
log.debug("Deleting vnf alarm %s", alarm.alarm_uuid)
try:
log.exception("Error deleting alarm in MON %s", alarm.alarm_uuid)
alarm.delete_instance()
- except Exception as e:
- log.exception("Error deleting orphaned alarms:")
- tx.rollback()
- raise e
- database.db.close()
+ except Exception as e:
+ log.exception("Error deleting vnf alarms:")
+ raise e
+ finally:
+ database.db.close()
async def handle_alarm(self, alarm_uuid: str, status: str, payload: dict):
database.db.connect()