From ff543f5405094a06a68d3d076b069b5e69277738 Mon Sep 17 00:00:00 2001 From: Lluis Gifre <lluis.gifre@cttc.es> Date: Tue, 17 May 2022 15:27:51 +0200 Subject: [PATCH] Device component: - Updated default OpenConfig unitary test template config - Added minor code improvements in OpenConfig Driver --- .../service/drivers/openconfig/OpenConfigDriver.py | 13 +++++++------ src/device/tests/Device_OpenConfig_Template.py | 13 +++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/device/service/drivers/openconfig/OpenConfigDriver.py b/src/device/service/drivers/openconfig/OpenConfigDriver.py index 741142363..74b30e013 100644 --- a/src/device/service/drivers/openconfig/OpenConfigDriver.py +++ b/src/device/service/drivers/openconfig/OpenConfigDriver.py @@ -63,9 +63,9 @@ class NetconfSessionHandler: self.__username = settings.get('username') self.__password = settings.get('password') self.__key_filename = settings.get('key_filename') - self.__hostkey_verify = settings.get('hostkey_verify') - self.__look_for_keys = settings.get('look_for_keys') - self.__allow_agent = settings.get('allow_agent') + self.__hostkey_verify = settings.get('hostkey_verify', True) + self.__look_for_keys = settings.get('look_for_keys', True) + self.__allow_agent = settings.get('allow_agent', True) self.__force_running = settings.get('force_running', False) self.__device_params = settings.get('device_params') self.__manager_params = settings.get('manager_params') @@ -183,8 +183,9 @@ def do_sampling(samples_cache : SamplesCache, resource_key : str, out_samples : def edit_config( netconf_handler : NetconfSessionHandler, resources : List[Tuple[str, Any]], delete=False, target='running', - default_operation='merge', test_option=None, error_option=None, format='xml' # pylint: disable=redefined-builtin + default_operation=None, test_option=None, error_option=None, format='xml' # pylint: disable=redefined-builtin ): + if default_operation is None: default_operation = 'delete' if delete else 'merge' str_method = 'DeleteConfig' if delete else 'SetConfig' LOGGER.info('[{:s}] resources = {:s}'.format(str_method, str(resources))) results = [None for _ in resources] @@ -296,14 +297,14 @@ class OpenConfigDriver(_Driver): if self.__netconf_handler.use_candidate: with self.__netconf_handler.locked(target='candidate'): results = edit_config( - self.__netconf_handler, resources, target='candidate', delete=True, default_operation='delete') + self.__netconf_handler, resources, target='candidate', delete=True) try: self.__netconf_handler.commit() except Exception as e: # pylint: disable=broad-except LOGGER.exception('[DeleteConfig] Exception commiting resources: {:s}'.format(str(resources))) results = [e for _ in resources] # if commit fails, set exception in each resource else: - results = edit_config(self.__netconf_handler, resources, delete=True, default_operation='delete') + results = edit_config(self.__netconf_handler, resources, delete=True) return results def SubscribeState(self, subscriptions : List[Tuple[str, float, float]]) -> List[Union[bool, Exception]]: diff --git a/src/device/tests/Device_OpenConfig_Template.py b/src/device/tests/Device_OpenConfig_Template.py index df588b3d8..d95e86dfa 100644 --- a/src/device/tests/Device_OpenConfig_Template.py +++ b/src/device/tests/Device_OpenConfig_Template.py @@ -20,15 +20,20 @@ DEVICE_OC_ADDRESS = '127.0.0.1' # populate the Netconf Server IP address of th DEVICE_OC_PORT = 830 # populate the Netconf Server port of the device to test DEVICE_OC_USERNAME = 'username' # populate the Netconf Server username of the device to test DEVICE_OC_PASSWORD = 'password' # populate the Netconf Server password of the device to test -DEVICE_OC_TIMEOUT = 120 +DEVICE_OC_TIMEOUT = 15 DEVICE_OC_ID = json_device_id(DEVICE_OC_UUID) DEVICE_OC = json_device_packetrouter_disabled(DEVICE_OC_UUID) DEVICE_OC_CONNECT_RULES = json_device_connect_rules(DEVICE_OC_ADDRESS, DEVICE_OC_PORT, { - 'username': DEVICE_OC_USERNAME, - 'password': DEVICE_OC_PASSWORD, - 'timeout' : DEVICE_OC_TIMEOUT, + 'username' : DEVICE_OC_USERNAME, + 'password' : DEVICE_OC_PASSWORD, + 'force_running' : True, + 'hostkey_verify' : True, + 'look_for_keys' : True, + 'allow_agent' : True, + 'device_params' : {'name': 'default'}, + 'manager_params' : {'timeout' : DEVICE_OC_TIMEOUT}, }) DEVICE_OC_CONFIG_RULES = [] # populate your configuration rules to test -- GitLab