Closed lokmahesh closed 8 months ago
I tried to debug it a bit looks like sub interface having a problem that it can not find key name in it. Here is the trace:
/home/mahesh/study/binding.py(2983)_set_enabled()->None -> self._set() (Pdb) /usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py(250)load_json() -> for key in d: (Pdb) p key 'enabled' (Pdb) n /usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py(251)load_json() -> child = getattr(obj, "get%s" % safe_name(key), None) (Pdb) /usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py(252)load_json() -> if child is None and skip_unknown is False: (Pdb) /usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py(253)load_json() -> raise AttributeError("JSON object contained a key that" + (Pdb) p key 'name' (Pdb) p d {'enabled': True, 'name': u'0', 'description': u'to_ISP-A'} (Pdb) p safe_name(key) u'name' (Pdb) p obj <pyangbind.lib.yangtypes.YANGBaseClass object at 0x7f65e47cc450> (Pdb) p dir(obj) ['_YANGBaseClassgenerate_extmethod', 'class', 'delattr', 'doc', 'format', 'getattribute', 'getitem', 'hash', 'init', 'iter', 'module', 'new', 'reduce', '__reduce_ex', 'repr', 'setattr', 'setitem', 'sizeof', 'slots', 'str', 'subclasshook', '_add_metadata', '_base_type', '_changed', '_choice', '_cpresent', '_default', '_defining_module', '_extensions', '_extensionsd', '_extmethods', '_get_description', '_get_enabled', '_get_index', '_is_config', '_is_container', '_is_keyval', '_is_leaf', '_mchanged', '_metadata', '_namespace', '_parent', '_path', '_path_helper', '_presence', '_present', '_pyangbind_elements', '_pybind_base_class', '_pybind_generated_by', '_register_path', '_register_paths', '_set', '_set_description', '_set_enabled', '_set_index', '_set_present', '_supplied_register_path', '_unset_description', '_unset_enabled', '_unset_index', '_yang_name', '_yang_path', '_yang_type', '_yc_config_openconfig_interfacesinterfaces_interface_subinterfaces_subinterface_configdescription', '_yc_config_openconfig_interfacesinterfaces_interface_subinterfaces_subinterface_configenabled', '_yc_config_openconfig_interfacesinterfaces_interface_subinterfaces_subinterface_configindex', 'append', 'default', 'description', 'elements', 'enabled', 'extend', 'get', 'index', 'insert', 'pop', 'remove', 'yang_name'] (Pdb) n /usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py(254)load_json() -> "did not exist (%s)" % (key)) (Pdb) n AttributeError: Attribut...(name)',) /usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py(254)load_json() -> "did not exist (%s)" % (key)) (Pdb) n --Return-- /usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py(254)load_json()->None -> "did not exist (%s)" % (key)) (Pdb) n AttributeError: Attribut...(name)',)
It's actually your json that is incorrect. In the subinterface:config you gave "name": "0"
"config": {
"enabled": true,
"name": "0",
"description": "to_ISP-A"
}
In the model it says it's "index": "0". The error states that it doesn't know the attribute 'name'.
Closing issues without recent activity
I am trying to load a json which I got from openconfig supported devices;
import pdb import json from pprint import * import pyangbind.lib.pybindJSON as pybindJSON from pyangbind.lib.serialise import pybindJSONDecoder import binding import pyangbind.lib.xpathhelper as xpathhelper ocbind = binding.openconfig_interfaces() ph = xpathhelper.YANGPathHelper() dst_ocif = pybindJSON.load("test.json", binding, "openconfig_interfaces", path_helper=ph) print pybindJSON.dumps(dst_ocif)
Attached test.txt which is test.json I am trying to load and want to convert it to IETF format but I am getting following error.
Traceback (most recent call last): File "ietf_test1.py", line 15, in
dst_ocif = pybindJSON.load("test.json", binding, "openconfig_interfaces", path_helper=ph)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/pybindJSON.py", line 78, in load
extmethods=extmethods, overwrite=overwrite)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/pybindJSON.py", line 58, in loads
path_helper=path_helper, extmethods=extmethods, overwrite=overwrite)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py", line 271, in load_json
path_helper=path_helper, skip_unknown=skip_unknown)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py", line 309, in load_json
obj=parent, path_helper=path_helper, skip_unknown=skip_unknown)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py", line 271, in load_json
path_helper=path_helper, skip_unknown=skip_unknown)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py", line 309, in load_json
obj=parent, path_helper=path_helper, skip_unknown=skip_unknown)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py", line 271, in load_json
path_helper=path_helper, skip_unknown=skip_unknown)
File "/usr/local/lib/python2.7/dist-packages/pyangbind/lib/serialise.py", line 253, in load_json
"did not exist (%s)" % (key))
AttributeError: JSON object contained a key thatdid not exist (name)
Where I am creating "binding" using following:
pyang --plugindir $PYBINDPLUGIN --use-xpathhelper -p /tmp/yang/standard/ietf/RFC/ -p .. -p yang-standard-openconfig/models/vlan -o binding yang-standard-openconfig/models/interfaces/openconfig-interfaces.yang yang-standard-openconfig/models/interfaces/openconfig-if-ip.yang -f pybind
test .txt
Any help ?