-
Notifications
You must be signed in to change notification settings - Fork 320
Description
This is related to #2475, but I thought it might be better to keep it clean as I think this might be a bug.
Im sorry but I dont do C, so I replicated it with the libyang-python module. Im sure this can easily be reproduced in C as I dont believe this is a problem within libyang-python.
Im using libyang 4.2.2 with the latest master version of libyang-python
the model Im using is this:
module leaf-list-test {
namespace "urn:test:leaf-list-test";
prefix llt;
container system {
leaf-list ordered-names {
type string;
ordered-by user;
}
}
}my code looks like this:
from libyang import Context
running_xml = """
<system xmlns="urn:test:leaf-list-test">
<ordered-names>alpha</ordered-names>
<ordered-names>bravo</ordered-names>
<ordered-names>charlie</ordered-names>
<ordered-names>delta</ordered-names>
<ordered-names>echo</ordered-names>
</system>
"""
intent_xml = """
<system xmlns="urn:test:leaf-list-test">
<ordered-names>new_alpha</ordered-names>
<ordered-names>bravo</ordered-names>
<ordered-names>charlie</ordered-names>
<ordered-names>echo</ordered-names>
<ordered-names>foxtrot</ordered-names>
</system>
"""
this_path = __file__.rsplit("/", 1)[0]
ctx = Context(this_path)
ctx.load_module("leaf-list-test")
running = ctx.parse_data_mem(running_xml, "xml", strict=True, no_state=True, validate_present=True)
intent = ctx.parse_data_mem(intent_xml, "xml", strict=True, no_state=True, validate_present=True)
diff = running.diff(intent)
print(running.print_mem("xml", pretty=True))
print(intent.print_mem("xml", pretty=True))
print(diff.print_mem("xml", pretty=True))When I run it, it gives me this output (print of running, intent and diff)
<system xmlns="urn:test:leaf-list-test">
<ordered-names>alpha</ordered-names>
<ordered-names>bravo</ordered-names>
<ordered-names>charlie</ordered-names>
<ordered-names>delta</ordered-names>
<ordered-names>echo</ordered-names>
</system>
<system xmlns="urn:test:leaf-list-test">
<ordered-names>new_alpha</ordered-names>
<ordered-names>bravo</ordered-names>
<ordered-names>charlie</ordered-names>
<ordered-names>echo</ordered-names>
<ordered-names>foxtrot</ordered-names>
</system>
<system xmlns="urn:test:leaf-list-test" xmlns:yang="urn:ietf:params:xml:ns:yang:1" yang:operation="none">
<ordered-names yang:operation="delete" yang:orig-value="">alpha</ordered-names>
<ordered-names yang:operation="delete" yang:orig-value="charlie">delta</ordered-names>
<ordered-names yang:operation="create" yang:value="">new_alpha</ordered-names>
<ordered-names yang:operation="create" yang:value="echo">foxtrot</ordered-names>
</system>I could obviously be wrong here, but from what I can deduct, then the yang:value is the internal placement in libyang. It would be the same as yang:insert="after" yang:value="whatever" The difference is that libyang has implicit yang:insert="after"and if its the first item in the list then yang:value=""
This is consistent of how it works on a list, but the problem I face is on a leaf-list then doing the yang:operation="delete" operation it uses the yang:orig-value="" or yang:orig-value="whatever"..
just to carve it out into wet cardboard, then this is what I get:
<system xmlns="urn:test:leaf-list-test" xmlns:yang="urn:ietf:params:xml:ns:yang:1" yang:operation="none">
<ordered-names yang:operation="delete" yang:orig-value="">alpha</ordered-names> <---------- Notice this is orig-value
<ordered-names yang:operation="delete" yang:orig-value="charlie">delta</ordered-names> <---------- Notice this is orig-value
<ordered-names yang:operation="create" yang:value="">new_alpha</ordered-names>
<ordered-names yang:operation="create" yang:value="echo">foxtrot</ordered-names>
</system>and this is what I expect:
<system xmlns="urn:test:leaf-list-test" xmlns:yang="urn:ietf:params:xml:ns:yang:1" yang:operation="none">
<ordered-names yang:operation="delete" yang:value="">alpha</ordered-names> <---------- Notice this is value now
<ordered-names yang:operation="delete" yang:value="charlie">delta</ordered-names> <---------- Notice this is value now
<ordered-names yang:operation="create" yang:value="">new_alpha</ordered-names>
<ordered-names yang:operation="create" yang:value="echo">foxtrot</ordered-names>
</system>When creating a new entry, it seems correct and as I said before the behaviour for list also seems to follow this approach (when deleting an item, it uses value="" if its index=0)
Hope it makes sense.
Esben