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

Leaf-list does not seem to work as RPC input #17

Open
mattiaswal opened this issue Dec 16, 2024 · 5 comments
Open

Leaf-list does not seem to work as RPC input #17

mattiaswal opened this issue Dec 16, 2024 · 5 comments

Comments

@mattiaswal
Copy link
Contributor

curl -k -u admin:admin      -H "Content-Type: application/yang-data+json"      -X POST      --data '{                                                         
        "infix-system:input": {                                                                                                                               
           "parameters": [                                                                                                                                    
             "primary",                                                                                                                                       
             "secondary"                                                                                                                                      
           ]                                                                                                                                                  
       }                                                                                                                                                      
     }'   https://localhost:443/restconf/operations/infix-system:set-boot-order   
 

Where the RPC is defined in:

     rpc set-boot-order {
    description
      "Set order of boot-partions";
    input {
      leaf-list parameters {
        type string;
      }
    }

Am I doing anything wrong here? When looking at the RFC it looks like it is correct.

@jktjkt
Copy link
Contributor

jktjkt commented Dec 16, 2024

This looks good. Before I start reproducing this locally, what is the error message that you're getting and what is the expected behavior?

@mattiaswal
Copy link
Contributor Author

{
  "ietf-restconf:errors": {
    "error": [
      {
        "error-type": "application",
        "error-tag": "operation-failed",
        "error-message": "Validation failed. Invalid input data."
      }
    ]
  }
}

Expected behavior: To be able to set a sorted leaf-list, that will be handled for the callback to work on.

@mattiaswal
Copy link
Contributor Author

mattiaswal commented Dec 17, 2024

I succeeded to call the RPC using sysrepo, but RESTCONF still fails.

admin@ix-00-00-00:~$ sysrepocfg -f json -R
{
  "infix-system:set-boot-order": {
      "boot-order": [
        "primary"
      ]
    }
}

admin@ix-00-00-00:~$ 
admin@ix-00-00-00:~$  curl -k -u admin:admin      -H "Content-Type: application/yang-data+json"      -X POST      --data '{                                                       
  "infix-system:input": {
           "boot-order": [
             "primary",
             "secondary"
           ]
       }
}'   https://localhost:443/restconf/operations/infix-system:set-boot-order

{
  "ietf-restconf:errors": {
    "error": [
      {
        "error-type": "protocol",
        "error-tag": "invalid-value",
        "error-message": "Validation failure: Can't parse into operation data tree: LY_EVALID"
      }
    ]
  }
}

@jktjkt
Copy link
Contributor

jktjkt commented Dec 18, 2024

I tried to reproduce this with the latest devel of everything upstream (which means also these four sysrepo-cpp patches 1 2 3 4 and a patch to rousette due to a change in error reporting format in sysrepo). In order to reproduce, I used this patch for the test suite:

diff --git a/tests/restconf-rpc.cpp b/tests/restconf-rpc.cpp
index c4229a0..68a5d33 100644
--- a/tests/restconf-rpc.cpp
+++ b/tests/restconf-rpc.cpp
@@ -123,6 +123,15 @@ TEST_CASE("invoking actions and rpcs")
 
             REQUIRE_CALL(rpcCall, rpcCall("/example:test-rpc-no-input-no-output", std::map<std::string, std::string>({})));
             REQUIRE(post(RESTCONF_OPER_ROOT "/example:test-rpc-no-input-no-output", {AUTH_ROOT, CONTENT_TYPE_JSON}, "") == Response{204, noContentTypeHeaders, ""});
+
+            REQUIRE_CALL(rpcCall, rpcCall("/example:test-rpc", std::map<std::string, std::string>({{"/example:test-rpc/i", "ahoj"}, {"/example:test-rpc/ll[1]", "a"}, {"/example:test-rpc/ll[2]", "b"}})));
+            REQUIRE(post(RESTCONF_OPER_ROOT "/example:test-rpc", {AUTH_ROOT, CONTENT_TYPE_JSON}, R"({"example:input": {"i":"ahoj", "ll": ["a", "b"]}}")") == Response{200, jsonHeaders, R"({
+  "example:output": {
+    "out1": "some-output-string",
+    "out2": "some-output-string-2"
+  }
+}
+)"});
         }
 
         SECTION("Data format")
diff --git a/tests/yang/example.yang b/tests/yang/example.yang
index 5d586a0..43ca82b 100644
--- a/tests/yang/example.yang
+++ b/tests/yang/example.yang
@@ -172,6 +172,9 @@ module example {
         type string;
         mandatory true;
       }
+      leaf-list ll {
+        type string;
+      }
     }
     output {
       leaf out1 { type string; }

...and everything worked just fine.

Could you please check whether this still happens with the following commits:

Note that there are some big changes in how the operational DS is implemented in these versions (which will become a release shortly).

@mattiaswal
Copy link
Contributor Author

I can confirm that it works, we can close this issue.

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