Subject: [yang-doctors] when statement of an optional leaf? Does it make an optional leaf?

From: Benoit Claise <[email-masked]>
Date: Tue, 17 Mar 2020 16:03:05 +0100

YANG doctors,

$ pyang -f tree  ietf-service-assurance.yang
module: ietf-service-assurance
   +--ro assurance-graph-version?       yang:counter32
   +--ro assurance-graph-last-change?   yang:date-and-time
   +--rw subservices
      +--rw subservice* [type id]
         +--rw type                                identityref
         +--rw id                                  string
         +--ro last-change?                        yang:date-and-time
         +--ro label?                              string
         +--rw under-maintenance?                  boolean
         +--rw maintenance-contact string <===============================
         +--rw (parameter)?
         |  +--:(service-instance-parameter)
         |     +--rw service-instance-parameter
         |        +--rw service?         string
         |        +--rw instance-name?   string
         +--ro health-score?                       uint8
         +--rw symptoms
         |  +--ro symptom* [start-date-time id]
         |     +--ro id                     string
         |     +--ro health-score-weight?   uint8
         |     +--ro label?                 string
         |     +--ro start-date-time        yang:date-and-time
         |     +--ro stop-date-time?        yang:date-and-time
         +--rw dependencies
            +--rw dependency* [type id]
               +--rw type               -> /subservices/subservice/type
               +--rw id                 -> 
/subservices/subservice[type=current()/../type]/id
               +--rw dependency-type?   identityref

The YANG modules comes from 
https://datatracker.ietf.org/doc/draft-claise-opsawg-service-assurance-yang/
Have a look at 
https://raw.githubusercontent.com/YangModels/yang/ecb622b214e59c5f6312e915d4d65823a6485852/experimental/ietf-extracted-YANG-modules/[email-masked]

The leafs in question:

           leaf under-maintenance {
             type boolean;
             default false;
             description
               "An optional flag indicating whether this particular subservice is under
               maintenance. Under this circumstance, the subservice symptoms and the
               symptoms of its dependencies in the assurance graph should not be taken
               into account. Instead, the subservice should send a 'Under Maintenance'
               single symptom.

               The operator changing the under-maintenance value must set the
               maintenance-contact variable.

               When the subservice is not under maintenance any longer, the
               under-maintenance flag must return to its default value and
               the under-maintenance-owner variable deleted.";
           }
           leaf maintenance-contact {
    when "../under-maintenance";
             type string;
             mandatory true;
             description
               "A string used to model an administratively assigned name of the
               resource that changed the under-maintenance value to 'true.

               It is suggested that this name contain one or more of the following:
               IP address, management station name, network manager's name, location,
               or phone number. In some cases the agent itself will be the owner of
               an entry. In these cases, this string shall be set to a string
               starting with 'monitor'.";
           }

In case of a leaf (maintenance-contact) with a when statement pointing 
to an optional leaf (under-maintenance), should the leaf 
(maintenance-contact) be marked as optional in the tree output?

Regards, Benoit

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 17 Mar 2020 18:24:51 +0100

Hi Benoit,

"maintenance-contact" may remain mandatory - due to its default value, "under-maintenace" is always present, as far as XPath evaluation is concerned.

But because of this, your when expression probably doesn't have the effect that you expect: it will always be true. I think it needs to be changed to

    when "../under-maintenance = 'true'";

Lada

Benoit Claise <bclaise=[email-masked]> writes:

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

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

---

From: "Jean Quilbeuf -X (jquilbeu - LIANEO at Cisco)" <[email-masked]>
Date: Tue, 17 Mar 2020 17:54:00 +0000

Hi Ladislav,
Thanks, that was indeed the issue !

Best,
Jean

-----Original Message-----
From: Ladislav Lhotka <[email-masked]> 
Sent: Tuesday, March 17, 2020 6:25 PM
To: Benoit Claise <bclaise=[email-masked]>; YANG Doctors <[email-masked]>
Cc: Eric Vyncke (evyncke) <[email-masked]>; Jean Quilbeuf -X (jquilbeu - LIANEO at Cisco) <[email-masked]>
Subject: Re: [yang-doctors] when statement of an optional leaf? Does it make an optional leaf?

Hi Benoit,

Lada

Benoit Claise <bclaise=[email-masked]> writes:

> https://raw.githubusercontent.com/YangModels/yang/ecb622b214e59c5f6312
> e915d4d65823a6485852/experimental/ietf-extracted-YANG-modules/ietf-ser
> [email-masked]
>
> The leafs in question:
>
>            leaf under-maintenance {
>              type boolean;
>              default false;
>              description

---

From: Benoit Claise <[email-masked]>
Date: Tue, 17 Mar 2020 19:07:58 +0100

Hi Lada,

Thanks for the XPath correction.
When I apply this change, I still see the maintenance-contact as mandatory.

         +--rw maintenance-contact                 string

I guess the validation is not clever enough to combine "mandatory true" 
and Xpath (when "../under-maintenance='true'") from maintenance-contact 
with the optional under-maintenance leaf ... to conclude that 
maintenance-contact is actually optional.

Regards, Benoit

---

From: "Jean Quilbeuf -X (jquilbeu - LIANEO at Cisco)" <[email-masked]>
Date: Tue, 17 Mar 2020 18:19:05 +0000

Hi Benoît, all,
To clarify:
by "it works" I meant that instances that do not specify a "maintenance-contact" nor a "under-maintenance" (which then default to false) become valid for ConfD after the modification. Did not try pyang !

Best,
Jean

-----Original Message-----
From: Benoit Claise <[email-masked]> 
Sent: Tuesday, March 17, 2020 7:08 PM
To: Ladislav Lhotka <[email-masked]>; Benoit Claise <bclaise=[email-masked]>; YANG Doctors <[email-masked]>
Cc: Eric Vyncke (evyncke) <[email-masked]>; Jean Quilbeuf -X (jquilbeu - LIANEO at Cisco) <[email-masked]>
Subject: Re: [yang-doctors] when statement of an optional leaf? Does it make an optional leaf?

Hi Lada,

I guess the validation is not clever enough to combine "mandatory true" 
and Xpath (when "../under-maintenance='true'") from maintenance-contact with the optional under-maintenance leaf ... to conclude that maintenance-contact is actually optional.

Regards, Benoit
> But because of this, your when expression probably doesn't have the 
> effect that you expect: it will always be true. I think it needs to be 
> changed to
>
>> https://raw.githubusercontent.com/YangModels/yang/ecb622b214e59c5f631
>> 2e915d4d65823a6485852/experimental/ietf-extracted-YANG-modules/ietf-s
>> [email-masked]
>>
>> The leafs in question:
>>
>>             leaf under-maintenance {
>>               type boolean;
>>               default false;
>>               description
>> In case of a leaf (maintenance-contact) with a when statement 
>> pointing to an optional leaf (under-maintenance), should the leaf

---

From: Martin Björklund <[email-masked]>
Date: Tue, 17 Mar 2020 19:42:27 +0100 (CET)

Hi,

> When I apply this change, I still see the maintenance-contact as

maintenance-contact has a "mandatory true" statement.  The "when"
statement doesn't change that.  Hence it is marked as mandatory in the
tree diagram.  "when" statements are not visible in tree diagrams.

/martin

> I guess the validation is not clever enough to combine "mandatory
> true" and Xpath (when "../under-maintenance='true'") from
> maintenance-contact with the optional under-maintenance leaf ... to
> conclude that maintenance-contact is actually optional.
> 
> Regards, Benoit
> > Hi Benoit,
> >
> > "maintenance-contact" may remain mandatory - due to its default value,
> > "under-maintenace" is always present, as far as XPath evaluation is
> > concerned.
> >
> >>   <===============================
> >>           +--rw (parameter)?

---

From: Benoit Claise <[email-masked]>
Date: Thu, 19 Mar 2020 09:01:57 +0100

Thanks Martin for the clarification.

Regards, B.
> .