freeconf / yang

Standards-based management for Golang microservices
Apache License 2.0
38 stars 15 forks source link

XPath expressions in 'when' statement not using the correct context #112

Open eelcocramer opened 4 months ago

eelcocramer commented 4 months ago

I wanted to make this into a PR but cannot really find where this should be fixed. Any pointers that help me put this into a PR are appreciated!

I'm using the when statement in an action output:

output {
    leaf status {;
        type boolean;
        mandatory true;
    }
    leaf message {
        when "../status = 'false'";
        type string;
    }
}

According to yang linters the XPath ../status is correct but when I use this with freeconf I get an error in the restconf server's response: '..' not found in xpath

When I change the xpath query in the when statement to when "status = 'false'" the output of a restconf request is rendered correctly. However now the yang linters complain:

warning: node "component::status" is not found in "component::message"
dhubler commented 4 months ago

There's an xpath package and even a grammar file in yacc syntax that may or may not to the issue.

This is likely on the tougher side to look at, I can help if you cannot find it

On Sat, Jul 13, 2024, 5:20 AM Eelco @.***> wrote:

I wanted to make this into a PR but cannot really find where this should be fixed. Any pointers that help me put this into a PR are appreciated!

I'm using the when https://datatracker.ietf.org/doc/html/rfc7950#section-7.21.5 statement in an action output:

output { leaf status {; type boolean; mandatory true; } leaf message { when "../status = 'false'"; type string; } }

According to yang linters the XPath ../status is correct but when I use this with freeconf I get an error in the restconf servers response: '..' not found in xpath

When I change the xpath query in the when statement to when "status = 'false'" the output of a restconf request is rendered correctly. However now the yang linters complain:

warning: node "component::status" is not found in "component::message"

— Reply to this email directly, view it on GitHub https://github.com/freeconf/yang/issues/112, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACA7UOUWABPHOKGCGKF3TZMDWL3AVCNFSM6AAAAABK2DYA3KVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQYDMOBRGU3DMNQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

eelcocramer commented 4 months ago

An update.

I added a test case to reproduce this issue in my cloned repository. Test case can be found here.

The error is generated in the resolvePath function of xpath_impl. It can easily be fixed by changing the behaviour of meta.Find but I have the feeling that is not the correct way to fix this issue. I do believe the selection where resolvePath is called with, is not the right selection.

eelcocramer commented 4 months ago

I tried running the test with a debugger to see if I could understand how it works but I'm lost at the yacc stuff.

dhubler commented 4 months ago

If the error is in resolvePath then bug is not in yacc.

Does the xpath work in config tree (i.e. not in an output directive)?

On Tue, Jul 16, 2024 at 3:18 AM Eelco @.***> wrote:

I tried running the test with a debugger to see if I could understand how it works but I'm lost at the yacc stuff.

— Reply to this email directly, view it on GitHub https://github.com/freeconf/yang/issues/112#issuecomment-2230193590, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACA7RKW5ZXYJ3HCH34Z4LZMTCLRAVCNFSM6AAAAABK2DYA3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZQGE4TGNJZGA . You are receiving this because you commented.Message ID: @.***>

dhubler commented 4 months ago

Is "../status" incorrect? parent of output would not have the "status" field.

eelcocramer commented 4 months ago

But ../status refers to the parent of message and that does have the status field. Without the ../ (so when this library does work) pyang and other linters complain with a warning that the node status is not found in the node message.