From edbe53e27d40f258765f9d407c05318d44b1f13d Mon Sep 17 00:00:00 2001 From: akarneliuk Date: Wed, 10 Aug 2022 09:06:27 +0100 Subject: [PATCH 1/3] 0.8.7 --- README.rst | 4 ++++ pygnmi/client.py | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 799ebdd..acb2010 100644 --- a/README.rst +++ b/README.rst @@ -86,6 +86,10 @@ Contributors Dev Log ======= +Release **0.8.7**: + +- Fixed bug, when returned ``json_val`` or ``json_ietf_val`` is not processed correctly if the value is empty string. + Release **0.8.6**: - Fixed minor issue with establishing ``insecure`` channel. diff --git a/pygnmi/client.py b/pygnmi/client.py index 9d375e2..e4c9da3 100644 --- a/pygnmi/client.py +++ b/pygnmi/client.py @@ -438,13 +438,15 @@ def get(self, prefix: str = "", path: list = None, # Message Update, Key val if update_msg.HasField('val'): if update_msg.val.HasField('json_ietf_val'): - update_container.update({'val': json.loads(update_msg.val.json_ietf_val)}) + processed_val = json.loads(update_msg.val.json_ietf_val) if update_msg.val.json_ietf_val else None + update_container.update({'val': processed_val}) elif update_msg.val.HasField('json_val'): - update_container.update({'val': json.loads(update_msg.val.json_val)}) + processed_val = json.loads(update_msg.val.json_val) if update_msg.val.json_val else None + update_container.update({'val': processed_val}) elif update_msg.val.HasField('string_val'): - update_container.update({'val':update_msg.val.string_val}) + update_container.update({'val': update_msg.val.string_val}) elif update_msg.val.HasField('int_val'): update_container.update({'val': update_msg.val.int_val}) From e550fb4f5659da9dba9c6354d572934c5bdc7cd4 Mon Sep 17 00:00:00 2001 From: akarneliuk Date: Wed, 10 Aug 2022 11:29:47 +0100 Subject: [PATCH 2/3] 0.8.7 --- README.rst | 2 +- pygnmi/__init__.py | 2 +- pygnmi/client.py | 2 +- setup.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index acb2010..3b16af1 100644 --- a/README.rst +++ b/README.rst @@ -405,7 +405,7 @@ Release **0.1.0**: (c)2020-2022, karneliuk.com -.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.6&color=success +.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.7&color=success .. _version: https://pypi.org/project/pygnmi/ .. |tag| image:: https://img.shields.io/static/v1?label=status&message=stable&color=success .. _tag: https://pypi.org/project/pygnmi/ diff --git a/pygnmi/__init__.py b/pygnmi/__init__.py index f863c73..29232b0 100644 --- a/pygnmi/__init__.py +++ b/pygnmi/__init__.py @@ -2,4 +2,4 @@ pyGNMI module to manage network devices with gNMI (c)2020-2022, Karneliuk """ -__version__ = "0.8.6" +__version__ = "0.8.7" diff --git a/pygnmi/client.py b/pygnmi/client.py index e4c9da3..265e52f 100644 --- a/pygnmi/client.py +++ b/pygnmi/client.py @@ -191,7 +191,7 @@ def connect(self, timeout: int = None): # Set empty override if neither CN ans SARs exist if not ssl_cert_common_name and not self.__cert_sans: - self.__options.append(("grpc.ssl_target_name_override", "")) + self.__options.append(("grpc.ssl_target_name_override", "".encode(encoding="utf-8"))) logger.warning('ssl_target_name_override is applied, should be used for testing only!') diff --git a/setup.py b/setup.py index fbba7c3..cccb850 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='pygnmi', packages=['pygnmi', 'pygnmi.spec.v080', 'pygnmi.artefacts'], - version='0.8.6', + version='0.8.7', license='bsd-3-clause', description='Pure Python gNMI client to manage network functions and collect telemetry.', long_description=long_description, @@ -14,7 +14,7 @@ author='Anton Karneliuk', author_email='anton@karneliuk.com', url='https://github.com/akarneliuk/pygnmi', - download_url='https://github.com/akarneliuk/pygnmi/archive/v0.8.6.tar.gz', + download_url='https://github.com/akarneliuk/pygnmi/archive/v0.8.7.tar.gz', keywords=['gnmi', 'automation', 'grpc', 'network'], install_requires=[ 'grpcio', From 673b9915fd6cf4a825b366151a3f6e05758b6251 Mon Sep 17 00:00:00 2001 From: akarneliuk Date: Wed, 10 Aug 2022 17:10:24 +0100 Subject: [PATCH 3/3] 0.8.7 --- README.rst | 2 +- pygnmi/client.py | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 3b16af1..7958df5 100644 --- a/README.rst +++ b/README.rst @@ -88,7 +88,7 @@ Dev Log Release **0.8.7**: -- Fixed bug, when returned ``json_val`` or ``json_ietf_val`` is not processed correctly if the value is empty string. +- Fixed bug, when returned ``json_val`` or ``json_ietf_val`` is not processed correctly if the value is empty string. Fix for `Issue 58 `_. Release **0.8.6**: diff --git a/pygnmi/client.py b/pygnmi/client.py index 265e52f..c7456c5 100644 --- a/pygnmi/client.py +++ b/pygnmi/client.py @@ -10,6 +10,7 @@ import time import threading import os +from typing import Any import cryptography import grpc from pygnmi.spec.v080.gnmi_pb2_grpc import gNMIStub @@ -438,12 +439,10 @@ def get(self, prefix: str = "", path: list = None, # Message Update, Key val if update_msg.HasField('val'): if update_msg.val.HasField('json_ietf_val'): - processed_val = json.loads(update_msg.val.json_ietf_val) if update_msg.val.json_ietf_val else None - update_container.update({'val': processed_val}) + update_container.update({'val': process_potentially_json_value(update_msg.val.json_ietf_val)}) elif update_msg.val.HasField('json_val'): - processed_val = json.loads(update_msg.val.json_val) if update_msg.val.json_val else None - update_container.update({'val': processed_val}) + update_container.update({'val': process_potentially_json_value(update_msg.val.json_val)}) elif update_msg.val.HasField('string_val'): update_container.update({'val': update_msg.val.string_val}) @@ -1244,8 +1243,24 @@ def telemetryParser(in_message=None, debug: bool = False): def debug_gnmi_msg(is_printable, what_to_print, message_name) -> None: + """This helper function prints debug output""" if is_printable: print(message_name) print("-" * os.get_terminal_size().columns) print(what_to_print) print("-" * os.get_terminal_size().columns, end="\n\n\n") + + +def process_potentially_json_value(input_val) -> Any: + """This helper method converts value from bytestream""" + unprocessed_value = input_val.decode(encoding="utf-8") + + if unprocessed_value: + try: + processed_val = json.loads(unprocessed_value) + except json.decoder.JSONDecodeError: + processed_val = unprocessed_value + else: + processed_val = None + + return processed_val