CiscoDevNet / ydk-gen

Generate model-driven APIs from YANG models
http://ciscodevnet.github.io/ydk-gen/
Apache License 2.0
137 stars 74 forks source link

data tag not recognized when attribute present #1021

Open amoruck opened 4 years ago

amoruck commented 4 years ago

Expected Behavior

Data tag should be correctly recognized

Current Behavior

"ydk - ERROR - Cannot find 'data' tag in RPC reply from device".

Steps to Reproduce

Query Arista switch with EOS 4.24.1.1F (tested with cEOS-lab-4.24.1.1F) for interface config

Your Script

from ydk.services import NetconfService, Datastore from ydk.providers import NetconfServiceProvider from ydk.models.openconfig import openconfig_interfaces as oc_interfaces import logging

def set_logger(): 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)

set_logger() provider = NetconfServiceProvider(address="172.18.0.3", port=830, username="admin", password="abc123", protocol="ssh")

netconf = NetconfService() interfaces = oc_interfaces.Interfaces() interface = interfaces.Interface() interface.name = 'Ethernet2' interfaces.interface.append(interface) cfg = netconf.get_config(provider, Datastore.running, interfaces)

Logs

2020-07-29 19:44:00,581 - ydk - INFO - Path where models are to be downloaded: /root/.ydk/172.18.0.3 2020-07-29 19:44:00,588 - ydk - INFO - Connected to 172.18.0.3 on port 830 using ssh with timeout of -1 2020-07-29 19:44:00,599 - ydk - INFO - Executing 'get' RPC on [openconfig-interfaces:interfaces] from running 2020-07-29 19:44:00,607 - ydk - INFO - ============= Sending RPC to device =============

Ethernet2

2020-07-29 19:44:00,611 - ydk - INFO - ============= Received RPC from device ============= <?xml version="1.0"?>

Ethernet2 true 300 false 0 Ethernet2 oc-vlan-types:TPID_0X8100 ianaift:ethernetCsmacd false false false false true 00:00:00:00:00:00 SPEED_UNKNOWN false 200 ACCESS 0 0 0 true 0 false false 1500 false false false 1500

2020-07-29 19:44:00,612 - ydk - ERROR - Cannot find 'data' tag in RPC reply from device <?xml version="1.0"?>

Ethernet2 true 300 false 0 Ethernet2 oc-vlan-types:TPID_0X8100 ianaift:ethernetCsmacd false false false false true 00:00:00:00:00:00 SPEED_UNKNOWN false 200 ACCESS 0 0 0 true 0 false false 1500 false false false 1500

Traceback (most recent call last): File "b.py", line 31, in cfg = netconf.get_config(provider, Datastore.running, interfaces) File "/usr/local/lib/python3.6/dist-packages/ydk/services/netconf_service.py", line 108, in get_config return _ns_get(provider, source, read_filter, self._ns.get_config) File "/usr/local/lib/python3.6/dist-packages/ydk/services/netconf_service.py", line 165, in _ns_get top_result = ns_call(provider, top_filters) File "/usr/lib/python3.6/contextlib.py", line 99, in exit self.gen.throw(type, value, traceback) File "/usr/local/lib/python3.6/dist-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error _raise(_exc) File "/usr/local/lib/python3.6/dist-packages/ydk/errors/error_handler.py", line 54, in _raise exec("raise exc from None") File "", line 1, in ydk.errors.YServiceProviderError: Cannot find 'data' tag in RPC reply 2020-07-29 19:44:00,624 - ydk - INFO - Disconnected from device

System Information

Python 3.6.9 root@ydk:/var/tmp# pip freeze bash: pip: command not found root@ydk:/var/tmp# pip3 freeze asn1crypto==0.24.0 chardet==3.0.4 cryptography==2.1.4 idna==2.6 keyring==10.6.0 keyrings.alt==3.0 pybind11==2.5.0 pycrypto==2.6.1 pygobject==3.26.1 python-apt==1.6.5+ubuntu0.3 python-debian==0.1.32 pyxdg==0.25 SecretStorage==2.3.1 six==1.11.0 ydk==0.8.4 ydk-models-ietf==0.1.5.post2 ydk-models-openconfig==0.1.8 root@ydk:/var/tmp# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.4 LTS Release: 18.04 Codename: bionic

amoruck commented 4 years ago

logs.txt attaching logs as file.

111pontes commented 4 years ago

Thanks for sharing the problem. Can you point to the standard that defines the time-modified attribute in the data tag? I believe that attribute isn't defined in an RFC.

amoruck commented 4 years ago

Thanks for replay, please understand that I am not netconf expert, I have only noticed that my first "hello world" interaction with the device failed, and it seems the XML I'm receiving from the device has correct syntax (as long as XML and data tag presence is considered)

So if it is really forbidden to add attributes to data tag in netconf response, and the correct behaviour is to throw an error not just to ignore unknown attribute - it should be at least mentioned in error message, because now error message suggests that response parsing routine has some cognitive problems (it says tag cannot be found when the tag is in fact present).

111pontes commented 4 years ago

The underlying issue is that your device is sending non-standard NETCONF messages that are confusing your script. Having said that, I agree that, at a minimum, the error message needs to be improved since the data tag does exist in the payload sent from the router. I'm marking this as an enhancement issue.

amoruck commented 4 years ago

So, it seems that because of this confusion caused by additional XML attibute it is now impossible to to use ydk with Arista switches; Wouldn't it be possible to change ydk behavior to warn about unknown attribute being ignored?

111pontes commented 4 years ago

Standards exist for a reason: to achieve interoperability (even at the cost of slower innovation). Interoperability suffers when you deviate from a standard. In this case, there is no debate on improving the error message. Now, deciding on whether to silently ignore an unexpected attribute would require careful analysis on our part before deciding to change the implementation. See the criticism of the Robustness principle.

amoruck commented 4 years ago

I have tried to find some help on Arista forum, and this is what they said. Unfortunately I am too noob in netconf to make anything useful out of it, so I'm leaving it here for reference;

111pontes commented 4 years ago

Thanks for sharing. The referenced comment describes what should be fixed on the network device to not violate the NETCONF standard. That is a change required by the device vendor. Furthermore, notice that the configuration data in your log file is not vendor neutral. These are at least some of the vendor-specific nodes that are not part of the OpenConfig specification:

/interfaces/interface/config/load-interval
/interfaces/interface/ethernet/config/fec-encoding
/interfaces/interface/ethernet/config/sfp-100base-t
/interfaces/interface/ethernet/pfc