libyang icon indicating copy to clipboard operation
libyang copied to clipboard

lyd_validate_all behavior

Open rabhat31 opened this issue 2 years ago • 3 comments

Hi, I'm running into some peculiar behavior with lyd_validate_all() and I just wanted to check whether this was expected or not.

  1. 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>
  1. 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>
  1. Validating the node with lyd_validate_all(LYD_VALIDATE_PRESENT) does not raise an error even though the key to this configuration is missing.

  2. 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?

rabhat31 avatar Aug 24 '23 17:08 rabhat31

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.

michalvasko avatar Aug 25 '23 09:08 michalvasko

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().

rabhat31 avatar Aug 25 '23 17:08 rabhat31

I see, you cannot do that anymore. Instead, create the new list instance and then "swap" the old instance with the new instance.

michalvasko avatar Sep 04 '23 07:09 michalvasko