Add a ServiceError(Exception) for malformed user requests

For example requested bandwidth should be >0

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
This commit is contained in:
EstherLerouzic
2019-09-13 17:30:46 +01:00
parent 57f264bedb
commit bdfc55e801
3 changed files with 13 additions and 2 deletions

View File

@@ -30,7 +30,8 @@ from gnpy.core.request import (Path_request, Result_element, compute_constrained
requests_aggregation, propagate_and_optimize_mode,
BLOCKING_NOPATH, BLOCKING_NOMODE, BLOCKING_NOSPECTRUM,
find_reversed_path)
from gnpy.core.exceptions import ConfigurationError, EquipmentConfigError, NetworkTopologyError
from gnpy.core.exceptions import (ConfigurationError, EquipmentConfigError, NetworkTopologyError,
ServiceError)
import gnpy.core.ansi_escapes as ansi_escapes
from gnpy.core.spectrum_assignment import (build_oms_list, reversed_oms, spectrum_selection,
pth_assign_spectrum)
@@ -363,6 +364,9 @@ if __name__ == '__main__':
except ConfigurationError as e:
print(f'{ansi_escapes.red}Configuration error:{ansi_escapes.reset} {e}')
exit(1)
except ServiceError as e:
print(f'{ansi_escapes.red}Service error:{ansi_escapes.reset} {e}')
exit(1)
# Build the network once using the default power defined in SI in eqpt config
# TODO power density: db2linp(ower_dbm": 0)/power_dbm": 0 * nb channels as defined by

View File

@@ -17,3 +17,7 @@ class EquipmentConfigError(ConfigurationError):
class NetworkTopologyError(ConfigurationError):
'''Topology of user-provided network is wrong'''
class ServiceError(Exception):
'''Service of user-provided request is wrong'''

View File

@@ -26,6 +26,7 @@ from gnpy.core.elements import Transceiver, Roadm, Edfa, Fused
from gnpy.core.utils import db2lin, lin2db
from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power
from gnpy.core.spectrum_assignment import build_oms_list, reversed_oms
from gnpy.core.exceptions import ServiceError
from copy import copy, deepcopy
from csv import writer
from math import ceil
@@ -157,7 +158,9 @@ class Result_element(Element):
}
pro_list.append(temp)
index += 1
if isinstance(element, Transceiver) :
else:
raise ServiceError('request {self.path_id} should have positive path bandwidth value.')
if isinstance(element, Transceiver):
temp = {
'path-route-object': {
'index': index,