CESNET / netopeer2

NETCONF toolset
BSD 3-Clause "New" or "Revised" License
290 stars 186 forks source link

Issues when committing configurations that contains unions of leafrefs #1560

Closed martin-olivier closed 2 months ago

martin-olivier commented 2 months ago

Hello,

I encountered issues when committing configurations that contains a leaf of type union of multiple leafrefs.

Here is a basic configuration where the bug can be reproduced:

module lr-test {
    yang-version  1.1;
    namespace  "urn:test:lr/test";
    prefix lr-test;
    organization
        "test";
    contact
        "test support - <support@test.com>";
    description
        "test.";

    grouping abcd {
        description
            "abcd.";

        list a {
            key "name";
            description
                "a.";
            leaf name {
                type int64;
                description
                    "a.";
            }
        }

        list b {
            key "name";
            description
                "b.";
            leaf name {
                type int64;
                description
                    "b.";
            }
        }

        list community {
            key "name";
            description
                "community.";
            leaf name {
                type string;
                description
                    "The name of the community.";
            }
            leaf view {
                type union {
                    type leafref {
                        path
                            "../../a/name";
                    }
                    type leafref {
                        path
                            "../../b/name";
                    }
                }
                description
                    "view.";
            }
        }
    }

    container test {
        description "test";
        uses abcd;
    }
}
  1. Load the yang file
sysrepocfg -i ./lr-test.yang
  1. Edit the running configuration in netopeer2-cli with the following xml:
<test xmlns="urn:test:lr/test">
        <b><name>123</name></b>
        <community>
                <name>test</name>
                <view>123</view>
        </community>
</test>
root@vm: netopeer2-cli
> connect
> edit-config --target running --config=rpc.xml --defop replace
ERROR
        type:     protocol
        tag:      data-missing
        severity: error
        app-tag:  instance-required
        path:     /lr-test:test/community[name='test']/view
        message:  Required leafref target with value "123" missing.

⚠️ It should not fail since b/name has been setup

A strange thing is that if I do the same operation, but this time by setting a/name instead of b/name, It works fine:

<test xmlns="urn:test:lr/test">
        <a><name>123</name></a>
        <community>
                <name>test</name>
                <view>123</view>
        </community>
</test>
root@vm: netopeer2-cli
> connect
> edit-config --target running --config=rpc.xml --defop replace
OK

Versions used:

netopeer2 v2.2.14 libyang v2.1.154

michalvasko commented 2 months ago

Please use the latest devel libyang, should be fixed, tests included.

martin-olivier commented 2 months ago

Hello @michalvasko

In the meantime, I have also tested with the latest devel libyang, and the bug was still happening

michalvasko commented 2 months ago

Yes, I have just committed a fix but referenced it incorrectly.

martin-olivier commented 2 months ago

Hello @michalvasko,

Thank you for your bugfix, it's working well now.

Have a nice day!