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

Issue with pygnmi not returning value for get on leaf level for presence container #137

Open sai1274 opened 1 year ago

sai1274 commented 1 year ago

I am currently experiencing an issue with the pygnmi library. When attempting to use the 'get' operation on a leaf for a presence container, the function does not return any value. However, when the same 'get' operation is performed at the container level, it returns an empty dictionary for the specific leaf.

Here is a snippet of my code for reference:

from pygnmi.client import gNMIclient

# Define the server details
server_host = 'ip-address'  
server_port = 57400  

# Define the path for the GET request
path = ['Cisco-IOS-XR-um-grpc-cfg:grpc/no-tls']  # Replace with the desired path

# Connect to the server and send a GET request
with gNMIclient(target=(server_host, server_port),username="router", password="password", insecure=True) as client:
    client.connect()
    result = client.get("Cisco-IOS-XR-um-grpc-cfg://",path)
    print(result)

I've also attached the output below:

(venv) bash-4.4$ python3 temp1.py 
/ws/sampsamp-bgl/venv/lib64/python3.6/site-packages/pygnmi/client.py:16: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  import cryptography
{'notification': [{'timestamp': 1698385454495971212, 'prefix': None, 'alias': None, 'atomic': False, 'update': [{'path': 'grpc/no-tls'}]}]}
(venv) bash-4.4$ 

Can you please help me understand why the 'get' operation isn't returning the expected output at the leaf level? Any help or guidance would be appreciated.

Thanks, Sampath

akarneliuk commented 1 year ago

Hey @sai1274 ,

Could you please run for me the code with debug=True flag set and share with me the output?

So far, first impression that there is no value, and we check for value to present: https://github.com/akarneliuk/pygnmi/blob/master/pygnmi/client.py#L498

Thanks, Anton

sai1274 commented 1 year ago

Hey @akarneliuk ,

Here is the output you requested for

GRPC Target
----------------------------------------
IP_ADDRESS:57400
----------------------------------------

GRPC Channel options
----------------------------------------
[]
----------------------------------------

gNMI request
----------------------------------------

----------------------------------------

gNMI response
----------------------------------------
supported_models {
  ######
}
supported_encodings: JSON_IETF
supported_encodings: ASCII
supported_encodings: PROTO
gNMI_version: "0.8.0"

----------------------------------------

gNMI request
----------------------------------------
prefix {
  origin: "Cisco-IOS-XR-um-grpc-cfg"
}
path {
  origin: "Cisco-IOS-XR-um-grpc-cfg"
  elem {
    name: "grpc"
  }
  elem {
    name: "no-tls"
  }
}
encoding: JSON_IETF

----------------------------------------

gNMI response
----------------------------------------
notification {
  timestamp: 1698656459700171701
  update {
    path {
      origin: "Cisco-IOS-XR-um-grpc-cfg"
      elem {
        name: "grpc"
      }
      elem {
        name: "no-tls"
      }
    }
  }
}
error {
}

----------------------------------------

{'notification': [{'timestamp': 1698656459700171701, 'prefix': None, 'alias': None, 'atomic': False, 'update': [{'path': 'grpc/no-tls'}]}]}

I've replaced sensitive data with placeholders, indicated by hashes, in accordance with our company's data protection policy."

Thanks, Sampath