cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1146
Views
0
Helpful
0
Replies

Yang: Issue with must statement on leafs that are part of the key?

ogenstad
Level 1
Level 1

I have a Yang file which looks like this:

 

module myservice {

  namespace "http://example.com/myservice";
  prefix myservice;

  import ietf-inet-types {
    prefix inet;
  }
  import tailf-common {
    prefix tailf;
  }
  import tailf-ncs {
    prefix ncs;
  }

  description
    "Handle configuration for route-reflector clients";

  revision 2019-02-11 {
    description
      "Initial revision.";
  }

  container rr {

    list device {
      key "device";
      leaf device {
        tailf:info "Device";
        type leafref {
          path "/ncs:devices/ncs:device/ncs:name";
        }
       }

       list reflectors {
         key "device";

         leaf device {
          tailf:info "Device";
          type leafref {
            path "/ncs:devices/ncs:device/ncs:name";
          }
         }

       }

    }


  }

  list myservice {
    tailf:info "Define route reflector clients";

    uses ncs:service-data;
    ncs:servicepoint bgp-rr-rfs-servicepoint;

    key "rr-service";
    // key "rr-service device";

    leaf rr-service {
      type enumeration {
        enum "vpn";
      }
    }

    leaf device {
      tailf:info "Device";
      must "count(/rr/device[device=current()]/reflectors) > 0";
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }

    }

  }
}

I've then populated the rr container so that there are two devices there each one has defined two route reflectors:

 

admin@ncs% show rr | display xpath
/rr/device[device='xr-pe0']/reflectors[device='xr-rr0']
/rr/device[device='xr-pe0']/reflectors[device='xr-rr1']
/rr/device[device='xr-pe2']/reflectors[device='xr-rr0']
/rr/device[device='xr-pe2']/reflectors[device='xr-rr1']
[ok][2019-02-22 14:58:38]

I want the "must" statement to enforce that the service requires that the reflector count for each device is more than zero. 

 

Using the above Yang solves this problem as I'm not able to commit the service without setting two route reflectors. Here I correctly see that only xr-pe0 and xr-pe2 is available in the possible completions list and when I try to commit the service using xr-pe1 which doesn't have any route reflectors configured the must-statement evaluates to false and an error is given.

 

admin@ncs% set myservice vpn device ?
Description: Device
Possible completions:
  xr-pe0  xr-pe2
admin@ncs% set myservice vpn device xr-pe1
[ok][2019-02-22 14:59:25]

[edit]
admin@ncs% commit dry-run
Aborted: 'myservice vpn device' (value "xr-pe1"): the 'must' expression "count(/rr/device[device=current()]/reflectors) >0" failed
[error][2019-02-22 14:59:27]

[edit]
admin@ncs%

However, if I change the key so that I key my service with `key "rr-service device"` instead things fall apart. The context-sensitive help still works and xr-pe0 and xr-pe2 is seen in the possible completions list. But, if I enter xr-pe1 and commit dry-run it's as if the must-statement is completely ignored. Instead, the data is sent of to the Python VM.

 

admin@ncs% set myservice vpn ?
Description: Device
Possible completions:
  <Device>  xr-pe0  xr-pe2
admin@ncs% set myservice vpn xr-pe1
[ok][2019-02-22 15:01:56]

[edit]
admin@ncs% commit dry-run
Aborted: Python cb_create error. 'NoneType' object has no attribute 'string'
[error][2019-02-22 15:02:00]

[edit]
admin@ncs%

Am I doing something wrong? Is this a bug, or shouldn't this be possible?

 

Thanks.

 

0 Replies 0
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: