Re: [netmod] ?==?utf-8?q? Question on when-construction involving identities not detected as an error during module compilation

Michal Vaško <mvasko@cesnet.cz> Fri, 18 May 2018 10:23 UTC

Return-Path: <mvasko@cesnet.cz>
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 DD10412D574 for <netmod@ietfa.amsl.com>; Fri, 18 May 2018 03:23:23 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.79
X-Spam-Level:
X-Spam-Status: No, score=-1.79 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, T_DKIM_INVALID=0.01] autolearn=no autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=cesnet.cz
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 JgjT-HsPo-fq for <netmod@ietfa.amsl.com>; Fri, 18 May 2018 03:23:21 -0700 (PDT)
Received: from kalendar.cesnet.cz (kalendar.cesnet.cz [78.128.211.34]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 8A52712D77A for <netmod@ietf.org>; Fri, 18 May 2018 03:23:21 -0700 (PDT)
Received: by kalendar.cesnet.cz (Postfix, from userid 999) id EE23F604FB; Fri, 18 May 2018 12:23:18 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=kalendar; t=1526638998; bh=QFGg5bzVGAib3TCvyZC9n8Z/tAA+e+jiiy7abW+khns=; h=In-Reply-To:From:Date:Cc:To:Subject; b=0sOAO48jcDwK+kMFrHo+j59658ddmUgTaHxdFsReDVkseQC+5AtcyJZDyyPDkK5sf 6pxXqvCFUAxiEAC2210cKF9pQTAmL2lFno5dfSTmw5YTL1vlgyPHVl6xeEi2dLrLqJ nN7lEJsBsA6o+dvXJBqbC01Uu9Nxmy7CAV423rqU=
Content-Type: text/plain; charset="utf-8"
In-Reply-To: <20180518.121626.115730608086823938.mbj@tail-f.com>
From: Michal Vaško <mvasko@cesnet.cz>
X-Forward: 2001:67c:1220:80c:f5:8e35:ef0e:146c
Date: Fri, 18 May 2018 12:23:18 +0200
Cc: bart.bogaert@nokia.com, netmod@ietf.org
To: Martin Bjorklund <mbj@tail-f.com>
MIME-Version: 1.0
Message-ID: <3ee8-5afea980-1f-15b6c1c0@106157737>
User-Agent: SOGoMail 2.3.23
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/2feQpolaMhRDOP0_SpvDUDRK8zw>
Subject: Re: [netmod] ?==?utf-8?q? Question on when-construction involving identities not detected as an error during module compilation
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: Fri, 18 May 2018 10:23:24 -0000

Hi,

On Friday, May 18, 2018 12:16 CEST, Martin Bjorklund <mbj@tail-f.com> wrote: 
 
> Hi,
> 
> "Bogaert, Bart (Nokia - BE/Antwerp)" <bart.bogaert@nokia.com> wrote:
> > Hi,
> > 
> > We have a question on YANG module compilation.  Assume the following
> > model:
> > 
> > module test-feat-compile {
> >   yang-version 1.1;
> >   namespace "http://www.example.com/test-feat-compile";
> >   prefix "tfc";
> > 
> >   identity failure-reason {
> >     description
> >       "The reason a failure occurred.";
> >   }
> > 
> >   identity no-failure {
> >     description
> >       "No failure has occurred.";
> >   }
> > 
> >   identity general-error {
> >     base failure-reason;
> >     description
> >       "A general error occurred.";
> >   }
> > 
> >   container failure {
> >     description
> >       "Objects associated with a failure.";
> > 
> >     leaf failure-reason {
> >       type identityref {
> >         base failure-reason;
> >       }
> >       description
> >         "The reason the failure occurred.";
> >     }
> > 
> >     leaf failure-string {
> >       when "../failure-reason != 'no-failure'" {
> >         description
> >           "Only valid when there is a failure.";
> >       }
> >       type string;
> >       description
> >         "A text string indicating the reason for the failure when
> >          either no defined reason exists or additional information
> >          is available beyond the definition of the reason.";
> >     }
> >   }
> > }
> > 
> > Looking at the when clause there is something obviously wrong (at
> > least this is how I see it):
> > 
> >   *   The leaf 'failure-reason' is of type identityref with 'failure-reason'
> >       as base
> >   *   Identity 'no-failure' does not have 'failure-reason' as base (see it
> >       as having been forgotten)
> > Question is: shouldn't this be reported at compile time?  Pyang
> > doesn't and the other compiler we use doesn't report this either.
> > 
> > Even when 'no-failure' is modified into some arbitrary string it is
> > still accepted while this arbitrary string is not defined anywhere as
> > identity.
> > 
> > And when it comes to the correct syntax, RFC 7950 states (section
> > 9.1.3) that identities in must and when statements should be prefixed
> > (so tfc:no-failure in this case).  Also this "violation" passes.
> > 
> > So: what can we expect to be checked at compile time in this case?
> > Now you can only detect these anomalies when using a system supporting
> > the modules and detect that things do not work as intended.  It would
> > be better to have these erroneous constructions being detected at
> > compile time.  If there is something in the RFC that allows the
> > compiler to behave as it does now it would be good to know.
> 
> Strictly speaking, the "when" expressions are not erroneous; they are
> proper XPath expressions that happen to always return "false".
> 
> A good compiler could detect this and produce a warning, but it would
> be incorrect to flag this as an error.

Exactly and you can try using yanglint(1) from libyang [1], which prints both problems you mentioned as warnings.

Kind regards,
Michal Vasko

[1] https://github.com/cesnet/libyang