openconfig/gnmi

gnmi not initiating connection???

allan-silverstein opened this issue · 7 comments

Hello,
I'm trying to run a few simple gnmi tests (get request) and can't seem to get started. If I use a command line client of gnmi called "gnmic" (https://gnmic.kmrd.dev/), everything works fine to my device. The problem here is it appears a connection is never attempted?? It gets stuck on this
grpc.channel_ready_future(channel).result(timeout=10)

and says failed to connect. I ran a tcpdump on the interface to see what is happening but no traffic ever leaves the interface when I run the script??? I tried doing some logging but nothing is written the log file... Not sure how to troubleshoot here??

Here is the simple script:

import grpc
import sys
import re
from bin.gnmi_pb2_grpc import gNMIStub
from bin.gnmi_pb2 import (GetRequest, GetResponse, Path,
                                    PathElem, CapabilityRequest,
                                    Encoding, SetRequest, Update, TypedValue)
import logging
logging.basicConfig(filemode="w", filename="gnmi_app.log",
                    format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
                    datefmt='%H:%M:%S',level=logging.DEBUG,)
logging.getLogger("gnmi_app")


host = "10.191.252.157"
port = "50051" 
metadata=[('username', "xxxx"), ('password', "xxx")]

#####################
# Path builder
#####################
#def gnmi_path_generator(path_in_question):
## Removed code here as the script does not even get this far


try:
    channel = grpc.insecure_channel(':'.join([host, port]), metadata) # create an insecure channel
    grpc.channel_ready_future(channel).result(timeout=10) # specify timeout as 10s and provide the channel
    gnmi_stub = gNMIStub(channel) # creating the stub object and providing the channel
    path_string = "/drivenets-top/protocols/rsvp/config-items"
    get_path = gnmi_path_generator(path_string)
    get_message = GetRequest(path=[get_path], type=1, encoding=4) # paths are passed as a List.
    print(gnmi_stub.Get(get_message, metadata=metadata)) # printing the raw response
except grpc.FutureTimeoutError as e: # always check for TimeoutError
    print(e)
    print("Failed to connect")

Thx
Al Silverstein

gcsl commented
hellt commented

I just tried it with a certificate, and the same problem (fails here: grpc.channel_ready_future(channel).result(timeout=10)) tcpdump shows a connection is not even attempted??? It just seems I'm blind at this point for troubleshooting??? Any suggestions for troubleshooting?
Thx
Al

############################################################
# First step to is to create a credential with certificate.
############################################################
with open("grpc_dnor.crt", "rb") as fp: 
    cert = fp.read()
credentials = grpc.ssl_channel_credentials(cert) # object type is grpc.ChannelCredentials

try:
    breakpoint()
    channel = grpc.secure_channel(':'.join([host, port]), credentials) # create the secure channel
    grpc.channel_ready_future(channel).result(timeout=10) # specify timeout as 10s and provide the channel
    gnmi_stub = gNMIStub(channel) # creating the stub object and providing the channel
    path_string = "/drivenets-top/protocols/rsvp/config-items"
    get_path = gnmi_path_generator(path_string)
    get_message = GetRequest(path=[get_path], type=1, encoding=4)
    print(gnmi_stub.Get(get_message, metadata=metadata)) # printing the raw response
except grpc.FutureTimeoutError as e: # always check for TimeoutError
    print(e)
    print("Failed to connect")
gcsl commented

I'm running on an Ubuntu server 18.04. tcpdump is being run on the Linux server (client). When I perform a tcpdump on the server and use gnmic, I see the traffic; even if the cert is wrong and it fails, I see packets initiated. Whenever I try to setup the channel with the python client (secure or insecure), I never see a single packet initiated from the server (via tcpdump). Again, I haven't tried gnmi_cli but I have tried gnmic (https://netdevops.me/2020/gnmic-gnmi-cli-client-and-collector/) from the same system and it works fine. Are there any debugging flags/logging I can set so I can see more information and possibly point to where the problem is?
Thx
Al

gcsl commented

I did do the gRPC Hello world example and it worked fine....