akarneliuk / pygnmi

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

Error getting capabilities from gnxi-simulators #24

Closed rkkilari closed 2 years ago

rkkilari commented 3 years ago

I am trying to test with gnmi simulators. I am getting below error. Same simulator returns successful response with gnmi_cli command line request.

Simulator is from https://github.com/onosproject/gnxi-simulators gnmi simulator is running in docker on port 10162. Here is the code I am using to get capabilities.

-----code starts here --->

!/usr/bin/env python

//# Modules from pygnmi.client import gNMIclient ///# Body if name == "main": gc = gNMIclient(target=("127.0.0.1", 10162), username="admin",password="admin", insecure=True) result = gc.capabilities() print(f"127.0.0.1 : {result}\n\n") ----- code ends here --->

--- Error message starts here -----

$ python3 capabilities.py Traceback (most recent call last): File "/home/test/.local/lib/python3.8/site-packages/pygnmi/client.py", line 181, in capabilities gnmi_message_response = self.stub.Capabilities(gnmi_message_request, metadata=self.metadata) AttributeError: 'gNMIclient' object has no attribute '_gNMIclient__stub'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "capabilities.py", line 10, in result = gc.capabilities() File "/home/test/.local/lib/python3.8/site-packages/pygnmi/client.py", line 222, in capabilities except grpc._channel._InactiveRpcError as err: AttributeError: module 'grpc' has no attribute '_channel'

akarneliuk commented 3 years ago

Hello @rkkilari ,

thanks for your enquiry. The reason for the error is that you are missing connect() method. If you are willing to use a long-living sessions, your code should look like:

from pygnmi.client import gNMIclient

if name == "__main__":
    gc = gNMIclient(target=("127.0.0.1", 10162), username="admin",password="admin", insecure=True)
    gc.connect()

    result = gc.capabilities()
    print(f"127.0.0.1 : {result}\n\n")

    gc.close()

Alternatively you can use the with ... as ... context manager, as provided in examples:

from pygnmi.client import gNMIclient

if name == "__main__":
    with gNMIclient(target=("127.0.0.1", 10162), username="admin",password="admin", insecure=True) as gc:
        result = gc.capabilities()
    print(f"127.0.0.1 : {result}\n\n")

Let me know if that works for you.

Best, Anton

rkkilari commented 3 years ago

Thank u for the suggestion, (Tried 127.0.0.1 and 0.0.0.0, I know it should not matter.) I am getting below error. I suspect it can not see the running simulator, as it is timing out But gnmi_cli gets a successful response though.

pygnmi2$ python test.py Traceback (most recent call last): File "test.py", line 6, in with gNMIclient(target=("0.0.0.0", 10164), username="admin",password="admin", insecure=True) as gc: File "/home/mchin/.local/lib/python3.8/site-packages/pygnmi/client.py", line 66, in enter return self.connect() File "/home/mchin/.local/lib/python3.8/site-packages/pygnmi/client.py", line 76, in connect grpc.channel_ready_future(self.channel).result(timeout=self.gnmi_timeout) File "/home/mchin/.local/lib/python3.8/site-packages/grpc/_utilities.py", line 140, in result self._block(timeout) File "/home/mchin/.local/lib/python3.8/site-packages/grpc/_utilities.py", line 86, in _block raise grpc.FutureTimeoutError() grpc.FutureTimeoutError

akarneliuk commented 3 years ago

Hello @rkkilari ,

the grpc.FutureTimeoutError means that the pygnmi cannot connect to your gNMI-speaking device. I'm afraid, we are not familiar with what it is, hence, cannot really help here. We'd suggest to check:

Can you share the nmap and gnmi_cli outputs, please?

Thanks