From 87e715aaf35b2f9ab82826985998e5e26cb94950 Mon Sep 17 00:00:00 2001 From: gifrerenom <lluis.gifre@cttc.es> Date: Tue, 24 Dec 2024 10:01:48 +0000 Subject: [PATCH] Device - gNMI OpenConfig Driver: - Refining code --- .../gnmi_openconfig/GnmiSessionHandler.py | 1 - .../gnmi_openconfig/handlers/Interface.py | 56 +++++++------------ 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py b/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py index 00409dfbd..03a55f472 100644 --- a/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py +++ b/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py @@ -40,7 +40,6 @@ class GnmiSessionHandler: self._use_tls = settings.get('use_tls', False) self._channel : Optional[grpc.Channel] = None self._stub : Optional[gNMIStub] = None - self._yang_handler = None self._monit_thread = None self._yang_handler = YangHandler() self._subscriptions = Subscriptions() diff --git a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py index c471faf2e..8521098a3 100644 --- a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py +++ b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py @@ -80,14 +80,19 @@ class InterfaceHandler(_Handler): yang_ipv4_addr.create_path('config/ip', address_ip) yang_ipv4_addr.create_path('config/prefix-length', address_prefix) + LOGGER.info('YangHandler Data:') + for path, dnode in yang_handler.get_data_paths().items(): + LOGGER.debug('|-> {:s}: {:s}'.format(str(path), json.dumps(dnode.print_dict()))) + str_path = '/interfaces/interface[name={:s}]'.format(if_name) str_data = yang_if.print_mem('json') json_data = json.loads(str_data) json_data = json_data['openconfig-interfaces:interface'][0] str_data = json.dumps(json_data) - is_error = False - LOGGER.warning('Releasing...') + # List elements to release: + LOGGER.warning('Objects to release:') + #LOGGER.warning('Releasing...') while not objects_to_free.empty(): LOGGER.warning('Getting...') try: @@ -96,42 +101,23 @@ class InterfaceHandler(_Handler): LOGGER.warning('Item is None') continue - try: - type_obj = type(obj) - LOGGER.warning('Releasing[type]: {:s}'.format(str(type_obj))) - except: - LOGGER.exception('Releasing[type]: <failed>') - - try: - str_obj = str(obj) - if str_obj is not None: - LOGGER.warning('Releasing[str]: {:s}'.format(str_obj)) - except: - LOGGER.exception('Releasing[str]: <failed>') - - try: - repr_obj = repr(obj) - if repr_obj is not None: - LOGGER.warning('Releasing[repr]: {:s}'.format(str(repr_obj))) - except: - LOGGER.exception('Releasing[repr]: <failed>') - - try: - LOGGER.warning('Releasing: {:s} => {:s}'.format( - str(obj.path()), str(obj.print_mem('json')) - )) - LOGGER.warning('Freeing...') - obj.free() - LOGGER.warning('Free done') - except: - LOGGER.exception('Something went wrong...') - is_error = True - break + LOGGER.warning('Releasing[type]: {:s}'.format(str(type(obj)))) + LOGGER.warning('Releasing: {:s} => {:s}'.format( + str(obj.path()), str(obj.print_mem('json')) + )) + + #try: + # LOGGER.warning('Freeing...') + # obj.free() + # LOGGER.warning('Free done') + #except: + # LOGGER.exception('Something went wrong...') + # is_error = True + # break except queue.Empty: LOGGER.warning('No more objects...') continue - if not is_error: - LOGGER.warning('Release done') + #LOGGER.warning('Release done') return str_path, str_data def parse( -- GitLab