From bdfc55e8010b03271fba48cefb70f551285324e8 Mon Sep 17 00:00:00 2001 From: EstherLerouzic Date: Fri, 13 Sep 2019 17:30:46 +0100 Subject: [PATCH] Add a ServiceError(Exception) for malformed user requests For example requested bandwidth should be >0 Signed-off-by: EstherLerouzic --- examples/path_requests_run.py | 6 +++++- gnpy/core/exceptions.py | 4 ++++ gnpy/core/request.py | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/path_requests_run.py b/examples/path_requests_run.py index 8d5c401e..6d68712a 100755 --- a/examples/path_requests_run.py +++ b/examples/path_requests_run.py @@ -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 diff --git a/gnpy/core/exceptions.py b/gnpy/core/exceptions.py index 503d9df9..655dc196 100644 --- a/gnpy/core/exceptions.py +++ b/gnpy/core/exceptions.py @@ -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''' + diff --git a/gnpy/core/request.py b/gnpy/core/request.py index b9965477..15bdf7eb 100644 --- a/gnpy/core/request.py +++ b/gnpy/core/request.py @@ -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,