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

pygnmicli sub #89

Open ksator opened 2 years ago

ksator commented 2 years ago

Hello @akarneliuk I am not able to use pygnmicli with subscribe-once subscribe-stream subscribe2 I already provided output examples in issue #85 using subscribe2 on the same setup with Python pygNMI works

akarneliuk commented 2 years ago

Hello @ksator ,

Thanks, I already picked that up in that thread, but it is good to track that separately, so thanks for creating a new issue. The fix is coming...

Best, Anton

akarneliuk commented 2 years ago

Hello @ksator ,

it shall be fixed in #90 and release pygnmi==0.8.5. You still will be getting exception when you close stream subscription, cause that is related to the underlying gRPC code. I'm still looking into that one.

Best, Anton

ksator commented 2 years ago

Thank you @akarneliuk

capabilities works

pygnmicli -t "192.168.0.5:443" --token `cat token.tok` -o capabilities

subscribe-once works

pygnmicli -t "192.168.0.5:443" --token `cat token.tok` -o subscribe-once -x /inventory/state/device/device-id
pygnmicli -t "192.168.0.5:443" --token `cat token.tok` -o subscribe-once -x arista:/inventory/state/device/device-id
pygnmicli -t "192.168.0.5:443" --token `cat token.tok` -o subscribe-once -x openconfig:/interfaces/interface[name=Ethernet2]/state/admin-status --gnmi-path-target leaf1
ksator commented 2 years ago

subscribe-stream works, but there is a traceback when you close the connection using ^C

arista@devbox:~$ pygnmicli -t "192.168.0.5:443" --token `cat token.tok` -o subscribe-stream -x openconfig:/interfaces/interface[name=Ethernet2]/state/admin-status --gnmi-path-target leaf1
Collecting Capabilities...
Collection of Capabilities is successfull
{
    "update": {
        "update": [
            {
                "path": "interfaces/interface[name=Ethernet2]/state/admin-status",
                "val": "UP"
            }
        ],
        "timestamp": 1659298841014572795,
        "prefix": ""
    },
    "sync_response": true
}

^CTelemtry collection is temrinated.
Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/home/arista/.local/lib/python3.9/site-packages/pygnmi/client.py", line 950, in enqueue_updates
    for update in subscription:
  File "/home/arista/.local/lib/python3.9/site-packages/grpc/_channel.py", line 426, in __next__
    return self._next()
  File "/home/arista/.local/lib/python3.9/site-packages/grpc/_channel.py", line 826, in _next
    raise self
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
        status = StatusCode.CANCELLED
        details = "Channel closed!"
        debug_error_string = "{"created":"@1659299168.214843927","description":"Error received from peer ipv4:192.168.0.5:443","file":"src/core/lib/surface/call.cc","file_line":966,"grpc_message":"Channel closed!","grpc_status":1}"
>
arista@devbox:~$ 
ksator commented 2 years ago

subscribe2 doesnt work but I think I dont need if I use subscribe-stream and subscribe-once


arista@devbox:~$ pygnmicli -t "192.168.0.5:443" --token `cat token.tok` -o subscribe2 -x openconfig:/interfaces/interface[name=Ethernet2]/state/admin-status --gnmi-path-target leaf1
Collecting Capabilities...
Collection of Capabilities is successfull
Traceback (most recent call last):
  File "/home/arista/.local/bin/pygnmicli", line 163, in <module>
    main()
  File "/home/arista/.local/bin/pygnmicli", line 76, in main
    mode = args.operation.split("-")[1]
IndexError: list index out of range
arista@devbox:~$ ```
akarneliuk commented 2 years ago

Hey @ksator ,

That is correct, you don't need subsribe2, so just use subsribe-once and subsrcibe-stream. We will work out how to remove the tracebacks, but for the time being, it is important it is working. Thanks for validating.

Best, Anton

vinodkumar-singh commented 1 year ago

Hi, I still see this issue. Is this resolved? After closing the connection, if I re run the code to stream using subscribe2 or subscribe-once or subscribe-stream, it always throws error "grpc status:1, grpcs_message:"channel closed!"

akarneliuk commented 1 year ago

Hey @vinodkumar-singh , Is there any help needed?