Re: [yang-doctors] XPath question

Andy Bierman <andy@yumaworks.com> Tue, 07 June 2022 22:05 UTC

Return-Path: <andy@yumaworks.com>
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 541BEC14CF10 for <yang-doctors@ietfa.amsl.com>; Tue, 7 Jun 2022 15:05:56 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.105
X-Spam-Level:
X-Spam-Status: No, score=-7.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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-5, 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 (2048-bit key) header.d=yumaworks.com
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 5jKzSRP2iaKz for <yang-doctors@ietfa.amsl.com>; Tue, 7 Jun 2022 15:05:52 -0700 (PDT)
Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 3608DC14F73E for <yang-doctors@ietf.org>; Tue, 7 Jun 2022 15:05:52 -0700 (PDT)
Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-2ef5380669cso190500557b3.9 for <yang-doctors@ietf.org>; Tue, 07 Jun 2022 15:05:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yumaworks.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B0+HtCUQd9FhQaEjZ7m6qdNIy8ZA2LQHdAVmWZ7Jr7A=; b=LI+ZVNzVderkDgthoiMfbP1ZSjweWOj7b/1h5GVezUY1hFbs7H8PwV2ExYEugRHWpw oCIzqxBLNZnPVtLUxMRDTSULFACT0/JzjnG+ruWh3oqyyfusPSAU0Esf25eB9Nz32IW3 O5S1fPRtLBD3xCAEDxwsDMfN8xkAP89SNhiWgZPbzUprGCq+DmG+vHs70kJjBIgnQnxD YcuEXQHy9YgMhLT6PaWfyRyOz58rXKeraCLmBwViH9MoMFhI9EUd7aYKwdzgyTE7q1vU 9q3rQtLMDMitgOQLTH6hyrN8Cl7TUUlV8TbW5byjnDDHyLwbe1Zd2ULvpMxWw9yWeqDr fVCw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B0+HtCUQd9FhQaEjZ7m6qdNIy8ZA2LQHdAVmWZ7Jr7A=; b=Km2y9nZSm9L3G6e9WXZi8PgazJkZb+QpbXq1s31/BIGdtukvOtCkNO+9uSGDwFeNFP kconMOhergSA58N2AkWsWOIsGzIZOEgP6ZWEz8679RrmNtzHfdEj9e4Wvb4p1CGiRJyu Q+HZNCVjGEKV9h4KrbzKZ4amPOCoZMd5mWJQWWuRK3XOvM4UJ5exSkQ1ghmz/oT1VC4N pIznm6BV5LvGaqTK2z3AFTJdfE0E16vIoqDmj2g13NTnFj1LPdnYasxPMoGht4upX3FU xlp2fJMtCVqHUa6QsLnTOaSG1Cyh9HqtFFaU08O15vLidkFd0ivEyTMDeuCqXFt9yV2T 6/4w==
X-Gm-Message-State: AOAM533zmfzcYzzKFN3kZfbnPrq6pD86gwfqxr+YddIhhogJVkS4gZFr 2vdf019gwe6vmK5nwTwzgItkCJcFYN2oZsBC5wEL4+FGuwu8Iw==
X-Google-Smtp-Source: ABdhPJz2/xBzNI07INw6QS0xCcVUVvlchiC6/8XYdZbEEXjrWYHexZL9xexuI8KJLQH9KKNHCesYs687Xv92pmMGlBc=
X-Received: by 2002:a81:8801:0:b0:2fe:e24b:1c33 with SMTP id y1-20020a818801000000b002fee24b1c33mr33294985ywf.110.1654639550874; Tue, 07 Jun 2022 15:05:50 -0700 (PDT)
MIME-Version: 1.0
References: <CABCOCHQuBzG=e=VM+sxj9ACmar=DVeKDD=JYCP86LAXAvjBZyQ@mail.gmail.com> <20220607.083434.636080514128977187.id@4668.se>
In-Reply-To: <20220607.083434.636080514128977187.id@4668.se>
From: Andy Bierman <andy@yumaworks.com>
Date: Tue, 07 Jun 2022 15:05:40 -0700
Message-ID: <CABCOCHTGo5GEADGffPhgcRG2mcq01H=ppDi76rAN757Q=uxV1Q@mail.gmail.com>
To: Martin Björklund <mbj+ietf@4668.se>
Cc: YANG Doctors <yang-doctors@ietf.org>
Content-Type: multipart/alternative; boundary="000000000000a9620d05e0e2cafa"
Archived-At: <https://mailarchive.ietf.org/arch/msg/yang-doctors/qV5QSIbJy8kNXUuHn4fPeHMNnK8>
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: Tue, 07 Jun 2022 22:05:56 -0000

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.
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.

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
>