Skip to content
Snippets Groups Projects
Commit a1fb0827 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'fix/2.0.0-device-error-messages' into 'release/2.0.1'

Multiple fixes

See merge request !56
parents 30b0185c 86d6cfab
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!56Multiple fixes
Showing
with 75 additions and 57 deletions
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
......@@ -22,13 +22,14 @@ from common.proto.device_pb2_grpc import DeviceServiceServicer
from common.tools.context_queries.Device import get_device
from common.tools.mutex_queues.MutexQueues import MutexQueues
from context.client.ContextClient import ContextClient
from device.service.Errors import ERROR_MISSING_DRIVER, ERROR_MISSING_KPI
from .driver_api._Driver import _Driver
from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver
from .monitoring.MonitoringLoops import MonitoringLoops
from .ErrorMessages import ERROR_MISSING_DRIVER, ERROR_MISSING_KPI
from .Tools import (
check_connect_rules, check_no_endpoints, compute_rules_to_add_delete, configure_rules, deconfigure_rules,
populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints, populate_initial_config_rules, subscribe_kpi, unsubscribe_kpi, update_endpoints)
populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints, populate_initial_config_rules,
subscribe_kpi, unsubscribe_kpi, update_endpoints)
LOGGER = logging.getLogger(__name__)
......@@ -110,7 +111,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
driver : _Driver = self.driver_instance_cache.get(device_uuid)
if driver is None:
msg = ERROR_MISSING_DRIVER.format(str(device_uuid))
msg = ERROR_MISSING_DRIVER.format(device_uuid=str(device_uuid))
raise OperationFailedException('ConfigureDevice', extra_details=msg)
if DeviceDriverEnum.DEVICEDRIVER_P4 in device.device_drivers:
......@@ -164,7 +165,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
try:
driver : _Driver = self.driver_instance_cache.get(device_uuid)
if driver is None:
msg = ERROR_MISSING_DRIVER.format(str(device_uuid))
msg = ERROR_MISSING_DRIVER.format(device_uuid=str(device_uuid))
raise OperationFailedException('GetInitialConfig', extra_details=msg)
device_config = DeviceConfig()
......@@ -190,7 +191,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
kpi_uuid = request.kpi_id.kpi_id.uuid
kpi_details = self.monitoring_loops.get_kpi_by_uuid(kpi_uuid)
if kpi_details is None:
msg = ERROR_MISSING_KPI.format(str(kpi_uuid))
msg = ERROR_MISSING_KPI.format(kpi_uuid=str(kpi_uuid))
raise OperationFailedException('MonitorDeviceKpi', extra_details=msg)
device_uuid = kpi_details[0]
......@@ -198,7 +199,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
try:
driver : _Driver = self.driver_instance_cache.get(device_uuid)
if driver is None:
msg = ERROR_MISSING_DRIVER.format(str(device_uuid))
msg = ERROR_MISSING_DRIVER.format(device_uuid=str(device_uuid))
raise OperationFailedException('MonitorDeviceKpi', extra_details=msg)
errors = manage_kpi_method(request, driver, self.monitoring_loops)
......
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
_DEVICE_ID = 'DeviceId({device_uuid:s})'
_ENDPOINT_ID = 'EndpointId({endpoint_uuid:s})'
_ENDPOINT_DATA = 'EndpointId({endpoint_data:s})'
_KPI = 'Kpi({kpi_uuid:s})'
_DEVICE_ENDPOINT_ID = _DEVICE_ID + '/' + _ENDPOINT_ID
_RESOURCE_KEY = 'Resource(key={resource_key:s})'
_RESOURCE_KEY_VALUE = 'Resource(key={resource_key:s}, value={resource_value:s})'
_SUBSCRIPTION = 'Subscription(key={subscr_key:s}, duration={subscr_duration:s}, interval={subscr_interval:s})'
_SAMPLE_TYPE = 'SampleType({sample_type_id:s}/{sample_type_name:s})'
_ERROR = 'Error({error:s})'
ERROR_MISSING_DRIVER = _DEVICE_ID + ' has not been added to this Device instance'
ERROR_MISSING_KPI = _KPI + ' not found'
ERROR_BAD_ENDPOINT = _DEVICE_ID + ': GetConfig retrieved malformed ' + _ENDPOINT_DATA
ERROR_GET = _DEVICE_ID + ': Unable to Get ' + _RESOURCE_KEY + '; ' + _ERROR
ERROR_GET_INIT = _DEVICE_ID + ': Unable to Get Initial ' + _RESOURCE_KEY + '; ' + _ERROR
ERROR_DELETE = _DEVICE_ID + ': Unable to Delete ' + _RESOURCE_KEY_VALUE + '; ' + _ERROR
ERROR_SET = _DEVICE_ID + ': Unable to Set ' + _RESOURCE_KEY_VALUE + '; ' + _ERROR
ERROR_SAMPLETYPE = _DEVICE_ENDPOINT_ID + ': ' + _SAMPLE_TYPE + ' not supported'
ERROR_SUBSCRIBE = _DEVICE_ID + ': Unable to Subscribe ' + _SUBSCRIPTION + '; ' + _ERROR
ERROR_UNSUBSCRIBE = _DEVICE_ID + ': Unable to Unsubscribe ' + _SUBSCRIPTION + '; ' + _ERROR
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ERROR_MISSING_DRIVER = 'Device({:s}) has not been added to this Device instance'
ERROR_MISSING_KPI = 'Kpi({:s}) not found'
ERROR_BAD_ENDPOINT = 'Device({:s}): GetConfig retrieved malformed Endpoint({:s})'
ERROR_GET = 'Device({:s}): Unable to Get resource(key={:s}); error({:s})'
ERROR_GET_INIT = 'Device({:s}): Unable to Get Initial resource(key={:s}); error({:s})'
ERROR_DELETE = 'Device({:s}): Unable to Delete resource(key={:s}, value={:s}); error({:s})'
ERROR_SET = 'Device({:s}): Unable to Set resource(key={:s}, value={:s}); error({:s})'
ERROR_SAMPLETYPE = 'Device({:s})/EndPoint({:s}): SampleType({:s}/{:s}) not supported'
ERROR_SUBSCRIBE = 'Device({:s}): Unable to Subscribe subscription(key={:s}, duration={:s}, interval={:s}); '+\
'error({:s})'
ERROR_UNSUBSCRIBE = 'Device({:s}): Unable to Unsubscribe subscription(key={:s}, duration={:s}, interval={:s}); '+\
'error({:s})'
......@@ -23,9 +23,10 @@ from common.tools.grpc.ConfigRules import update_config_rule_custom
from common.tools.grpc.Tools import grpc_message_to_json
from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS
from .monitoring.MonitoringLoops import MonitoringLoops
from .Errors import (
from .ErrorMessages import (
ERROR_BAD_ENDPOINT, ERROR_DELETE, ERROR_GET, ERROR_GET_INIT, ERROR_MISSING_KPI, ERROR_SAMPLETYPE, ERROR_SET,
ERROR_SUBSCRIBE, ERROR_UNSUBSCRIBE)
ERROR_SUBSCRIBE, ERROR_UNSUBSCRIBE
)
LOGGER = logging.getLogger(__name__)
......@@ -85,12 +86,13 @@ def populate_endpoints(device : Device, driver : _Driver, monitoring_loops : Mon
errors : List[str] = list()
for endpoint in results_getconfig:
if len(endpoint) != 2:
errors.append(ERROR_BAD_ENDPOINT.format(device_uuid, str(endpoint)))
errors.append(ERROR_BAD_ENDPOINT.format(device_uuid=device_uuid, endpoint_data=str(endpoint)))
continue
resource_key, resource_value = endpoint
if isinstance(resource_value, Exception):
errors.append(ERROR_GET.format(device_uuid, str(resource_key), str(resource_value)))
errors.append(ERROR_GET.format(
device_uuid=device_uuid, resource_key=str(resource_key), error=str(resource_value)))
continue
if resource_value is None:
continue
......@@ -134,7 +136,9 @@ def _raw_config_rules_to_grpc(
for resource_key, resource_value in raw_config_rules:
if isinstance(resource_value, Exception):
errors.append(error_template.format(device_uuid, str(resource_key), str(resource_value)))
errors.append(error_template.format(
device_uuid=device_uuid, resource_key=str(resource_key), resource_value=str(resource_value),
error=str(resource_value)))
continue
if resource_value is None: continue
......@@ -223,7 +227,8 @@ def subscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_loo
if resource_key is None:
kpi_sample_type_name = KpiSampleType.Name(kpi_sample_type).upper().replace('KPISAMPLETYPE_', '')
MSG = ERROR_SAMPLETYPE.format(
str(device_uuid), str(endpoint_uuid), str(kpi_sample_type), str(kpi_sample_type_name)
device_uuid=str(device_uuid), endpoint_uuid=str(endpoint_uuid), sample_type_id=str(kpi_sample_type),
sample_type_name=str(kpi_sample_type_name)
)
LOGGER.warning('{:s} Supported Device-Endpoint-KpiSampleType items: {:s}'.format(
MSG, str(monitoring_loops.get_all_resource_keys())))
......@@ -239,7 +244,8 @@ def subscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_loo
for (resource_key, duration, interval), result in zip(resources_to_subscribe, results_subscribestate):
if isinstance(result, Exception):
errors.append(ERROR_SUBSCRIBE.format(
str(device_uuid), str(resource_key), str(duration), str(interval), str(result)
device_uuid=str(device_uuid), subscr_key=str(resource_key), subscr_duration=str(duration),
subscr_interval=str(interval), error=str(result)
))
continue
......@@ -253,7 +259,7 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l
kpi_details = monitoring_loops.get_kpi_by_uuid(kpi_uuid)
if kpi_details is None:
return [ERROR_MISSING_KPI.format(str(kpi_uuid))]
return [ERROR_MISSING_KPI.format(kpi_uuid=str(kpi_uuid))]
device_uuid, resource_key, sampling_duration, sampling_interval = kpi_details
......@@ -264,7 +270,9 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l
for (resource_key, duration, interval), result in zip(resources_to_unsubscribe, results_unsubscribestate):
if isinstance(result, Exception):
errors.append(ERROR_UNSUBSCRIBE.format(
device_uuid, str(resource_key), str(duration), str(interval), str(result)))
device_uuid=str(device_uuid), subscr_key=str(resource_key), subscr_duration=str(duration),
subscr_interval=str(interval), error=str(result)
))
continue
monitoring_loops.remove_kpi(kpi_uuid)
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
/*
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment