Problem when commiting transaction with when and uses statement


I have a model like

 grouping vrf-export-config {
 description "Nexthop parameters for inter-as VPN options ";
 container vrf-export-policy {
     when "not (../static-vrf/config/static-vrf)";
     description "Nexthop related options for inter-as options";
     uses rpol:export-policy_config;      

As the default value for static-vrf is “false”
The strange part is , the confd_cli works fine , doesn’t throw any validation error.

But if I try to use the XML to configure , i face the validation error
/network-instances/network-instance[name=‘93500000017430898’]/vrf-export-policy: the ‘when’ expression “not (/ni:network-instances/ni:network-instance/static-vrf/config/static-vrf)” failed

Can anyone suggest any issue with above statements.

Well, it is difficult to comment when you haven’t included a single configurable node in your snippet, and don’t say anything about what it is that works in the CLI. But I can guess that you have a misunderstanding regarding XPath evaluation - it doesn’t know about YANG types, in particular not the significance of the values true and false for a YANG boolean.

The XPath expression not (../static-vrf/config/static-vrf) evaluates to true if the nodeset matching ../static-vrf/config/static-vrf is empty, i.e. (simplified) no static-vrf leafs exist. Since for the purpose of XPath evaluation in YANG, leafs with default are considered to “have” their default value if no value has been set, a leaf with a default value will always exist (if its ancestors exist). Thus the XPath expression will always evaluate to false.

I.e. your XML (NETCONF?) test seems to show that everything is working as designed (except that the error message doesn’t match your snippet), and when I try your snippet in the CLI, it is impossible to access the vrf-export-policy container, regardless of the value of the static-vrf leaf (as I expected).

You probably wanted the XPath expression to evaluate to true when the static-vrf leaf has the value false (whether from default or explicitly set). The way to express that in the when statement is:

   when "../static-vrf/config[static-vrf = 'false']";

Thanks Per for the suggestion and it works good.
For the error not matching, i was trying with different namespaces to solve the issue.
Next time i will be more descriptive, so it will be easy to answer the query. Thanks again…!!