robshakir / pyangbind

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

Issue with Generating Python Bindings Using –deviation Flag #352

Open ndmitri opened 1 month ago

ndmitri commented 1 month ago

Hello,

I am encountering an issue when attempting to generate Python bindings using pyangbind with the --deviation flag. The command runs without errors when generating the tree output, but fails during the binding generation step.

Environment

pyang version: 2.6.1 pyangbind version: 0.8.5 Python version: 3.11.9 Operating System: Ubuntu 22.04.2 LTS

Steps to Reproduce

  1. Generate Tree Output: This command runs without any errors and produces the correct tree output:
pyang -V -p ./EOS-4.22.1F -f tree --strict \
  --deviation ./EOS-4.22.1F/arista-intf-deviations.yang \
  --deviation ./EOS-4.22.1F/arista-intf-augments.yang \
  ./EOS-4.22.1F/openconfig-interfaces.yang
  1. Generate Python Bindings: This command fails with errors:
    pyang -V -p ./EOS-4.22.1F -f pybind --strict \
    --plugindir ~/.pyang/plugins \
    --deviation ./EOS-4.22.1F/arista-intf-deviations.yang \
    --deviation ./EOS-4.22.1F/arista-intf-augments.yang \
    -o oc-interfaces.py \
    ./EOS-4.22.1F/openconfig-interfaces.yang

Error Message

Here is the error message I receive when attempting to generate the bindings:

# module search path: ./EOS-4.22.1F:.:/home/ubuntu/.cache/pypoetry/virtualenvs/eos-py-lKpwrY1E-py3.11/share/yang/modules
# read ./EOS-4.22.1F/openconfig-interfaces.yang (CL)
# read EOS-4.22.1F/ietf-interfaces.yang
# read /home/ubuntu/.cache/pypoetry/virtualenvs/eos-py-lKpwrY1E-py3.11/share/yang/modules/ietf/ietf-interfaces.yang
# read EOS-4.22.1F/ietf-yang-types.yang
# read /home/ubuntu/.cache/pypoetry/virtualenvs/eos-py-lKpwrY1E-py3.11/share/yang/modules/ietf/ietf-yang-types.yang
# read EOS-4.22.1F/openconfig-yang-types.yang
# read EOS-4.22.1F/openconfig-extensions.yang
# read EOS-4.22.1F/openconfig-types.yang
# READ EOS-4.22.1F/openconfig-interfaces.yang
# read EOS-4.22.1F/openconfig-if-ethernet.yang
# read EOS-4.22.1F/iana-if-type.yang
# read /home/ubuntu/.cache/pypoetry/virtualenvs/eos-py-lKpwrY1E-py3.11/share/yang/modules/iana/iana-if-type.yang
# read EOS-4.22.1F/openconfig-if-aggregate.yang
# read EOS-4.22.1F/openconfig-if-types.yang
# read EOS-4.22.1F/openconfig-vlan.yang
# read EOS-4.22.1F/openconfig-vlan-types.yang
# read EOS-4.22.1F/openconfig-if-ip.yang
# read EOS-4.22.1F/openconfig-inet-types.yang
# read EOS-4.22.1F/openconfig-if-tunnel.yang
./EOS-4.22.1F/arista-intf-augments.yang:159: warning: node "openconfig-interfaces::type" is not found in "openconfig-vlan::config"
./EOS-4.22.1F/arista-intf-augments.yang:169: warning: node "openconfig-interfaces::type" is not found in "openconfig-vlan::config"
EOS-4.22.1F/openconfig-if-aggregate.yang:205: warning: node "openconfig-interfaces::state" is config false and is not part of the accessible tree
EOS-4.22.1F/openconfig-if-ethernet.yang:427: warning: node "openconfig-interfaces::state" is config false and is not part of the accessible tree
INFO: encountered (<pyang.error.Position object at 0x7f8917312840>, 'XPATH_NODE_NOT_FOUND1', ('openconfig-interfaces', 'type', 'openconfig-vlan', 'config'))
FATAL: pyangbind cannot build module that pyang has found errors with.

Request

I am seeking assistance in understanding why the pyangbind command fails despite no errors being reported in the tree validation step. Any insights or guidance on how to resolve this issue would be greatly appreciated.

Thank you for your help!

robshakir commented 1 month ago

For safety, pyangbind treats warnings from pyang as errors. The only two error types that are permitted are around invalid regexp patterns, and unused imports. You can edit this here but it is likely not guaranteed that code generation will succeed.

Alternatively, you can fix the models that are being used.

noredistribution commented 1 month ago

on the latest EOS version after referencing all the necessary files, e.g.:

pyang -V -p ./EOS-4.32.1F -f pybind --strict \
  --plugindir /home/tamas/.local/lib/python3.12/site-packages/pyangbind/plugin \
  --deviation ./EOS-4.32.1F/release/openconfig/models/interfaces/arista-intf-deviations.yang \
  --deviation ./EOS-4.32.1F/release/openconfig/models/interfaces/arista-intf-augments.yang \
  -o oc-interfaces.py \
  ./EOS-4.32.1F/openconfig/public/release/models/interfaces/openconfig-interfaces.yang \
  ../yang_modules/ietf-interfaces.yang \
  ../yang_modules/ietf-yang-types.yang \
  ../yang_modules/iana-if-type.yang \
  ./EOS-4.32.1F/openconfig/public/release/models/interfaces/openconfig-if-ethernet.yang \
  ./EOS-4.32.1F/openconfig/public/release/models/interfaces/openconfig-if-aggregate.yang \
  ./EOS-4.32.1F/openconfig/public/release/models/vlan/openconfig-vlan.yang \
  ./EOS-4.32.1F/openconfig/public/release/models/interfaces/openconfig-if-ip.yang

we are getting FATAL: unmapped type (arista-addr-type), that is now a deprecated type, that you might be aware of @robshakir , is it possible to add support for that in pyangbind? or is there an easy way to bypass that error?

xavier-contreras commented 1 month ago

I haven't spent enough time root causing this, but the public models do have deprecated leaves that generate bindings just fine. It may be a matter of how this is modeled that is triggering the error.