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

"Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com> Wed, 28 March 2018 17:46 UTC

Return-Path: <jason.sterne@nokia.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 10A04126DED for <netmod@ietfa.amsl.com>; Wed, 28 Mar 2018 10:46:44 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.901
X-Spam-Level:
X-Spam-Status: No, score=-1.901 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=nokia.onmicrosoft.com
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 Em-q_lyncjBJ for <netmod@ietfa.amsl.com>; Wed, 28 Mar 2018 10:46:41 -0700 (PDT)
Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30139.outbound.protection.outlook.com [40.107.3.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 947AC1243F3 for <netmod@ietf.org>; Wed, 28 Mar 2018 10:46:40 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=IzCeiJYaZn71pJUGZmU1XyV2ZtmqfzzUAXpF1gwx5I8=; b=sZH19OSUU2eVCsSU8eamAz3nYpYuUJ4CPfxvlExTjzuQmCNSyjpBxufL88RwSjB2Zk+SYuo/CDYUiOvCVwbiPP3GCqXKzyeF+rgzhInEefUZF4NHITt3+JGrw9aHnyPqzobLsMj+acK+gk0/hS9+AbjcZS13x6Hbq7XoKm+XGA8=
Received: from AM3PR07MB1124.eurprd07.prod.outlook.com (10.163.187.158) by AM3PR07MB337.eurprd07.prod.outlook.com (10.242.109.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.5; Wed, 28 Mar 2018 17:46:37 +0000
Received: from AM3PR07MB1124.eurprd07.prod.outlook.com ([fe80::c88d:cbe7:1cfc:7399]) by AM3PR07MB1124.eurprd07.prod.outlook.com ([fe80::c88d:cbe7:1cfc:7399%4]) with mapi id 15.20.0631.009; Wed, 28 Mar 2018 17:46:37 +0000
From: "Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com>
To: Martin Bjorklund <mbj@tail-f.com>
CC: "Alex.Campbell@Aviatnet.com" <Alex.Campbell@Aviatnet.com>, "netmod@ietf.org" <netmod@ietf.org>
Thread-Topic: [netmod] YANG 'must' Xpaths, predicates and wildcards
Thread-Index: AdPGKRar8qf0qVjUQtmgVwXGx31jZQACPNCkABzr32AABRfBAAAAbAMA
Date: Wed, 28 Mar 2018 17:46:37 +0000
Message-ID: <AM3PR07MB1124FCFC799ED0E079F19B0E9BA30@AM3PR07MB1124.eurprd07.prod.outlook.com>
References: <AM3PR07MB112461BED4C88FDC4343C4F39BA30@AM3PR07MB1124.eurprd07.prod.outlook.com> <1522202212651.39558@Aviatnet.com> <AM3PR07MB112427002EE13423DDA8A6E49BA30@AM3PR07MB1124.eurprd07.prod.outlook.com> <20180328.192750.259736782775438140.mbj@tail-f.com>
In-Reply-To: <20180328.192750.259736782775438140.mbj@tail-f.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-originating-ip: [135.245.20.13]
x-ms-publictraffictype: Email
x-microsoft-exchange-diagnostics: 1; AM3PR07MB337; 7:c4+UZNWM0pmnia3Y5JUWaxOTDXpledpGZrby4U2WmmcTSjeZFe6YDOuU0JPyQViH/2B3Nsv8AI/r0fRvGyayVgF7hUsyAa6EZcbIAa7A5xRHFbYAsMiiNJuzMKNXf79i/A+B5pKJezUDXVok3h5T661k9eSlaxHR5sEmmfAwYiUiDVhsvCbi628Q4l6rSPCn5KdYsrPI4viQMlMiM84eOfieEc2ufvenWFZ+1BdC3Lc1OyUTFgN6QEVfbxah3GLn
x-ms-exchange-antispam-srfa-diagnostics: SOS;
x-ms-office365-filtering-ht: Tenant
x-ms-office365-filtering-correlation-id: fd19d572-b1fe-4ca9-2463-08d594d3db03
x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:AM3PR07MB337;
x-ms-traffictypediagnostic: AM3PR07MB337:
x-microsoft-antispam-prvs: <AM3PR07MB3379DF5D9B5BF85A24100DF9BA30@AM3PR07MB337.eurprd07.prod.outlook.com>
x-exchange-antispam-report-test: UriScan:(82608151540597)(788757137089);
x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231221)(11241501184)(806099)(944501327)(52105095)(6055026)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:AM3PR07MB337; BCL:0; PCL:0; RULEID:; SRVR:AM3PR07MB337;
x-forefront-prvs: 06259BA5A2
x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39380400002)(376002)(39860400002)(396003)(346002)(366004)(199004)(189003)(53754006)(13464003)(486005)(93886005)(2900100001)(99286004)(14454004)(54906003)(97736004)(76176011)(6346003)(446003)(316002)(11346002)(7696005)(486005)(26005)(102836004)(68736007)(86362001)(478600001)(53546011)(6506007)(186003)(4326008)(33656002)(55016002)(2906002)(106356001)(81156014)(53936002)(6436002)(9686003)(105586002)(74316002)(3280700002)(3660700001)(81166006)(305945005)(8676002)(6916009)(66066001)(7736002)(3846002)(5250100002)(6116002)(6246003)(476003)(229853002)(25786009)(5660300001)(8936002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM3PR07MB337; H:AM3PR07MB1124.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1;
received-spf: None (protection.outlook.com: nokia.com does not designate permitted sender hosts)
authentication-results: spf=none (sender IP is ) smtp.mailfrom=jason.sterne@nokia.com;
x-microsoft-antispam-message-info: m3j8XzTDWysSwmXN5KNxBGUFTZJSNcGqOXCgaMX8bHFOyb+S8hAPmy8EJ+ChM5iqcK2T+7AVH9lIPBqbTyDH7Zgsx5q5BFa9Y6exHbhbbPeGMBauq/HWDNt4iPm4kGjAAFRHLj6NgkC18pvPi/0BssWZhccIwWLJzZwoE/ftSgpgUdqqzUgv+NRoLovC1awWdpMP0cDU8ppYtRYe3ePf31ZUoEVjf3oPUEDq2tCK0P9+av5oYMQoqBbWKUZ0bRIWUMeiW61tbJUF8HPPHvY1O7JEGJPlYhl9YVYHKVUxidfwBWCZdF6w6FZcu5zQ3eLsbPaYi6Arh2DAPKM+EYZTtclhH4RynddpmCGxQkPIKEC2pHp8dg074CBlP23noh5k
spamdiagnosticoutput: 1:99
spamdiagnosticmetadata: NSPM
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-OriginatorOrg: nokia.com
X-MS-Exchange-CrossTenant-Network-Message-Id: fd19d572-b1fe-4ca9-2463-08d594d3db03
X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Mar 2018 17:46:37.5750 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR07MB337
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/3yiLeV91HjKhlNK5QeQApzBzeuc>
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:46:44 -0000

Thx.  In the case I'm most concerned about, a-list (and all descendants) is config true and 'entry' is the key leaf.  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

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