robshakir / pyangbind

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

Empty RPC XML Serialisation will not work #282

Closed eduardpo closed 1 year ago

eduardpo commented 2 years ago

Empty RPC is legal AFAIK, input/output are optional...

print(pybindIETFXMLEncoder.serialise(system_reset))

Exception:

Exception has occurred: AttributeError
'yc_reset_radio_bridge_tg_system__radio_bridge_tg_s' object has no attribute '_yang_name'
  File "/local/home/eduardp/siklu_pyang/tg_yang_models/src/pyangbind/pyangbind/lib/serialise.py", line 375, in encode
    return cls.generate_xml_tree(obj._yang_name, obj._yang_namespace, preprocessed)
  File "/local/home/eduardp/siklu_pyang/tg_yang_models/src/pyangbind/pyangbind/lib/serialise.py", line 380, in serialise
    doc = cls.encode(obj, filter=filter)
  File "/home/eduardp/siklu_pyang/pygen/test_system.py", line 37, in <module>
    print(pybindIETFXMLEncoder.serialise(system_reset))

Yang RPC:

rpc reset {
    description
        "RPC for rebooting the unit";
}

Corresponding python binding class:

class yc_reset_radio_bridge_tg_system__radio_bridge_tg_system_rpc_reset(PybindBase):
    """
    This class was auto-generated by the PythonClass plugin for PYANG
    from YANG module radio-bridge-tg-system - based on the path /radio_bridge_tg_system_rpc/reset. Each member element of
    the container is represented as a class variable - with a specific
    YANG type.

    YANG Description: RPC for rebooting the unit
    """
    _pyangbind_elements = {}

Command being used to generate bindings:

pyang --plugindir "$PYBINDPLUGIN" -f pybind --build-rpcs -o ../pygen/gen/system.py radio-bridge-tg-system.yang

Please advise, Ed

JoseIgnacioTamayo commented 1 year ago

Hi eduardpo,

Reproducing your issue is key to understand it and fix it.

Personally, I have always serialized/deserialized YANG schema nodes.

Looking forward to helping you with the issue.

JoseIgnacioTamayo commented 1 year ago

Hi,

'pyang --build-rpcs' would ' Generate class bindings for the input and output of RPCs defined in each module. These are placed at the root of each module'.

If the RPC has no input nor output, there would be no classes generated for them, nothing to serialize, I think.

JoseIgnacioTamayo commented 1 year ago

Closing, as there was no follow up on the issue.