Subject: [netmod] evaluating 'when' statements with unconfigured leafs

From: "Sterne, Jason (Nokia - CA/Ottawa)" <[email-masked]>
Date: Wed, 25 Sep 2019 15:37:21 +0000

Hi all,

I saw some recent questions about 'when' statements. I had another one related to evaluating 'when' statements that involve leafs that don't currently have a value at all.

leaf foo {
    type enumeration {
        enum val1;
        enum val2;
    }
}

leaf bar {
    when "../foo != 'val2'";
    type uint8;
}

Notice that foo does not have a default statement. So if no manager has set leaf foo, it doesn't exist in the config.

In that case, does the "when" statement evaluate to 'true'  (i.e. leaf bar is allowed to have a value) ?

i.e. assuming leaf foo is not set at all, is this accepted?
<bar>23</bar>

Or is there something special here because of the non-existence of leaf foo?

If the "when" evaluates to 'false', then does the following "when" evaluate differently than the one above?
    when "not(../foo = 'val2')";

Jason

---

From: Andy Bierman <[email-masked]>
Date: Wed, 25 Sep 2019 09:20:29 -0700

On Wed, Sep 25, 2019 at 8:37 AM Sterne, Jason (Nokia - CA/Ottawa) <
[email-masked]> wrote:

> Hi all,
>
>
>
> I saw some recent questions about 'when' statements. I had another one
> related to evaluating 'when' statements that involve leafs that don't
> currently have a value at all.
>
>
>
> leaf foo {
>
>     type enumeration {
>
>         enum val1;
>
>         enum val2;
>
>     }
>
> }
>
>
>
> leaf bar {
>
>     when "../foo != 'val2'";
>
>     type uint8;
>
> }
>
>
>
> Notice that foo does not have a default statement. So if no manager has
> set leaf foo, it doesn't exist in the config.
>
>
>

no

> Or is there something special here because of the non-existence of leaf

 correct.
An empty node-set does not always convert to am empty string.
So easy to tell XPath to do the wrong thing...

    when "../foo != 'val2'";

is not equivalent to

  when "string(../foo) != 'val2'";

If one object to be compared is a node-set and the other is a string, then
the comparison will be true if and only if there is a node in the node-set
such that the result of performing the comparison on the string-value
<https://www.w3.org/TR/1999/REC-xpath-19991116/#dt-string-value> of the
node and the other string is true.

Andy

If the "when" evaluates to 'false', then does the following "when" evaluate
> differently than the one above?
>
> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod
>

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 26 Sep 2019 09:02:42 +0200

>     when "not(../foo = 'val2')";

Indeed it does. If the "foo" instance doesn't exist, then this expression evaluates to true.

Lada

-- 
Ladislav Lhotka 
Head, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67