akarneliuk / pygnmi

The pure Python implementation of the gNMI client.
https://training.karneliuk.com
BSD 3-Clause "New" or "Revised" License
129 stars 44 forks source link

AttributeError: 'gNMIclient' object has no attribute '_gNMIclient__channel' #99

Open renukamanavalan opened 2 years ago

renukamanavalan commented 2 years ago

Versions installed:

admin@str-s6000-on-5:~$ pip freeze | grep -i gnmi
gnmi==0.0.0a0
gnmi-py==0.7.1
pygnmi==0.8.9
admin@str-s6000-on-5:~$ 

My trial: I just created client and tried a subscribe onchange stream request. The .subscribe fails with following: AttributeError: 'gNMIclient' object has no attribute '_gNMIclient__channel'

Details below. Any tips would be pretty helpful.

admin@str-s6000-on-5:~$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pygnmi.client import gNMIclient
>>> host = ('127.0.0.1', '50051')
>>> cl = gNMIclient(host, username='admin', password='admin', insecure=True)
>>> subscribe
{'subscription': [{'path': 'all', 'mode': 'on_change'}], 'use_aliases': False, 'mode': 'stream', 'encoding': 'json'}
>>> st = cl.subscribe_stream(subscribe=subscribe)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/pygnmi/client.py", line 840, in subscribe_stream
    return StreamSubscriber(self.__channel, gnmi_message_request, self.__metadata)
AttributeError: 'gNMIclient' object has no attribute '_gNMIclient__channel'
>>> ds = {'subscription': [{'path': 'DOCKER_STATS', 'mode': 'sample', 'sample_interval': 10000000000}], 'use_aliases': False, 'mode': 'stream', 'encoding': 'json'}
>>> st = cl.subscribe_stream(subscribe=ds)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/pygnmi/client.py", line 840, in subscribe_stream
    return StreamSubscriber(self.__channel, gnmi_message_request, self.__metadata)
AttributeError: 'gNMIclient' object has no attribute '_gNMIclient__channel'
akarneliuk commented 2 years ago

Hey @renukamanavalan , Can you please provide a bit more details:

renukamanavalan commented 2 years ago

Wow! Out of words! Never expected such a quick response.

Here are the details. 1) There is a opensource project called SONiC. 2) The main firmware/os-image is buildimage 3) One of the submodules the OS uses is sonic-gnmi 4) This submodule runs a gNMI server that can be reached via gnmi_cli (a GO based tool) as below. gnmi_cli -client_types=gnmi -a 127.0.0.1:50051 -t EVENTS -logtostderr -insecure -v 7 -streaming_type ON_CHANGE -q all[heartbeat=5] -qt s 5) One of the use cases we have, the internal host processes publishes events. A gnmi client connection to telemetry can be used to receive those events. Generally external tools connect to receive the events.

I am writing a test script that publishes few events and would like to receive the same via gnmi Query to help test end to end. My script is in python, so if I can write a python code to subscribe to gNMI server and receive the events, it will help.

I installed pygnmi. I have attached the entire o/p of pip freeze. I just tried the steps above, to test it first, from inside the host. BTW, running the gnmi_cli (mentioned above) works fine inside the host.

admin@str-s6000-on-5:~$ sudo pip freeze | grep -i gnmi
gnmi==0.0.0a0
gnmi-py==0.7.1
pygnmi==0.8.9
admin@str-s6000-on-5:~$ 

pip_freeze.txt

Any help from you would be great

THANK YOU!