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

"Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com> Wed, 28 March 2018 16:11 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 9AE5B127599 for <netmod@ietfa.amsl.com>; Wed, 28 Mar 2018 09:11:53 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.9
X-Spam-Level:
X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, 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 B38sRvu8xQ1G for <netmod@ietfa.amsl.com>; Wed, 28 Mar 2018 09:11:51 -0700 (PDT)
Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02on0710.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe05::710]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 37CB21243F6 for <netmod@ietf.org>; Wed, 28 Mar 2018 09:11:50 -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=ITJxT2diEPst+jIn31XR+b7+XntEUVQIO7N9IrRcV1I=; b=YS5+wVOWOuAHZgCI5PIn5b7lsNax+ey6W2wi9OukGDJEBnPnu9qq6/EpJBaly9ova1dzaDvR1cXKmfFz6RCtLdROAc39c99F0qrwmbKajSSbmKCoSuClnMzmejX2G60zGF8qctihWwJrQYT09np8m08Kdh8+JqXZqMOaMHp7+vQ=
Received: from AM3PR07MB1124.eurprd07.prod.outlook.com (10.163.187.158) by AM3PR07MB0630.eurprd07.prod.outlook.com (10.160.3.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.11; Wed, 28 Mar 2018 16:11:45 +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 16:11:45 +0000
From: "Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com>
To: Alex Campbell <Alex.Campbell@Aviatnet.com>, "netmod@ietf.org" <netmod@ietf.org>
Thread-Topic: YANG 'must' Xpaths, predicates and wildcards
Thread-Index: AdPGKRar8qf0qVjUQtmgVwXGx31jZQACPNCkABzr32A=
Date: Wed, 28 Mar 2018 16:11:45 +0000
Message-ID: <AM3PR07MB112427002EE13423DDA8A6E49BA30@AM3PR07MB1124.eurprd07.prod.outlook.com>
References: <AM3PR07MB112461BED4C88FDC4343C4F39BA30@AM3PR07MB1124.eurprd07.prod.outlook.com> <1522202212651.39558@Aviatnet.com>
In-Reply-To: <1522202212651.39558@Aviatnet.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: spf=none (sender IP is ) smtp.mailfrom=jason.sterne@nokia.com;
x-originating-ip: [135.245.20.13]
x-ms-publictraffictype: Email
x-microsoft-exchange-diagnostics: 1; AM3PR07MB0630; 7:y5yhlTWgxlk60NfAaOSv2zrMGyEIfzRLBn+G92Jbs0UmgULnLBJzAUYmH221XR7LbZIqQyTeX+XawIKUsYbHLH98ldiWwIRF2lG7RZ4vf7dg6CFut83fqdwYEqQG1F2Ss/kGFLZSA66ANjEYXZfO2yF8WqnLDlE6gJ6j7vET8CftIvnlEUx8SMe8T3ptpynemoFI3yVZ+EjDbwlW5W7Zc0lQK/WktryFu0h4cXn4IZkRs6gj5k4N8IIlLIUyCcPR
x-ms-exchange-antispam-srfa-diagnostics: SOS;
x-ms-office365-filtering-ht: Tenant
x-ms-office365-filtering-correlation-id: 64fd3683-e45b-477c-4a4f-08d594c69a69
x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:AM3PR07MB0630;
x-ms-traffictypediagnostic: AM3PR07MB0630:
x-microsoft-antispam-prvs: <AM3PR07MB0630864C4FAD9877EE7D9D919BA30@AM3PR07MB0630.eurprd07.prod.outlook.com>
x-exchange-antispam-report-test: UriScan:(28532068793085)(82608151540597)(788757137089)(21748063052155);
x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231221)(11241501184)(806099)(944501327)(52105095)(93006095)(93001095)(6055026)(6041310)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM3PR07MB0630; BCL:0; PCL:0; RULEID:; SRVR:AM3PR07MB0630;
x-forefront-prvs: 06259BA5A2
x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39380400002)(39860400002)(396003)(366004)(376002)(346002)(199004)(189003)(53754006)(3846002)(790700001)(66066001)(486005)(486005)(476003)(6246003)(68736007)(478600001)(33656002)(102836004)(186003)(2900100001)(14454004)(26005)(53546011)(6506007)(6116002)(5660300001)(106356001)(5250100002)(11346002)(446003)(110136005)(316002)(2501003)(55016002)(7736002)(99286004)(6436002)(97736004)(3280700002)(3660700001)(74316002)(8676002)(9686003)(229853002)(236005)(54896002)(105586002)(53936002)(6306002)(86362001)(8936002)(2906002)(25786009)(76176011)(81156014)(81166006)(7696005); DIR:OUT; SFP:1102; SCL:1; SRVR:AM3PR07MB0630; 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)
x-microsoft-antispam-message-info: LZiwpkK8O3sm6SU0chajez8VmVofbdexQHyrdAssGJk0rN2AMlVLA5cnnXCY0pORTlekBabut8+DsH4t8Sv8ZpTf6WxcbzEpexPuI/zxF47b56BNJRebhLibK3SnDWyLnjgFWEi2uJc20Sm7YzYT1/bjQNb3LJobFNHMpats29RK8uyGa9dticc/6AQss0z+X58JQFRq0FVYY9FzpW7xA11tp5ne2fyklgz+D78zoYpFWql9mCy1S8dvX45u/hV23ADJFAwLhKDX8UXqpo8rTl1qNNtrSfjnZ/VXFp+W84rsw0xeFb1C7TX0ALC0tcvqkHiKpebqsrehSXnX3rVuBgxTpzaSTiBsuB2rE+LR4ShCVpAF6n8ECMiYDgcuoCFx
spamdiagnosticoutput: 1:99
spamdiagnosticmetadata: NSPM
Content-Type: multipart/alternative; boundary="_000_AM3PR07MB112427002EE13423DDA8A6E49BA30AM3PR07MB1124eurp_"
MIME-Version: 1.0
X-OriginatorOrg: nokia.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 64fd3683-e45b-477c-4a4f-08d594c69a69
X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Mar 2018 16:11:45.7507 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR07MB0630
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/4ZamyKbfVNX_EUM2mxTMI6oDmJY>
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 16:11:53 -0000

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=*]";

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.

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