Re: [netmod] YANG 'must' Xpaths, predicates and wildcards

Martin Bjorklund <mbj@tail-f.com> Wed, 28 March 2018 17:50 UTC

Return-Path: <mbj@tail-f.com>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 4F9261270B4 for <netmod@ietfa.amsl.com>; Wed, 28 Mar 2018 10:50:57 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.911
X-Spam-Level:
X-Spam-Status: No, score=-1.911 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zt4Bud74jaAs for <netmod@ietfa.amsl.com>; Wed, 28 Mar 2018 10:50:55 -0700 (PDT)
Received: from mail.tail-f.com (mail.tail-f.com [46.21.102.45]) by ietfa.amsl.com (Postfix) with ESMTP id 1E82B126C89 for <netmod@ietf.org>; Wed, 28 Mar 2018 10:50:55 -0700 (PDT)
Received: from localhost (h-80-27.A165.priv.bahnhof.se [212.85.80.27]) by mail.tail-f.com (Postfix) with ESMTPSA id 648DB1AE00A0; Wed, 28 Mar 2018 19:50:54 +0200 (CEST)
Date: Wed, 28 Mar 2018 19:50:54 +0200
Message-Id: <20180328.195054.808825470516981841.mbj@tail-f.com>
To: jason.sterne@nokia.com
Cc: Alex.Campbell@Aviatnet.com, netmod@ietf.org
From: Martin Bjorklund <mbj@tail-f.com>
In-Reply-To: <AM3PR07MB1124FCFC799ED0E079F19B0E9BA30@AM3PR07MB1124.eurprd07.prod.outlook.com>
References: <AM3PR07MB112427002EE13423DDA8A6E49BA30@AM3PR07MB1124.eurprd07.prod.outlook.com> <20180328.192750.259736782775438140.mbj@tail-f.com> <AM3PR07MB1124FCFC799ED0E079F19B0E9BA30@AM3PR07MB1124.eurprd07.prod.outlook.com>
X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO)
Mime-Version: 1.0
Content-Type: Text/Plain; charset="utf-8"
Content-Transfer-Encoding: base64
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/nu6nLA4lhCB1OUw5cTvH-0ckhvU>
Subject: Re: [netmod] YANG 'must' Xpaths, predicates and wildcards
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.22
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 28 Mar 2018 17:50:57 -0000

"Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com> wrote:
> Thx.  In the case I'm most concerned about, a-list (and all
> descendants) is config true and 'entry' is the key leaf.

No need to check for a key's existance!

> So all
> a-list entries have a node called 'entry' by definition.
> 
> (I'm regretting using the name 'entry' for my key now in this example 😊
> 
> In this case it seems all the following result in the equivalent behavior (checking that a-list has at least one entry):
> 	must "../a-list";
> 	must "../a-list[entry=*]";
> 	must "../a-list[entry]";  <- this confuses me but I'll take your word for it
> 	must "../a-list/entry";
> 	must "../a-list[entry=*]/entry";
> 	must "../a-list[entry]/entry";  <- not sure about this one

Yes.  As would:

    must "../a-list[1=1]/entry";
    must "../a-list[count(*) > 0]/entry";

etc; if you want to have a confusing expression instead of the simple:

    must "../a-list";


/martin



> 
> Rgds,
> Jason
> 
> > -----Original Message-----
> > From: Martin Bjorklund [mailto:mbj@tail-f.com]
> > Sent: Wednesday, March 28, 2018 1:28 PM
> > To: Sterne, Jason (Nokia - CA/Ottawa) <jason.sterne@nokia.com>
> > Cc: Alex.Campbell@Aviatnet.com; netmod@ietf.org
> > Subject: Re: [netmod] YANG 'must' Xpaths, predicates and wildcards
> > 
> > "Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com> 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:Alex.Campbell@Aviatnet.com]
> > > Sent: Tuesday, March 27, 2018 9:57 PM
> > > To: Sterne, Jason (Nokia - CA/Ottawa) <jason.sterne@nokia.com>;
> > > netmod@ietf..org
> > > 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 <netmod-bounces@ietf.org<mailto:netmod-
> > bounces@ietf.org>>
> > > on behalf of Sterne, Jason (Nokia - CA/Ottawa)
> > > <jason.sterne@nokia.com<mailto:jason.sterne@nokia.com>>
> > > Sent: Wednesday, 28 March 2018 1:10 p.m.
> > > To: netmod@ietf.org<mailto:netmod@ietf.org>
> > > 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