lyd_validate_all behavior
Hi, I'm running into some peculiar behavior with lyd_validate_all() and I just wanted to check whether this was expected or not.
- Create a tree where one of the leafs is a key, in this example that is "first"
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<line>
<vty>
<first>0</first>
<ip>
<tcp/>
</ip>
<length>512</length>
<monitor/>
</vty>
</line>
</native>
- Delete the key
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<line>
<vty>
<ip>
<tcp/>
</ip>
<length>512</length>
<monitor/>
</vty>
</line>
</native>
-
Validating the node with lyd_validate_all(LYD_VALIDATE_PRESENT) does not raise an error even though the key to this configuration is missing.
-
If I try to create a tree with the XML from step 2, I get an error Read Mem: List instance is missing its key "first"., (Path: Data location "/Cisco-IOS-XE-native:native/line/vty")
Is it expected that lyd_validate_all catch this error in the modified tree?
You delete the key by calling lyd_free() on it? The validation may not check this because the parser already does so I suppose this should be forbidden. The idea is that a list instance may never exist without its keys, it can only be an opaque node then.
Yes, we use lyd_free() to delete the key. The idea is that we would delete the key and then replace it with another key using lyd_new_path().
I see, you cannot do that anymore. Instead, create the new list instance and then "swap" the old instance with the new instance.