Skip to content

Data tree example is not working #65

@tias77

Description

@tias77

cffi==1.15.1
libyang==2.7.1
pycparser==2.21

Python 3.10.12 (main, Jun  7 2023, 20:12:10) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import libyang
>>> 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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/libyang/schema.py", line 215, in parse_data_dict
    return dict_to_dnode(
  File "/usr/local/lib/python3.10/site-packages/libyang/data.py", line 1277, in dict_to_dnode
    result.root().validate(
  File "/usr/local/lib/python3.10/site-packages/libyang/data.py", line 430, in validate
    self.validate_all(no_state, validate_present)
  File "/usr/local/lib/python3.10/site-packages/libyang/data.py", line 449, in validate_all
    raise self.context.error("validation failed")
libyang.util.LibyangError: validation failed: Mandatory node "content-id" instance does not exist.
>>>

It seems to be related to config store:
93676bc
#21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions