CESNET / libyang-python

Python bindings for the libyang library
MIT License
62 stars 46 forks source link

validation failed: Missing required element "content-id" in "yang-library". #21

Closed gwieser1234 closed 3 years ago

gwieser1234 commented 3 years ago

Hi,

I am trying to build a data tree based on the example that you have provided. I can load the schema, but I was not able to create a data tree. I am getting an error: "libyang.util.LibyangError: validation failed: Missing required element "content-id" in "yang-library".

Any pointer is much appreciated.

ctx = libyang.Context() module = ctx.parse_module_str(''' ... module example { ... namespace "urn:example"; ... prefix "ex"; ... container data { ... list interface { ... key name; ... leaf name { ... type string; ... } ... leaf address { ... type string; ... } ... } ... leaf hostname { ... type string; ... } ... } ... } ... ''')

print(module.print_mem('tree')) module: example +--rw data +--rw interface* [name] | +--rw name string | +--rw address? string +--rw hostname? string

node = module.parse_data_dict({ ... 'data': { ... 'hostname': 'foobar', ... 'interface': [ ... {'name': 'eth0', 'address': '1.2.3.4/24'}, ... {'name': 'lo', 'address': '127.0.0.1'}, ... ], ... }, ... }) Traceback (most recent call last): File "", line 6, in File "/home/gwieser/libyang-python-test01/venv/lib/python3.6/site-packages/libyang/schema.py", line 190, in parse_data_dict validate=validate, File "/home/gwieser/libyang-python-test01/venv/lib/python3.6/site-packages/libyang/data.py", line 903, in dict_to_dnode no_yanglib=no_yanglib, File "/home/gwieser/libyang-python-test01/venv/lib/python3.6/site-packages/libyang/data.py", line 282, in validate raise self.context.error("validation failed") libyang.util.LibyangError: validation failed: Missing required element "content-id" in "yang-library".

rjarry commented 3 years ago

Hi @gwieser1234

Indeed, the example is incorrect, I will fix the README.

gwieser1234 commented 3 years ago

HI Robin, thank you that fixed it. Its working now.

savnishsingh commented 1 year ago

Hi Robin, I am facing the same issue with libyang-python. When i use ctx.parse_data_mem(xml_tree, "xml",strict=True) i receive this error

<nc:error-info>failed to parse data tree: Mandatory node "content-id" instance does not exist.</nc:error-info>

The RPC that i am trying contains this data,

<rpc>
    <edit-config>
      <target>
        <running/>
      </target>
        <config>
            <ManagedElement xmlns="urn:3gpp:sa5:_3gpp-common-managed-element">
              <id>O1/mns/ManagedElement-Single/123456</id>
              <GNBDUFunction xmlns="urn:3gpp:sa5:_3gpp-nr-nrm-gnbdufunction">
                <id>O1/mns/GnbDuFunction-Single/123456:5</id>
                <NRCellDU xmlns="urn:3gpp:sa5:_3gpp-nr-nrm-nrcelldu">
                  <id>O1/mns/NrCellDu-Single/123456:011</id>
                  <attributes>
                        <nRPCI>17</nRPCI>
                        <arfcnDL>140001</arfcnDL>
                        <arfcnUL>140002</arfcnUL>
                        <ssbFrequency>703</ssbFrequency>
                  </attributes>
                </NRCellDU>
              </GNBDUFunction>
            </ManagedElement>
        </config>
    </edit-config>
</rpc>

I believe get_yanglib_data is needed here but i don't understand completely how to get around this error

rjarry commented 1 year ago

https://netopeer.liberouter.org/doc/libyang/master/html/group__dataparseroptions.html

please do not resurect closed issues.

savnishsingh commented 1 year ago

Actually, i had exactly same error so i thought it might be related and not a new issue. So, from the link are you suggesting me to use this flag LYD_PARSE_SUBTREE? Because i have tried all others and it leads to same issue or it doesn't validate the tree with the PARSE_ONLY flag.

rjarry commented 1 year ago

The issue was reported with libyang 1 which is completely different.

I think rpc input cannot be validated without the complete datastore at hand (which you don't have in your case). So PARSE_ONLY makes a lot of sense. Maybe you should ask on the libyang project itself how to parse rpc input data. The python bindings don't do anything fancy besides wrapping the C API.

savnishsingh commented 1 year ago

Thanks Robin. I'll try the libyang project