Subject: [netmod] when-stmt on keys

From: Andy Bierman <[email-masked]>
Date: Wed, 18 Nov 2015 12:17:20 -0800

Hi,

This text in 7.21.5 is not clear:

   A leaf that is a list key MUST NOT have a "when" statement.

I think you mean that no when-stmt can use the key leaf as
a context node.

These are illegal in YANG 1.1 I think:

   augment /listX {
      when "foo";
      leaf key1 { ... }
   }

OR

    list listX {
       key key1;
       uses grouping1 {
          when "foo";
           // leaf key1 added via grouping
       }
    }

There are more ways that the key-leaf can inherit a when-stmt
but you get the idea.

The phrase "have a when-stmt" should be clear.
It implies that the when-stmt is a sub-statement of the leaf-stmt
but this is only 1 way the key leaf can be conditional.

Andy

---

From: Martin Bjorklund <[email-masked]>
Date: Thu, 19 Nov 2015 10:38:53 +0100 (CET)

> These are illegal in YANG 1.1 I think:

Why would this be illegal?  You didn't show the definition of listX,
but it cannot have "key1" as one of its keys.

>            // leaf key1 added via grouping

Why would this be illegal?

> There are more ways that the key-leaf can inherit a when-stmt

I don't think a key leaf can "inherit" a when statement.

> but this is only 1 way the key leaf can be conditional.

/martin

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 19 Nov 2015 11:11:18 +0100

> On 19 Nov 2015, at 10:38, Martin Bjorklund <[email-masked]> wrote:
> 

I think Andy has a point, here is a complete example:

  leaf foo {
    type empty;
  }
  list array {
    key "key1";
    leaf bar {
      type empty;
    }
  }
  augment "/array" {
    when "../foo";
    leaf key1 {
      type uint8;
    }
  }

Without the "when" statement it is perfectly okay but here the presence of "foo" makes "key1" disappear but "array" remains.

> Why would this be illegal?

Similar as above.

Lada

> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod

--
Ladislav Lhotka, CZ.NIC Labs
PGP Key ID: E74E8C0C

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 19 Nov 2015 11:15:39 +0100

> On 19 Nov 2015, at 11:11, Ladislav Lhotka <[email-masked]> wrote:
> 
>> 

s/presence/absence/ --------------------------------------------^^^^^^^^

Lada

---

From: Martin Bjorklund <[email-masked]>
Date: Thu, 19 Nov 2015 12:38:51 +0100 (CET)

> I think Andy has a point, here is a complete example:

I don't think this is legal even w/o the "when" statement.  RFC 6020
says in 7.8.2 about the "key" statetement:

   Each such leaf identifier MUST refer to a child leaf of the
   list.  The leafs can be defined directly in substatements to the
   list, or in groupings used in the list.

I.e., it is not legal to augment a key.  (I noticed that pyang doesn't
detect this...)

> Without the "when" statement it is perfectly okay but here the
> presence of "foo" makes "key1" disappear but "array" remains.
> 
> > 
> >> OR
> >> 
> >> 
> >>    list listX {
> >>       key key1;
> >>       uses grouping1 {
> >>          when "foo";

Ah, ok, yes this should be illegal.

I think we need to add specific text for this scenario:

  If a leaf key is defined in a grouping that is used in a list, the
  "uses" statement MUST NOT have a "when" statement.

/martin

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 19 Nov 2015 12:59:27 +0100

> On 19 Nov 2015, at 12:38, Martin Bjorklund <[email-masked]> wrote:
> 

OK, makes sense.

> I.e., it is not legal to augment a key.  (I noticed that pyang doesn't

Yes, I tried it. :-)

>  "uses" statement MUST NOT have a "when" statement.

And the same holds for "if-feature". I think these restrictions on list keys should be stated in sec. 7.8.2 (and possibly in 7.21.5, too).

Lada

---

From: Andy Bierman <[email-masked]>
Date: Thu, 19 Nov 2015 07:18:03 -0800

>   "uses" statement MUST NOT have a "when" statement.
Don't forget that a "uses" statement can inherit when-stmts as well,
e.g., inside a case-stmt.

IMO it is difficult to describe the true complexity of the when-stmt.
It is by far the hardest part of YANG to get right.  But usually developers
can interpret the simplistic text in the draft when writing the code.

BTW, I am still strongly opposed to modifying the datastore to evaluate
when-stmts.  I do not see why YANG should assume that different
implementations
will be evaluating different conceptual instance documents.
IMO the easiest and most interoperable behavior would be to just
evaluate the XPath on the document.  If somebody codes useless
garbage like "augment foo with bar when bar=3" then who cares?
This is operational garbage, not a use-case.

Andy