Subject: [yang-doctors] YANG must statement constraints

From: "Acee Lindem (acee)" <[email-masked]>
Date: Fri, 19 Mar 2021 14:25:26 +0000

When the constraint references a non-key leaf in a list, do all members of the list have to satisfy the constraint or only one of the list entries?

Thanks,
Acee

---

From: Ladislav Lhotka <[email-masked]>
Date: Fri, 19 Mar 2021 16:08:25 +0100

Hi Acee,

On 19. 03. 21 15:25, Acee Lindem (acee) wrote:
> When the constraint references a non-key leaf in a list, do all members
> of the list have to satisfy the constraint or only one of the list entries?

It depends on how the constraint is written.

If you have e.g.

    must "list/non-key-leaf = 42";

then it is sufficient that at least one instance on non-key-leaf exist
with that value. In contrast,

    must "not(list/non-key-leaf != 42)";

requires all instances to have that value.

Lada

> 
>  
> 
> Thanks,
> Acee
> 
> 
> _______________________________________________
> yang-doctors mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/yang-doctors
> 

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

---

From: "Acee Lindem (acee)" <[email-masked]>
Date: Fri, 19 Mar 2021 15:17:52 +0000

Hi Lada, 

I guess the corollary would be that: 

   must "list/non-key-leaf != 42";

Is satisfied if there is at least one list entry with a non-key-leaf other than 42.

And,

     must not("list/non-key-leaf = 42)";

Requires all leaf entries to have non-key-leaf not equal to 42. 

What if non-key-leaf is optional and not specified? Would this be equivalent to "!= 42" in the constraint evaluation?

Thanks much, 
Acee

On 3/19/21, 11:08 AM, "Ladislav Lhotka" <[email-masked]> wrote:

    Hi Acee,

    If you have e.g.

    Lada

---

From: Ladislav Lhotka <[email-masked]>
Date: Fri, 19 Mar 2021 16:39:30 +0100

> Is satisfied if there is at least one list entry with a non-key-leaf other than 42.

Yes.

> Requires all leaf entries to have non-key-leaf not equal to 42.

Yes.

> What if non-key-leaf is optional and not specified? Would this be equivalent to "!= 42" in the constraint evaluation?

This is another tricky point of XPath. Either of the conditions "= 42"
and "!= 42" is satisfied only if an instance exists and satisfies the
condition. In other words, if no instance exists, then neither of the
two conditions is true.

Lada

---

From: "Acee Lindem (acee)" <[email-masked]>
Date: Mon, 22 Mar 2021 13:44:46 +0000

Hi Lada, at 

One more thing to confirm (at least for now). A predicate for a list can reference non-key items in that list - right? For example:

       list foo {
              key "key";
              string key;
              string non-key;
       }

This is still valid - correct? 

    /some/xpath/foo[non-key="acee"]

Thanks,
Acee

On 3/19/21, 11:40 AM, "Ladislav Lhotka" <[email-masked]> wrote:

    Yes.

    Yes.

    Lada

---

From: Ladislav Lhotka <[email-masked]>
Date: Mon, 22 Mar 2021 17:44:05 +0100

>     /some/xpath/foo[non-key="acee"]

Yes, no problem. Lada