ConfD User Community

Refining group not triggering error

I’ve added a “refine” and “must” when “uses” refers to a group. An example of how it’s being used is as follows :

uses bird-config {                                                                                    
  refine feathers-count {                                                                                    
    must '(. = 30)' {                                                                                         
      error-message "Invalid number of feathers";                                                           
    }                                                                                                         
  }                                                                                                           
}      

Where the grouping “bird-config” is defined as:

grouping bird-config {                                                                                         
                                                                                                                         
    description                                                                                                          
      "Per bird configuration data.";                                                                                                       
                                                                                                                         
    leaf bird-name {                                                                                                            
      type species:birds;                                                                                    
      description                                                                                                        
        "[adapted from IETF BIRD model RFC 0000]                                                                           
                                                                                                                         
        The bird name.";                                                                             
    }                                                                                                                    
                                                                                                                         
    leaf feathers-count {                                                                                                 
      type uint8 {                                                                                                       
        range "0..30";                                                                                                   
      }                                                                                                                  
      mandatory true;                                                                                                      
      description                                                                                                          
        "[adapted from IETF BIRD model RFC 0000]                                                                             
                                                                                                                         
        The number of feathers.";                                                                                 
    }                                                                                                                    
  }

Why is error not being thrown with this simple refine-must statement when I input numbers that aren’t 30 in feathers-count?

That will not compile with confic. A uint8 has a 0…255 range.

If you were using the CLI to test that, did you commit the new config? must statements are validated when you commit the transaction.

1 Like

Following up on Conny’s response, following is an example that illustrates that your model won’t compile with ConfD:

$ cat abc.yang
module abc {
  namespace "http://example.com/abc";
  prefix abc;

  grouping bird-config {
    description
      "Per bird configuration data.";
    leaf bird-name {
      type string;
      description
        "[adapted from IETF BIRD model RFC 0000]
        The bird name.";
    }
    leaf feathers-count {
      type uint8 {
        range "0..3000";
      }
      //mandatory true;
      description
        "[adapted from IETF BIRD model RFC 0000]
        The number of feathers.";
    }                                                                                                                    
  }

  uses bird-config {
    refine feathers-count {
      must '(. = 3000)' {
        error-message "Invalid number of feathers";
      }
    }
  }
}

$ confdc -c -o abc.fxs  abc.yang
abc.yang:16: error: the range value 3000 is not valid for the base type

If your model is modified to match what is possible with the uint8 type:

$ confdc -c -o abc.fxs  abc.yang
abc.yang:16: error: the range value 3000 is not valid for the base type
make: *** [abc.fxs] Error 1

$ cat abc.yang
module abc {
  namespace "http://example.com/abc";
  prefix abc;

  grouping bird-config {
    description
      "Per bird configuration data.";
    leaf bird-name {
      type string;
      description
        "[adapted from IETF BIRD model RFC 0000]
        The bird name.";
    }
    leaf feathers-count {
      type uint8 {
        range "0..200";
      }
      //mandatory true;
      description
        "[adapted from IETF BIRD model RFC 0000]
        The number of feathers.";
    }                                                                                                                    
  }

  uses bird-config {
    refine feathers-count {
      must '(. = 200)' {
        error-message "Invalid number of feathers";
      }
    }
  }
}

$ confdc -c -o abc.fxs  abc.yang
$ $CONFD_DIR/bin/confd -c confd.conf --addloadpath $CONFD_DIR/etc/confd
$ $CONFD_DIR/bin/confd_cli -Cu admin
localhost# config 
Entering configuration mode terminal
localhost(config)# 
localhost(config)# feathers-count ?
Possible completions:
  <unsignedByte, 0 .. 200>
localhost(config)# feathers-count 180
localhost(config)# validate 
Failed: 'feathers-count' (value "180"): Invalid number of feathers
localhost(config)# commit
Aborted: 'feathers-count' (value "180"): Invalid number of feathers
localhost(config)# feathers-count 200
localhost(config)# validate 
Validation complete
localhost(config)# commit
Commit complete.

As you can see, the error is thrown when you perform either validate or commit for the transaction.

2 Likes