clicon / clixon

YANG-based toolchain including NETCONF and RESTCONF interfaces and an interactive CLI
http://www.clicon.org/
Other
215 stars 72 forks source link

restconf patch method adds redundant namespaces #235

Closed houtian124999 closed 3 years ago

houtian124999 commented 3 years ago

hi olof here is an bug with restcon patch method my yang is:

[root@localhost modules]# cat example-main.yang 
module example-main {
    yang-version 1.1;
    namespace "http://example-main";
    prefix example-main;

    description
        "TOMO";

    revision "2021-02-12" {
        description
        "";
    }

    import example { prefix example; }

    include example-main-augment;
}
[root@localhost modules]# cat example.yang 
module example {
    yang-version 1.1;
    namespace "http://example";
    prefix example;

    description
        "TOMO";

    revision "2021-02-12" {
        description
        "";
    }

    container a {
        leaf b {
            type string;
        }
    }
}
[root@localhost modules]# cat ../lib/example-main-augment.yang 
submodule example-main-augment {
    belongs-to "example-main" {
        prefix "example-main-augment";
    }

    import example { prefix example; }

    augment "/example:a" {
        leaf c {
            type boolean;
            default false;
            description "test";
        }
    }
}

startup_db is

<configuration>
   <a xmlns="http://example">
      <b>aa</b>
   </a>

running_db is

[root@localhost mgmt]# head -n 5 running_db 
<configuration>
   <a xmlns="http://example">
      <b>aa</b>
      <example-main:c xmlns:example-main="http://example-main">false</example-main:c>
   </a>

BUG: each patch adds a new xmlns

[root@localhost mgmt]# curl -X PATCH -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a -d '{"example:a":{"example-main:c":true}}'
[root@localhost mgmt]# head -n 5 running_db
<configuration>
   <a xmlns="http://example">
      <b>aa</b>
      <example-main:c xmlns:example-main="http://example-main" xmlns="http://example-main">true</example-main:c>
   </a>
[root@localhost mgmt]# curl -X PATCH -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a -d '{"example:a":{"example-main:c":true}}'
[root@localhost mgmt]# head -n 5 running_db
<configuration>
   <a xmlns="http://example">
      <b>aa</b>
      <example-main:c xmlns:example-main="http://example-main" xmlns="http://example-main" xmlns="http://example-main">true</example-main:c>
   </a>
[root@localhost mgmt]# curl -X PATCH -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a -d '{"example:a":{"example-main:c":true}}'
[root@localhost mgmt]# head -n 5 running_db
<configuration>
   <a xmlns="http://example">
      <b>aa</b>
      <example-main:c xmlns:example-main="http://example-main" xmlns="http://example-main" xmlns="http://example-main" xmlns="http://example-main">true</example-main:c>
   </a>
[root@localhost mgmt]# curl -X PATCH -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a -d '{"example:a":{"example-main:c":true}}'
[root@localhost mgmt]# head -n 5 running_db
<configuration>
   <a xmlns="http://example">
      <b>aa</b>
      <example-main:c xmlns:example-main="http://example-main" xmlns="http://example-main" xmlns="http://example-main" xmlns="http://example-main" xmlns="http://example-main">true</example-main:c>
   </a>