robshakir / pyangbind

A plugin for pyang that creates Python bindings for a YANG model.
Other
204 stars 121 forks source link

TypeError: unhandled keyword with children case #327

Closed hyberdk closed 7 months ago

hyberdk commented 1 year ago

Im trying to convert the Cisco-IOS-XE-native.yang models into python libs, but I am getting this error:

TypeError: unhandled keyword with children case at Cisco-IOS-XE-native.yang:2458 (at Cisco-IOS-XE-ip.yang:506)

Im not sure exactly what the problem is, so I was hoping that some of you would know.. It might be related the the changes made recently in pyang 2.6.0 where there were several fixes for handling imports/include statements in Yang 1.1 See this: mbj4668/pyang@dc9755382194d59484f439b557b6110b138a3bd0

This fix was needed to make the Cisco models (that are using yang 1.1) pass validation.. Note the models that are using Yang 1.0 still fails due to RFC incompliance. Anywho... Im using the latest 17.12.1 model from YangModels..

here is the repo steps..

remember you must use pyang 2.6.0 for the models to pass :-)

eslau@N503476:/tmp$ git clone https://github.com/YangModels/yang.git
Cloning into 'yang'...
remote: Enumerating objects: 53094, done.
remote: Counting objects: 100% (2409/2409), done.
remote: Compressing objects: 100% (786/786), done.
remote: Total 53094 (delta 1741), reused 2035 (delta 1620), pack-reused 50685
Receiving objects: 100% (53094/53094), 126.69 MiB | 23.17 MiB/s, done.
Resolving deltas: 100% (41352/41352), done.
Updating files: 100% (100946/100946), done.

eslau@N503476:/tmp$ cd yang/

eslau@N503476:/tmp/yang$ python3 -m venv venv

eslau@N503476:/tmp/yang$ source venv/bin/activate

(venv) eslau@N503476:/tmp/yang$ pip install pyang==2.6.0
Collecting pyang==2.6.0
  Using cached pyang-2.6.0-py2.py3-none-any.whl (594 kB)
Collecting lxml
  Using cached lxml-4.9.3-cp310-cp310-manylinux_2_28_x86_64.whl (7.9 MB)
Installing collected packages: lxml, pyang
Successfully installed lxml-4.9.3 pyang-2.6.0

(venv) eslau@N503476:/tmp/yang$ pip install pyangbind
Collecting pyangbind
  Using cached pyangbind-0.8.4.post1-py3-none-any.whl (52 kB)
Requirement already satisfied: pyang in ./venv/lib/python3.10/site-packages (from pyangbind) (2.6.0)
Collecting enum34
  Using cached enum34-1.1.10-py3-none-any.whl (11 kB)
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting regex
  Using cached regex-2023.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (773 kB)
Requirement already satisfied: lxml in ./venv/lib/python3.10/site-packages (from pyangbind) (4.9.3)
Installing collected packages: enum34, six, regex, pyangbind
Successfully installed enum34-1.1.10 pyangbind-0.8.4.post1 regex-2023.10.3 six-1.16.0

(venv) eslau@N503476:/tmp/yang$ export PYBINDPLUGIN=`/usr/bin/env python -c \
'import pyangbind; import os; print ("{}/plugin".format(os.path.dirname(pyangbind.__file__)))'`

(venv) eslau@N503476:/tmp/yang$ echo $PYBINDPLUGIN
/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin

(venv) eslau@N503476:/tmp/yang$ cd vendor/cisco/xe/17121/

(venv) eslau@N503476:/tmp/yang/vendor/cisco/xe/17121$ pyang --strict Cisco-IOS-XE-native.yang

(venv) eslau@N503476:/tmp/yang/vendor/cisco/xe/17121$ pyang --plugindir $PYBINDPLUGIN -f pybind -o xe_native.py Cisco-IOS-XE-native.yang
Traceback (most recent call last):
  File "/tmp/yang/venv/bin/pyang", line 8, in <module>
    sys.exit(run())
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyang/scripts/pyang_tool.py", line 548, in run
    emit_obj.emit(ctx, modules, fd)
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 213, in emit
    build_pybind(ctx, modules, fd)
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 430, in build_pybind
    get_children(ctx, fd, children, m, m)
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 765, in get_children
    elements += get_element(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 1484, in get_element
    get_children(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 765, in get_children
    elements += get_element(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 1484, in get_element
    get_children(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 765, in get_children
    elements += get_element(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 1484, in get_element
    get_children(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 765, in get_children
    elements += get_element(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 1484, in get_element
    get_children(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 765, in get_children
    elements += get_element(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 1484, in get_element
    get_children(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 750, in get_children
    elements += get_element(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 1484, in get_element
    get_children(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 765, in get_children
    elements += get_element(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 1484, in get_element
    get_children(
  File "/tmp/yang/venv/lib/python3.10/site-packages/pyangbind/plugin/pybind.py", line 834, in get_children
    raise TypeError("unhandled keyword with children %s at %s" % (parent.keyword, parent.pos))
TypeError: unhandled keyword with children case at Cisco-IOS-XE-native.yang:2458 (at Cisco-IOS-XE-ip.yang:506)
(venv) eslau@N503476:/tmp/yang/vendor/cisco/xe/17121$

Anyone have any recommendations?

Esben

JoseIgnacioTamayo commented 10 months ago

It seems this is a duplicate of https://github.com/robshakir/pyangbind/issues/258.

JoseIgnacioTamayo commented 9 months ago

With the fix in https://github.com/robshakir/pyangbind/pull/340, the binding is generated.

It is a very large Python binding. Splitting it into directories, it takes 1.6 GB and took ~ 20 minutes to bind.

But at least, it does not break with Exception.

JoseIgnacioTamayo commented 7 months ago

340 is included in release 0.8.5.