openconfig/public

Bug pyang pyangbind cannot properly generate openconfig-bgp.yang v2.6.0

sever-sever opened this issue · 1 comments

I am unsure if it is a bug with pyang==2.6.0, pyangbind==0.8.4.post1 , or with openconfig-bgp.yang v2.6.0 or all their combinations.
It could be reproduced in a container with an alpine image.
There is the command and Dockerfile to build python3 bgp modules

After a build, there is no expected oc.bgp modules (generated file size 5.3K)
Let me show an example:

/opt/openconfig # ls -lah oc_bgp.py 
-rw-r--r--    1 root     root        5.3K Nov 21 16:22 oc_bgp.py
/opt/openconfig # 
/opt/openconfig # python3
Python 3.11.6 (main, Oct  4 2023, 06:22:18) [GCC 12.2.1 20220924] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from oc_bgp import openconfig_bgp
>>> oc = openconfig_bgp()
>>> 
>>> oc.bgp.global_.config.as_ = "65001"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'openconfig_bgp' object has no attribute 'bgp'
>>> 
>>> dir(oc)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__weakref__', '_pyangbind_elements', 'elements', 'get']
>>> 

I found another openconfig-bgp.yang that works fine in this build
(generated file size 33.9M)

/opt/openconfig/yang_modules # rm openconfig-bgp.yang 
/opt/openconfig/yang_modules # 
/opt/openconfig/yang_modules # wget https://raw.githubusercontent.com/nanog75/code-samples/a64e8ab62844abc2b32f1a168ebbba31b35ad43d/ztp/yang/openconfig-bgp.yang
Connecting to raw.githubusercontent.com (185.199.108.133:443)
saving to 'openconfig-bgp.yang'
openconfig-bgp.yang  100% |****************************************************************************************************************************************************************|  3284  0:00:00 ETA
'openconfig-bgp.yang' saved
/opt/openconfig/yang_modules # 

/opt/openconfig/yang_modules # pyang --plugindir /usr/lib/python3.11/site-packages/pyangbind/plugin/ --format pybind -o oc_bgp.py openconfig-bgp.yang
/opt/openconfig/yang_modules # 
/opt/openconfig/yang_modules # ls -lah | grep .py
-rw-r--r--    1 root     root       33.9M Nov 21 16:54 oc_bgp.py
/opt/openconfig/yang_modules # 

And it works fine:

>>> 
>>> from oc_bgp import openconfig_bgp
>>> oc = openconfig_bgp()
>>> 
>>> oc.bgp.global_.config.as_ = "65001"
>>> 
>>> oc.
oc.bgp         oc.elements()  oc.get(        
>>> oc.

Likely because BGP was refactored to live inside a network-instance; there is no /bgp container. See eabe995.