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

Replace whole config #15

Closed
sdj38 opened this issue Feb 22, 2018 · 1 comment
Closed

Replace whole config #15

sdj38 opened this issue Feb 22, 2018 · 1 comment

Comments

@sdj38
Copy link

sdj38 commented Feb 22, 2018

Hi Olof,
While testing some of the new changes PUT the whole datastore in particular I noticed some cases it was not doing what it should. If there is already data in the datastore it is not being replaced but just being added to or modified. Here is an example

[root@localhost ~]# curl -X PUT -d '{ "data" : { "interfaces-config" : { "interface" : { "name" : "t1"}}}}' http://localhost/restconf/data
[root@localhost ~]# curl -G http://localhost/restconf/data
{
  "data": {
    "acl-config": {
      "acl-table": {
        "acl-list": [
          {
            "acl-name": "block https",
            "acl-rules": {
              "acl-rule": [
                {
                  "sequence": 20,
                  "action": "permit"
                }
              ]
            }
          }
        ]
      }
    },
    "interfaces-config": {
      "interface": [
        {
          "name": "t1"
        }
      ]
    }
  }
}
[root@localhost ~]# 

As you can see it adds interfaces-config onto the datastore instead of replacing the whole datastore. (which would remove all of acl-config )
Here is the RFC reference It should replace the whole datastore with whatever the data is. It seems if there is already data in the datastore it doesn't get replaced properly. I believe I ran into this error on other areas as well such as within just interfaces-config so /restconf/data/interfaces-config as the endpoint if I did a PUT with an interface already defined in the data store and wanted it replaced with a new interface so a different name than the one in the datastore it didn't get replaced with what I sent. I had to run a DELETE command first to get it to remove the interface and then it would let me do a PUT.

Thanks again for your help on this.

@olofhagsand
Copy link
Member

I have committed a patch for this in develop as shown below. The patch also supports DELETE of the whole datastore, although I cannot see if this is really allowed by the RFC. However, the "data" resource is not actually deleted, only its children.

diff --git a/datastore/text/clixon_xmldb_text.c b/datastore/text/clixon_xmldb_text.c
index 739e225..776de8d 100644
--- a/datastore/text/clixon_xmldb_text.c
+++ b/datastore/text/clixon_xmldb_text.c
@@ -781,6 +781,12 @@ text_modify_top(cxobj *x0,
break;
}
}

  • /* Special case top-level replace */
  • if (op == OP_REPLACE || op == OP_DELETE){
  •   x0c = NULL;
    
  •   while ((x0c = xml_child_each(x0, x0c, CX_ELMNT)) != NULL) 
    
  •       xml_purge(x0c);
    
  • }
    /* Loop through children of the modification tree */
    x1c = NULL;
    while ((x1c = xml_child_each(x1, x1c, CX_ELMNT)) != NULL) {

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

No branches or pull requests

2 participants