CiscoDevNet / ydk-gen

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

Node name `entity` not disambiguated in some cases #991

Closed 111pontes closed 2 years ago

111pontes commented 4 years ago

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

Expected Behavior

Model packages should be able to support any valid YANG model.

Current Behavior

In models with containers and lists named 'entity', the generated Python module doesn't disambiguate the class name correctly:

$ grep "class Entity(Entity):" *.py
Cisco_IOS_XR_invmgr_cfg.py:    class Entity(Entity):
Cisco_IOS_XR_invmgr_oper.py:        class Entity(Entity):
Cisco_IOS_XR_invmgr_oper.py:            class Entity(Entity):
Cisco_IOS_XR_snmp_agent_cfg.py:        class Entity(Entity):
$ 

Disambiguation works correctly for leaf nodes:

$ grep "self.entity_ =" *.py
Cisco_IOS_XR_invmgr_cfg.py:        self.entity_ = YList(self)
Cisco_IOS_XR_invmgr_oper.py:            self.entity_ = YList(self)
Cisco_IOS_XR_invmgr_oper.py:                self.entity_ = Inventory.Racks.Rack.Entity()
Cisco_IOS_XR_ip_mobileip_oper.py:                            self.entity_ = None
Cisco_IOS_XR_snmp_agent_cfg.py:            self.entity_ = Snmp.Notification.Entity()
$ 

Steps to Reproduce

$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ydk.models.cisco_ios_xr.Cisco_IOS_XR_invmgr_oper import Inventory
>>> 
>>> inventory = Inventory()
>>> rack = inventory.racks.Rack()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/ydk/models/cisco_ios_xr/Cisco_IOS_XR_invmgr_oper.py", line 3804, in __init__
    self.powershelf = Inventory.Racks.Rack.Powershelf()
  File "/usr/local/lib/python3.6/dist-packages/ydk/models/cisco_ios_xr/Cisco_IOS_XR_invmgr_oper.py", line 40817, in __init__
    self.yang_name = "powershelf"
  File "/usr/local/lib/python3.6/dist-packages/ydk/models/cisco_ios_xr/Cisco_IOS_XR_invmgr_oper.py", line 40830, in __setattr__
    self._perform_setattr(Inventory.Racks.Rack.Powershelf, [], name, value)
  File "/usr/local/lib/python3.6/dist-packages/ydk/types/py_types.py", line 350, in _perform_setattr
    self.__class__.__name__))
ydk.errors.YModelError: Attempt to assign unknown attribute 'yang_name' to 'Powershelf'.
>>> 

Your Script

from ydk.models.cisco_ios_xr.Cisco_IOS_XR_invmgr_oper import Inventory

inventory = Inventory()
rack = inventory.racks.Rack()

Logs

Enable logging and post the logs below

System Information

$ pip3 list | grep ydk
ydk                      0.8.3                                   
ydk-models-cisco-ios-xe  16.9.3                                  
ydk-models-cisco-ios-xr  6.6.2                                   
ydk-models-cisco-nx-os   9.2.3                                   
ydk-models-ietf          0.1.5.post2                             
ydk-models-openconfig    0.1.6.post1                             
ydk-service-gnmi         0.4.0.post2                             
$ 
ygorelik commented 4 years ago

Duplicate of #983.