Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restconf patch method unable to chage value to empty string #229

Closed
nowaits opened this issue May 24, 2021 · 6 comments
Closed

restconf patch method unable to chage value to empty string #229

nowaits opened this issue May 24, 2021 · 6 comments

Comments

@nowaits
Copy link
Contributor

nowaits commented May 24, 2021

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
Copy link
Member

Fixed by patch above. Please verify

@nowaits nowaits closed this as completed May 27, 2021
@nowaits nowaits reopened this May 29, 2021
@houtian124999
Copy link

houtian124999 commented May 29, 2021

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
Copy link
Member

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
Copy link

houtian124999 commented Jun 1, 2021

In my running_db, it's not

<b></b>

it's

<b/>

@houtian124999
Copy link

[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
Copy link
Contributor Author

nowaits commented Jun 15, 2021

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]$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants