Re: [yang-doctors] Yang syntax for a globally-unique key?

Kent Watsen <kent@watsen.net> Thu, 27 August 2020 13:44 UTC

Return-Path: <010001743029e724-30b5c901-5cc7-45df-932e-871f1e932c21-000000@amazonses.watsen.net>
X-Original-To: yang-doctors@ietfa.amsl.com
Delivered-To: yang-doctors@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 17C1C3A09B3 for <yang-doctors@ietfa.amsl.com>; Thu, 27 Aug 2020 06:44:50 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.897
X-Spam-Level:
X-Spam-Status: No, score=-1.897 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=amazonses.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 LIQdzTdJBnVR for <yang-doctors@ietfa.amsl.com>; Thu, 27 Aug 2020 06:44:48 -0700 (PDT)
Received: from a48-93.smtp-out.amazonses.com (a48-93.smtp-out.amazonses.com [54.240.48.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2DAD93A097E for <yang-doctors@ietf.org>; Thu, 27 Aug 2020 06:44:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=224i4yxa5dv7c2xz3womw6peuasteono; d=amazonses.com; t=1598535887; h=From:Message-Id:Content-Type:Mime-Version:Subject:Date:In-Reply-To:Cc:To:References:Feedback-ID; bh=MmXC5OMlkX58RW7+wa0oA3iPx4E4q7x7Pqv8kyJIcoY=; b=fiWHt3SEM31Q3Wn3PVQauNyhVoncBlLX9FkPaY8flxmrWaFag1LLaU3dlHXgxoar x161KOVLwwiuhd8mN3/1r77P3RbvOSB9z0RL+T2LPh2YxseITjv7QJoETh5T1rmHUaw ziKLIVJZKBWTTLghfYBayxxGR8NGNXY9XxK4PPXc=
From: Kent Watsen <kent@watsen.net>
Message-ID: <010001743029e724-30b5c901-5cc7-45df-932e-871f1e932c21-000000@email.amazonses.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_697E9537-EEF7-4456-9917-A52A22264EAB"
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\))
Date: Thu, 27 Aug 2020 13:44:46 +0000
In-Reply-To: <87v9h4w7zl.fsf@nic.cz>
Cc: yang-doctors@ietf.org
To: Ladislav Lhotka <ladislav.lhotka@nic.cz>
References: <0100017425c983cb-d9471cc6-34d3-4a49-ab7b-942bca5ae697-000000@email.amazonses.com> <CABCOCHRhE9EqpgKKHpvkCWrmE4JkQN6i5kAF4EMfXF=GA1EVQg@mail.gmail.com> <df41a832-7ebd-9abf-f9e5-d0838797ded0@nic.cz> <CABCOCHS-1XuWGf8U6z=r+WnTh4zH2qfDhbTX2YaPN2fcZt1twg@mail.gmail.com> <06a32179-128a-99f0-b489-56985679964d@nic.cz> <1dab12ae-1f41-10ad-789c-17a38f344efe@nic.cz> <01000174272e7b3e-8c389f49-635c-450a-b74d-6c71a890882d-000000@email.amazonses.com> <87lfi1hnyv.fsf@nic.cz> <010001742fecf818-d7acbe40-b835-47a9-a88f-35eb4c8ef9a9-000000@email.amazonses.com> <87v9h4w7zl.fsf@nic.cz>
X-Mailer: Apple Mail (2.3608.80.23.2.2)
X-SES-Outgoing: 2020.08.27-54.240.48.93
Feedback-ID: 1.us-east-1.DKmIRZFhhsBhtmFMNikgwZUWVrODEw9qVcPhqJEI2DA=:AmazonSES
Archived-At: <https://mailarchive.ietf.org/arch/msg/yang-doctors/Jc7cfT8lPhyRhqiUQ8KQvfj-zbc>
Subject: Re: [yang-doctors] Yang syntax for a globally-unique key?
X-BeenThere: yang-doctors@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Email list of the yang-doctors directorate <yang-doctors.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/yang-doctors>, <mailto:yang-doctors-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/yang-doctors/>
List-Post: <mailto:yang-doctors@ietf.org>
List-Help: <mailto:yang-doctors-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/yang-doctors>, <mailto:yang-doctors-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 27 Aug 2020 13:44:50 -0000

>> Pyang validated the corrected expression above, but yanglint threw an error, as described by: https://github.com/CESNET/libyang/issues/1180 <https://github.com/CESNET/libyang/issues/1180>.
> 
> Yes, we discussed this with Michal previously. The fact that there is no specific prescribed order doesn't mean there is no order at all. XPath data model expects the siglings to be in a sequence.

Michael says that he’ll schedule it for near end-of-year, in yanglint 2.0 only.


>> I have not yet tested with Yangson.  Is it known if Yangson supports "preceding-sibling”?  Looking at https://yangson.labs.nic.cz/xpath.html <https://yangson.labs.nic.cz/xpath.html> I see this:
>> 
>>    NotSupported – if the input XPath expression contains a feature that
>>    isn’t supported by the implementation, such as the preceding:: axis.
> 
> Yangson does support it, see below. Of course, preceding:: axis really makes no sense with YANG-modelled data.

Oh, happy days  :)

To workaround the yanglint issue, I guess that code can dynamically add a new “must” expression to an instance of Yangson’s “SchemaNode” class here: https://yangson.labs.nic.cz/schemanode.html#yangson.schemanode.SchemaNode.must <https://yangson.labs.nic.cz/schemanode.html#yangson.schemanode.SchemaNode.must>.

K.

> Lada
> 
> (yangson) $ cat test.yang 
> module test {
>  yang-version 1.1;
>  namespace "https://example.net/test";
>  prefix "t";
> 
>  container tenants {
>    list tenant {
>      key key;
>      must "not(preceding-sibling::tenant[admins/admin/name = current()/admins/admin/name])";
>      leaf key {
>        type string;
>      }
>      container admins {
>        list admin {
>          key name;
>          leaf name {
>            type string;
>          }
>        }
>      }
>    }
>  }
> }
> 
> (yangson) $ cat ylib.json 
> {
>  "ietf-yang-library:modules-state": {
>    "module-set-id": "",
>    "module": [
>      {
>        "name": "test",
>        "revision": "",
>        "namespace": "https://example.net/test",
>        "conformance-type": "implement"
>      }
>    ]
>  }
> }
> (yangson) $ cat inst1.json 
> {
>    "test:tenants": {
> 	"tenant": [
> 	    {
> 		"key": "foo",
> 		"admins": {
> 		    "admin": [ { "name": "alice" } ]
> 		}
> 	    },
> 	    {
> 		"key": "bar",
> 		"admins": {
> 		    "admin": [ { "name": "bob" } ]
> 		}
> 	    }
>        ]
>    }
> }
> 
> (yangson) $ cat inst2.json 
> {
>    "test:tenants": {
> 	"tenant": [
> 	    {
> 		"key": "foo",
> 		"admins": {
> 		    "admin": [ { "name": "alice" } ]
> 		}
> 	    },
> 	    {
> 		"key": "bar",
> 		"admins": {
> 		    "admin": [ { "name": "alice" } ]
> 		}
> 	    }
>        ]
>    }
> }
> 
> (yangson) $ yangson -v inst1.json ylib.json 
> (yangson) $ yangson -v inst2.json ylib.json 
> Semantic error: [/test:tenants/tenant/1] must-violation
> 
> -- 
> Ladislav Lhotka 
> Head, CZ.NIC Labs
> PGP Key ID: 0xB8F92B08A9F76C67
> 
> _______________________________________________
> yang-doctors mailing list
> yang-doctors@ietf.org
> https://www.ietf.org/mailman/listinfo/yang-doctors