"Sterne, Jason (Nokia - CA/Ottawa)" <[email protected]> wrote:
> Thanks Alex. Sorry about those sloppy mistakes. I agree about the
> ../a-list and I should have said count > 0.
>
> In the 2nd part of my email, my intention was to only allow foo to be
> configured if a-list has at least one entry configured. So I don't
> think min-elements 1 would work. I don't want to always require an
> entry in a-list. I only want to require one if foo is configured.
>
> I guess this also achieves the same thing right ?
> must "../a-list[entry=*]";
Yes, if all a-list entries has a node called "entry". But if that't
what you want, do:
must "../a-list[entry]";
> If foo has a default value, then does that mean the "must" is
> evaluated even if foo is deleted from the config ?
> leaf foo {
> must "../a-list"; <- always evaluated because of default ?
> type uint16;
> default 5;
> }
> If the must is always evaluated then it would be the equivalent of
> having min-elements 1 in a-list.
Correct.
/martin
>
> Rgds,
> Jason
>
> From: Alex Campbell [mailto:[email protected]]
> Sent: Tuesday, March 27, 2018 9:57 PM
> To: Sterne, Jason (Nokia - CA/Ottawa) <[email protected]>;
> [email protected]
> Subject: Re: YANG 'must' Xpaths, predicates and wildcards
>
>
> Hi,
>
>
>
> For one thing, it should be ../a-list since a-list is not a child of
> foo.
>
> Also - if foo is not configured and has no default value, then any
> must expressions in foo are not evaluated because it is not part of
> the "accessible tree". (I tested this in ConfD)
>
> Apart from these issues, yes it will behave as you expect - it will
> fail if a-list contains no entries.
>
>
>
> must "count(a-list) > 1"; is not equivalent since it requires at least
> two entries.
>
>
>
> However, you can more simply add a min-elements 1; statement to a-list
> to achieve the same goal - no XPath required.
>
>
>
> ________________________________
> From: netmod <[email protected]<mailto:[email protected]>>
> on behalf of Sterne, Jason (Nokia - CA/Ottawa)
> <[email protected]<mailto:[email protected]>>
> Sent: Wednesday, 28 March 2018 1:10 p.m.
> To: [email protected]<mailto:[email protected]>
> Subject: [netmod] YANG 'must' Xpaths, predicates and wildcards
>
> Hi all,
>
> I'm pretty sure that this xpath (e.g. in a must statement) isn't
> correct:
>
> (A) ../container-a/list-b[name=*]/some-leaf
>
> and should just be this instead:
>
> (B) ../container-a/list-b/some-leaf
>
> Or is the * an allowable wildcard for a key value in a predicate ?
>
> I also had a question about whether the following "must" correctly
> checks that at least one entry exists in a-list.
>
> container c1 {
> leaf foo {
> must "a-list";
> type uint16;
> }
> list a-list {
> key "entry";
> leaf entry {
> type uint16;
> }
> leaf another-entry {
> type uint32;
> }
> }
> }
>
> I think I could also replace that must with the following:
> must "count(a-list) > 1";
> but does must "a-list"; achieve the same thing ?
>
> Rgds,
> Jason
_______________________________________________
netmod mailing list
[email protected]
https://www.ietf.org/mailman/listinfo/netmod