fix: capture warning to show the ROADM uid

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
Change-Id: Ie13bf4c3436a5a0b8ec730698920eee2c7fb81e8
This commit is contained in:
EstherLerouzic
2024-01-26 17:30:12 +01:00
committed by Esther Le Rouzic
parent 0d236fd31e
commit ae858b911a

View File

@@ -27,6 +27,7 @@ from scipy.interpolate import interp1d
from collections import namedtuple
from typing import Union
from logging import getLogger
import warnings
from gnpy.core.utils import lin2db, db2lin, arrange_frequencies, snr_sum, per_label_average, pretty_summary_print, \
watt2dbm, psd2powerdbm, calculate_absolute_min_or_zero
@@ -239,7 +240,11 @@ class Roadm(_Node):
if not params:
params = {}
try:
super().__init__(*args, params=RoadmParams(**params), **kwargs)
with warnings.catch_warnings(record=True) as caught_warnings:
super().__init__(*args, params=RoadmParams(**params), **kwargs)
if caught_warnings:
msg = f'In ROADM {kwargs["uid"]}: {caught_warnings[0].message}'
_logger.warning(msg)
except ParametersError as e:
msg = f'Config error in {kwargs["uid"]}: {e}'
raise ParametersError(msg) from e