Re: [yang-doctors] XPath question

Ladislav Lhotka <ladislav.lhotka@nic.cz> Wed, 08 June 2022 08:22 UTC

Return-Path: <ladislav.lhotka@nic.cz>
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 B4F4CC139C27 for <yang-doctors@ietfa.amsl.com>; Wed, 8 Jun 2022 01:22:14 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.105
X-Spam-Level:
X-Spam-Status: No, score=-2.105 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_BLOCKED=0.001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=nic.cz
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fPCJwRS9xleu for <yang-doctors@ietfa.amsl.com>; Wed, 8 Jun 2022 01:22:10 -0700 (PDT)
Received: from mail.nic.cz (mail.nic.cz [IPv6:2001:1488:800:400::400]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2C73AC15AAF2 for <yang-doctors@ietf.org>; Wed, 8 Jun 2022 01:22:09 -0700 (PDT)
Received: from wedge.nic.cz (unknown [IPv6:2001:1488:fffe:6:a8c6:1fff:fec3:5de1]) by mail.nic.cz (Postfix) with ESMTPSA id 7A2D314054A; Wed, 8 Jun 2022 10:22:04 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1654676524; bh=DwK8v2RriBc4eybTnp1rsLjwk3DNrJV86HwJSQ99MXU=; h=From:To:Cc:Subject:Date:From; b=JwxHJrJ7EC7yXsav54oCBqhiJP4qsRRUl4AGvHGeRRiwlR57CyhRDRoOtAMV9stHJ En0eKHnkkqlPNVWrfXBLvmByhai3uNqDxsWkVT9uLQGvsBOhSaxjaCxWdeB8DpKRen RCRarlASINn3xhl23G5cvpaVO5HMatQpSMJ1yYGA=
From: Ladislav Lhotka <ladislav.lhotka@nic.cz>
To: Andy Bierman <andy@yumaworks.com>, Martin Björklund <mbj+ietf@4668.se>
Cc: YANG Doctors <yang-doctors@ietf.org>
In-Reply-To: <CABCOCHTGo5GEADGffPhgcRG2mcq01H=ppDi76rAN757Q=uxV1Q@mail.gmail.com>
References: <CABCOCHQuBzG=e=VM+sxj9ACmar=DVeKDD=JYCP86LAXAvjBZyQ@mail.gmail.com> <20220607.083434.636080514128977187.id@4668.se> <CABCOCHTGo5GEADGffPhgcRG2mcq01H=ppDi76rAN757Q=uxV1Q@mail.gmail.com>
Date: Wed, 08 Jun 2022 10:22:04 +0200
Message-ID: <87leu71s5v.fsf@nic.cz>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-Virus-Scanned: clamav-milter 0.103.4 at mail
X-Virus-Status: Clean
X-Rspamd-Queue-Id: 7A2D314054A
X-Spamd-Result: default: False [0.00 / 99.00]; WHITELISTED_IP(0.00)[2001:1488:fffe:6:a8c6:1fff:fec3:5de1]; TAGGED_RCPT(0.00)[ietf]; ASN(0.00)[asn:25192, ipnet:2001:1488::/32, country:CZ]
Authentication-Results: mail.nic.cz; auth=pass smtp.auth=ladislav.lhotka@nic.cz smtp.mailfrom=ladislav.lhotka@nic.cz
X-Spamd-Bar: /
X-Rspamd-Server: mail
Archived-At: <https://mailarchive.ietf.org/arch/msg/yang-doctors/KJbzxYZ23hkSap6ObBxX4WDPa-I>
Subject: Re: [yang-doctors] XPath question
X-BeenThere: yang-doctors@ietf.org
X-Mailman-Version: 2.1.39
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: Wed, 08 Jun 2022 08:22:14 -0000

Andy Bierman <andy@yumaworks.com> writes:

> On Mon, Jun 6, 2022 at 11:34 PM Martin Björklund <mbj+ietf@4668.se> wrote:
>
>> Andy Bierman <andy@yumaworks.com> wrote:
>> > Hi,
>> >
>> > RFC 7950 does not say whether unselected case-stmts are visible in XPath.
>> > The bbf-qos-enhanced-scheduling module has a default leaf in 1 case
>> > and a nested node with a must-stmt in a sibling case that references it.
>>
>> This will not work, since the XPath context in this case is the
>> datastore, and the datastore will never contain nodes from two
>> different cases.  But see below.
>>
>
>
> XPath evaluation also includes defaults.

Section 7.6.1 in RFC 7950:

   o  Otherwise, if this ancestor is a case node, the default value MUST
      be used if any node from the case exists in the data tree or the
      case node is the choice's default case, and if no nodes from any
      other case exist in the data tree.

So if instance nodes from other cases exist, the default value is not in use.

> pyang, yanglint, and yangdump-pro all accept this module:
>
> container top {
>      choice A {
>        leaf A1 {
>           type int32;
>           default 10;
>        }
>        container A2 {
>          leaf A2.1 {
>            type string;
>            must "../../A1 = 10";
>          }
>          leaf A2.2 {
>            type string;
>            must "../../A3 = 100";
>          }
>        }
>        leaf A3 {
>           type int32;
>           default 100;
>        }
>      }
>   }
>
> That seems correct because at compile-time only the schema nodes are known
> and they are used correctly.

There is nothing wrong with it, except that either of the must expressions always evaluates to false, if it is evaluated at all. This is by definition, because the must expressions are evaluated only if instances of leaves A2.1 or A2.2 exist in the data tree, in which case the defaults for A1 and A3 are not in use.

Lada

>
> The issue is whether the defaults (10 and 100) exist in XPath evaluation or
> not.
> Sec. 7.9.3 indicates that these defaults are not present (see bold).
> It seems clear that only the defaults in the default-case are used in XPath
> evaluation,
> and only if no explicit case is used.
>
> The BBF XPath is fine because a different list entry can be selected, but
> only if the
> leaf is set explicitly (since no default case in these examples).
>
>
> 7.9.3 <https://datatracker.ietf.org/doc/html/rfc7950#section-7.9.3>.
> The choice's "default" Statement
>
>    The "default" statement indicates if a case should be considered as
>    the default if no child nodes from any of the choice's cases exist.
>    The argument is the identifier of the default "case" statement.  If
>    the "default" statement is missing, there is no default case.
>
>    The "default" statement MUST NOT be present on choices where
>    "mandatory" is "true".
>
>    The default case is only important when considering the "default"
>    statements of nodes under the cases (i.e., default values of leafs
>    and leaf-lists, and default cases of nested choices).  The default
>    values and nested default cases under the default case are used if
>    none of the nodes under any of the cases are present.
>
>    There MUST NOT be any mandatory nodes (Section 3
> <https://datatracker.ietf.org/doc/html/rfc7950#section-3>) directly
> under the
>    default case.
>
>    *Default values for child nodes under a case are only used if one of
>    the nodes under that case is present or if that case is the default
>    case.  If none of the nodes under a case are present and the case is
>    not the default case, the default values of the cases' child nodes
>    are ignored.*
>
>
>  Andy
>
>
>> The issue is whether the XPath context includes the default leaf.
>> > Case 'queue' and 'child-schedular-queues' are siblings.
>> > I suspect our code is wrong and the defaults from all cases are visible
>> > to XPath evaluation.
>> >
>> >
>> >           case queue {
>> >             description
>> >               "The children are a list of queues.";
>> >             leaf contains-queues {
>> >               type boolean;
>> >               *default "true";*
>> >               description
>> >                 "Indicates the scheduler contains queues.";
>> >             }
>> >             uses bbf-qos-tm:queues;
>> >           }
>> >           case child-scheduler-queues {
>> >             if-feature "child-scheduler-queue-references";
>> >             container child-scheduler-queues {
>> >               description
>> >                 "Configuration to reference one or more queues within
>> >                  one or more child schedulers.";
>> >               list child-scheduler {
>> >
>> >                  // ....
>> >
>> >                 container queues {
>> >
>> >
>> > * must "../../../../bbf-qos-sched:scheduler-node"                     +
>> > "[bbf-qos-sched:name=current()/../name]/"                     +
>> > "bbf-qos-sched:contains-queues = 'true'" *{
>> >                     error-message
>> >                       "The referenced scheduler must contain queues.";
>> >                     description
>> >                       "The referenced scheduler must contain queues
>> >                        in order for queues to be referenced.";
>> >                   }
>>
>> I don't have the full model in front of me, but does this really refer
>> to a node in a sibling case?  It looks as if it might refer to another
>> instance of the "scheduler-node" list (I assume it is a list).
>>
>>
>> /martin
>>
> _______________________________________________
> yang-doctors mailing list
> yang-doctors@ietf.org
> https://www.ietf.org/mailman/listinfo/yang-doctors

-- 
Ladislav Lhotka
Head, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67