From f78e7625ab1b1e57b6e6cac8e63d70970494a880 Mon Sep 17 00:00:00 2001 From: gifrerenom <lluis.gifre@cttc.es> Date: Tue, 12 Mar 2024 09:44:09 +0000 Subject: [PATCH] Device component: - Enhanced management of setting DEVICE_EMULATED_ONLY - Removed unused imports --- src/device/Config.py | 6 ++++++ src/device/service/DeviceService.py | 5 +---- src/device/service/DeviceServiceServicerImpl.py | 1 - src/device/service/drivers/__init__.py | 5 +---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/device/Config.py b/src/device/Config.py index 1549d9811..2e831a405 100644 --- a/src/device/Config.py +++ b/src/device/Config.py @@ -12,3 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. + +import os + +TRUE_VALUES = {'T', 'TRUE', 'YES', '1'} +DEVICE_EMULATED_ONLY = os.environ.get('DEVICE_EMULATED_ONLY') +LOAD_ALL_DEVICE_DRIVERS = (DEVICE_EMULATED_ONLY is None) or (DEVICE_EMULATED_ONLY.upper() not in TRUE_VALUES) diff --git a/src/device/service/DeviceService.py b/src/device/service/DeviceService.py index 908d13376..0e1ce79f9 100644 --- a/src/device/service/DeviceService.py +++ b/src/device/service/DeviceService.py @@ -18,15 +18,12 @@ from common.Settings import get_service_port_grpc from common.proto.device_pb2_grpc import add_DeviceServiceServicer_to_server from common.proto.openconfig_device_pb2_grpc import add_OpenConfigServiceServicer_to_server from common.tools.service.GenericGrpcService import GenericGrpcService +from device.Config import LOAD_ALL_DEVICE_DRIVERS from .driver_api.DriverInstanceCache import DriverInstanceCache from .DeviceServiceServicerImpl import DeviceServiceServicerImpl from .monitoring.MonitoringLoops import MonitoringLoops from .OpenConfigServicer import OpenConfigServicer -TRUE_VALUES = {'T', 'TRUE', 'YES', '1'} -DEVICE_EMULATED_ONLY = os.environ.get('DEVICE_EMULATED_ONLY') -LOAD_ALL_DEVICE_DRIVERS = (DEVICE_EMULATED_ONLY is None) or (DEVICE_EMULATED_ONLY.upper() not in TRUE_VALUES) - # Custom gRPC settings # Multiple clients might keep connections alive waiting for RPC methods to be executed. # Requests needs to be serialized to ensure correct device configurations diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index 76fb65454..5e5d7540c 100644 --- a/src/device/service/DeviceServiceServicerImpl.py +++ b/src/device/service/DeviceServiceServicerImpl.py @@ -31,7 +31,6 @@ from context.client.ContextClient import ContextClient from .driver_api._Driver import _Driver from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver from .monitoring.MonitoringLoops import MonitoringLoops -from .drivers.oc_driver.OCDriver import OCDriver 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, diff --git a/src/device/service/drivers/__init__.py b/src/device/service/drivers/__init__.py index 1e8cff605..beb3db38e 100644 --- a/src/device/service/drivers/__init__.py +++ b/src/device/service/drivers/__init__.py @@ -15,12 +15,9 @@ import os from common.DeviceTypes import DeviceTypeEnum from common.proto.context_pb2 import DeviceDriverEnum +from device.Config import LOAD_ALL_DEVICE_DRIVERS from ..driver_api.FilterFields import FilterFieldEnum -TRUE_VALUES = {'T', 'TRUE', 'YES', '1'} -DEVICE_EMULATED_ONLY = os.environ.get('DEVICE_EMULATED_ONLY') -LOAD_ALL_DEVICE_DRIVERS = (DEVICE_EMULATED_ONLY is None) or (DEVICE_EMULATED_ONLY.upper() not in TRUE_VALUES) - DRIVERS = [] from .emulated.EmulatedDriver import EmulatedDriver # pylint: disable=wrong-import-position -- GitLab