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 unable to chage value to empty string #229

Closed nowaits closed 3 years ago

nowaits commented 3 years ago

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

module example {
    yang-version 1.1;
    namespace "http://example";
    prefix ex;

    description
    "TOMO";

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

    container a {
        leaf b {
            type string;
        }
    }
}

startup_db is

<configuration>
   <a xmlns="http://example">
      <b>aa</b>
   </a>
   <restconf xmlns="http://clicon.org/restconf">
      <enable>true</enable>
      <auth-type>none</auth-type>
      <pretty>true</pretty>
      <fcgi-socket>/home/dev/code/net-base/dist/www/fastcgi_restconf.sock</fcgi-socket>
   </restconf>
</configuration>

and in cli

curl -X PATCH -H "Content-Type: application/yang-data+json" -d '{
    "example:a":{
        "b":""
    }
}' http://localhost/restconf/data/example:a

Curl has no error, but in runing_db, the value b unchanged.

olofhagsand commented 3 years ago

Fixed by patch above. Please verify

houtian124999 commented 3 years ago

Hi,olof ~ This is a similar bug with restconf

The same YANG file

startup_db is

<configuration>
   <a xmlns="http://example">
      <b/>
   </a>
   <restconf xmlns="http://clicon.org/restconf">
      <enable>true</enable>
      <auth-type>none</auth-type>
      <pretty>true</pretty>
      <fcgi-socket>/home/dev/code/net-base/dist/www/fastcgi_restconf.sock</fcgi-socket>
   </restconf>
</configuration>

and in cli

curl -X PATCH -H "Content-Type: application/yang-data+json" -d '{
    "example:a":{
        "b":"aa"
    }
}' http://localhost/restconf/data/example:a

Curl has no error, but in runing_db, the value b unchanged.

olofhagsand commented 3 years ago

I cannot recreate it. Please double-check, if it still remains, please add more info on how you triggered the error.

olof@alarik> curl -X GET -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a
{"example:a":{"b":""}}
olof@alarik> sudo cat /usr/local/var/example/running_db 
<config>
   <a xmlns="urn:example:clixon">
      <b></b>
   </a>
</config>
olof@alarik> curl -X PATCH -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a -d '{"example:a":{"b":"aa"}}' 
olof@alarik> curl -X GET -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a
{"example:a":{"b":"aa"}}
olof@alarik> sudo cat /usr/local/var/example/running_db 
<config>
   <a xmlns="urn:example:clixon">
      <b>aa</b>
   </a>
</config>
houtian124999 commented 3 years ago

In my running_db, it's not

<b></b>

it's

<b/>
houtian124999 commented 3 years ago

[root@localhost mgmt]# curl -X GET -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a

{
    "example:a": {
      "b": ""
    }
  }

[root@localhost mgmt]# head -n 4 running_db

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

[root@localhost mgmt]# curl -X PATCH -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a -d '{"example:a":{"b":"aa"}}' [root@localhost mgmt]# head -n 4 running_db

<configuration>
   <a xmlns="http://example">
      <b/>
   </a>
nowaits commented 3 years ago

hi olof, Issule with Changing value from empty to none empty still exist. Config is:

<configuration>
   <a xmlns="http://example">
      <b/>
   </a>
   <restconf xmlns="http://clicon.org/restconf">
      <enable>true</enable>
      <auth-type>none</auth-type>
      <pretty>true</pretty>
      <fcgi-socket>/home/dev/code/net-base/dist/www/fastcgi_restconf.sock</fcgi-socket>
   </restconf>
</configuration>

Below is the test output:

[dev@localhost net-base]$ sudo cat /home/dev/var/mgmt/running_db 
<configuration>
   <a xmlns="http://example">
      <b/>
   </a>
   <restconf xmlns="http://clicon.org/restconf">
      <enable>true</enable>
      <auth-type>none</auth-type>
      <pretty>true</pretty>
      <fcgi-socket>/home/dev/code/net-base/dist/www/fastcgi_restconf.sock</fcgi-socket>
   </restconf>
</configuration>
[dev@localhost net-base]$ curl -X GET -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a
{
    "example:a": {
      "b": ""
    }
  }
[dev@localhost net-base]$ curl -X PATCH -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a -d '{"example:a":{"b":"aa"}}' 
[dev@localhost net-base]$ curl -X GET -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:a
{
    "example:a": {
      "b": ""
    }
  }
[dev@localhost net-base]$ sudo cat /home/dev/var/mgmt/running_db <configuration>
   <a xmlns="http://example">
      <b/>
   </a>
   <restconf xmlns="http://clicon.org/restconf">
      <enable>true</enable>
      <auth-type>none</auth-type>
      <pretty>true</pretty>
      <fcgi-socket>/home/dev/code/net-base/dist/www/fastcgi_restconf.sock</fcgi-socket>
   </restconf>
</configuration>
[dev@localhost net-base]$