Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gNMISession fails to decode GetRequest response when returned values is empty string #943

Closed
ygorelik opened this issue Jul 29, 2019 · 1 comment
Assignees

Comments

@ygorelik
Copy link
Collaborator

Seen in tests with IOS XR. When gNMISession requests a configuration, which is not present on device, the response has value of empty string. When that is value of a leaf it must be fine, but for container the expected value should be '{}' and for the list '[]'.

Expected Behavior

When configuration is not present on device the YDK should not fail with exception, but rather provide corrected JSON response.

Current Behavior

YDK fails with ValueError exception from json parser, when empty string value is returned for container or list.

Your Script

#!/usr/bin/env python
"""
Create configuration for model Cisco-IOS-XR-infra-infra-cfg.

usage: gn-create-xr-infra-infra-cfg-25-ydk.py [-h] [-v] device

positional arguments:
  device         gNMI device (http://user:password@host:port)

optional arguments:
  -h, --help     show this help message and exit
  -v, --verbose  print debugging messages
"""

import os
import logging

from argparse import ArgumentParser
from urllib.parse import urlparse

from ydk.path import Repository
from ydk.services import CRUDService
from ydk.gnmi.providers import gNMIServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_infra_infra_cfg as xr_infra_infra_cfg

if __name__ == "__main__":
    """Execute main program."""
    parser = ArgumentParser()
    parser.add_argument("-v", "--verbose", help="print debugging messages",
                        action="store_true")
    parser.add_argument("device",
                        help="gNMI device (http://user:password@host:port)")
    args = parser.parse_args()
    device = urlparse(args.device)

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.INFO)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                      "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    # create gNMI provider
    user_repo_dir = os.path.expanduser("~/.ydk/")
    repository = Repository(user_repo_dir+device.hostname)
    provider = gNMIServiceProvider(repo=repository,
                                   address=device.hostname,
                                   port=device.port,
                                   username=device.username,
                                   password=device.password)
    # create CRUD service
    crud = CRUDService()

    # delete configuration on gNMI device
    banner_filter = xr_infra_infra_cfg.Banners()
    response = crud.delete(provider, banner_filter)

    # read configuration on gNMI device
    banner_filter = xr_infra_infra_cfg.Banners()
    response = crud.read(provider, banner_filter)

Logs

/home/yan/.virtualenvs/ydk81/bin/python /home/yan/ydk-workspace/ydk-gen/scripts/issues/test_940.py -v ssh://admin:admin@10.30.110.84:57400
2019-07-26 14:05:06,148 - ydk - INFO - gNMIServiceProvider Connected to 10.30.110.84 via Insecure Channel
2019-07-26 14:05:06,149 - ydk - INFO - Executing CRUD delete operation on [Cisco-IOS-XR-infra-infra-cfg:banners]
2019-07-26 14:05:06,149 - ydk - INFO - Executing set gRPC operation 'delete' on entity 'Cisco-IOS-XR-infra-infra-cfg:banners'
2019-07-26 14:05:06,153 - ydk - INFO - 
=============== Set Request Sent ================
delete {
  origin: "Cisco-IOS-XR-infra-infra-cfg"
  elem {
    name: "banners"
  }
}


2019-07-26 14:05:07,674 - ydk - INFO - 
============= Set Response Received =============
response {
  path {
    origin: "Cisco-IOS-XR-infra-infra-cfg"
    elem {
      name: "banners"
    }
  }
  message {
  }
  op: DELETE
}
message {
}
timestamp: 1564170337500323260


2019-07-26 14:05:07,674 - ydk - INFO - Set Operation Succeeded
2019-07-26 14:05:07,674 - ydk - INFO - Operation succeeded
2019-07-26 14:05:07,676 - ydk - INFO - Executing CRUD read operation on [Cisco-IOS-XR-infra-infra-cfg:banners]
2019-07-26 14:05:07,676 - ydk - INFO - 
=============== Get Request Sent ================
path {
  origin: "Cisco-IOS-XR-infra-infra-cfg"
  elem {
    name: "banners"
  }
}
encoding: JSON_IETF


2019-07-26 14:05:07,760 - ydk - INFO - 
============= Get Response Received =============
notification {
  timestamp: 1564170337590864202
  update {
    path {
      origin: "Cisco-IOS-XR-infra-infra-cfg"
      elem {
        name: "banners"
      }
    }
    val {
      json_ietf_val: ""
    }
  }
}
error {
}


2019-07-26 14:05:07,760 - ydk - INFO - Get Operation Succeeded
Traceback (most recent call last):
  File "/home/yan/ydk-workspace/ydk-gen/scripts/issues/test_940.py", line 107, in <module>
    response = crud.read(provider, banner_filter)
  File "/home/yan/.virtualenvs/ydk81/lib/python3.5/site-packages/ydk/services/crud_service.py", line 69, in read
    read_top_entity = self._crud.read(provider, top_filters)
ValueError: parse error - unexpected '}'
2019-07-26 14:05:07,774 - ydk - INFO - Disconnected from device

Process finished with exit code 1

System Information

YDK-0.8.3

@ygorelik ygorelik self-assigned this Jul 29, 2019
ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Aug 1, 2019
ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Aug 1, 2019
@ygorelik
Copy link
Collaborator Author

ygorelik commented Aug 3, 2019

Resolved the issue in this commit:
Output of the script after bug fix:

2019-07-29 11:08:20,895 - ydk - INFO - gNMIServiceProvider Connected to 10.30.110.84 via Insecure Channel
2019-07-29 11:08:20,896 - ydk - INFO - Executing CRUD read operation on [Cisco-IOS-XR-infra-infra-cfg:banners]
2019-07-29 11:08:20,896 - ydk - INFO - 
=============== Get Request Sent ================
path {
  origin: "Cisco-IOS-XR-infra-infra-cfg"
  elem {
    name: "banners"
  }
}
encoding: JSON_IETF


2019-07-29 11:08:20,950 - ydk - INFO - 
============= Get Response Received =============
notification {
  timestamp: 1564418917430926131
  update {
    path {
      origin: "Cisco-IOS-XR-infra-infra-cfg"
      elem {
        name: "banners"
      }
    }
    val {
      json_ietf_val: ""
    }
  }
}
error {
}


2019-07-29 11:08:20,950 - ydk - INFO - Get Operation Succeeded
2019-07-29 11:08:20,952 - ydk - INFO - Disconnected from device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant