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

Client-side validation of xr_shellutil_cfg.HostNames() in 0.7.0 #739

Closed
rikwade opened this issue Apr 5, 2018 · 8 comments
Closed

Client-side validation of xr_shellutil_cfg.HostNames() in 0.7.0 #739

rikwade opened this issue Apr 5, 2018 · 8 comments
Assignees
Projects
Milestone

Comments

@rikwade
Copy link

rikwade commented Apr 5, 2018

Issue tracker is ONLY used for reporting bugs. Please use the YDK Community for any support issues.

Expected Behavior

Sending incorrect type parameter returns: <class 'ydk.errors.YPYModelError'>

Current Behavior

Incorrect parameter returns: <class 'ydk.errors.YPYServiceProviderError'>

Steps to Reproduce

Send Int as parameter to xr_shellutil_cfg.HostNames.host_name rather than String

Your Script

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_shellutil_cfg as xr_shellutil_cfg

new_hostname=xr_shellutil_cfg.HostNames()
new_hostname.host_name=-1

try:
    crud.update(provider,new_hostname)
except:
    print sys.exc_info()[0]

Logs

Enable logging and post the logs below

Executing CRUD update operation
=============Generating payload to send to device=============

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <target>
    <candidate/>
  </target>
  <error-option>rollback-on-error</error-option>
  <config><host-names xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-shellutil-cfg" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="merge">
  <host-name>-1</host-name>
</host-names>
</config>
</edit-config>
</rpc>


=============Reply payload received from device=============

<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="25">
  <ok/>
</rpc-reply>



=============Executing commit=============

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <commit/>
</rpc>

=============Reply payload received from device=============

<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="26">
  <rpc-error>
    <error-type>application</error-type>
    <error-tag>operation-failed</error-tag>
    <error-severity>error</error-severity>
    <error-path xmlns:ns1="http://cisco.com/ns/yang/Cisco-IOS-XR-shellutil-cfg">ns1:host-names/ns1:host-name</error-path>
    <error-message xml:lang="en">The process 'syslogd' rejected the operation but returned no error</error-message>
  </rpc-error>
</rpc-reply>



RPC error occurred: <?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="26">
  <rpc-error>
    <error-type>application</error-type>
    <error-tag>operation-failed</error-tag>
    <error-severity>error</error-severity>
    <error-path xmlns:ns1="http://cisco.com/ns/yang/Cisco-IOS-XR-shellutil-cfg">ns1:host-names/ns1:host-name</error-path>
    <error-message xml:lang="en">The process 'syslogd' rejected the operation but returned no error</error-message>
  </rpc-error>
</rpc-reply>

System Information

Python 2.7.14
YDK 0.7.0
Ubuntu 17.10
x86
XR: 6.1.4.16I

@ghost
Copy link

ghost commented Apr 5, 2018

Hi @rikwade , as can be seen from the documentation, there is no restriction specified for the host_name field. The documentation is generated from the yang model. So in this case, the yang model has no restriction. Only if there is a restriction, YPYModelError is raised.

@ghost ghost added the question label Apr 5, 2018
@rikwade
Copy link
Author

rikwade commented Apr 6, 2018

Hi @abhikeshav, thank you for the information. The behaviour I was expecting was to receive a YPYModelError if an int was passed to a str field in the model. For example if I explicitly cast the parameter as an int with:

new_hostname.host_name=int(123456)

it is accepted and configured on the XR device. Thank you for clarifying the behaviour we should expect.

@ghost
Copy link

ghost commented Apr 6, 2018

No problem, @rikwade. YPYModelError is only meant for checking the restrictions in the yang model. Python type checks for int instead of str is not part of this check.

@111pontes
Copy link
Collaborator

Thanks, @rikwade. We will look into enhancing this type of validation.

@111pontes
Copy link
Collaborator

Wonder why our automated testing didn't catch this issue. It seems we need to strengthen our type validation tests.

@rikwade
Copy link
Author

rikwade commented Apr 9, 2018

@abhikeshav The confusing point is that the YANG model specifies hostname as a 'str'. So one may expect a client-side type check if a developer passes an 'int'.

The setting of a hostname is often used as a "YDK Hello World", and it is a good method of demonstrating client-side validation. Therefore if this simple example does not exhibit the expected behaviour then a more complex example needs to be used, such as setting a static route (which does exhibit the expected behaviour if an invalid IP address is passed as the parameter).

@111pontes It would be good to look at this validation.

@ghost
Copy link

ghost commented Apr 9, 2018 via email

@ghost ghost added bug python and removed question labels Apr 23, 2018
@ghost ghost added this to Done in YDK May 1, 2018
@ghost ghost moved this from Done to In progress in YDK May 1, 2018
@ghost ghost added this to the 0.7.2-dev milestone May 1, 2018
@ghost ghost assigned ylil93 May 2, 2018
@ghost
Copy link

ghost commented Sep 15, 2018

Fixed in #820

@ghost ghost closed this as completed Sep 15, 2018
YDK automation moved this from In progress to Done Sep 15, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
YDK
  
Done
Development

No branches or pull requests

3 participants