0

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 '(. = 3000)' {                                                                                         
      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..3000";                                                                                                   
      }                                                                                                                  
      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 3000 in feathers-count?

I've tried double-quoting feathers-count in refine and double-quoting the must conditional statement instead of single quotes. I expected that when I run a configuration with an input number that isn't 3000 for feathers-count, an error should be thrown and the configuration should not apply, but what resulted was the configuration being seamlessly applied.

IPbean
  • 1

1 Answers1

0

It is a bug in the implementation you are using or you have not configured it properly.

Your YANG definitions are invalid. The range of a unit8 integer built in type is 0..255. 3000 will never fit in there and the tool you are using should have produced an error for this range statement:

      type uint8 {                                                                                                       
        range "0..3000";                                                                                                   
      }  

My guess would be that the implementation you are using is ignoring XPath expressions entirely. You are correct in your assumption that a validation error should have been reported for an expression that evaluates to false().

module a {
    yang-version 1.1;
    namespace "a:uri";
    prefix "a";
    
    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..255";
            }
            mandatory true;
            description
                "[adapted from IETF BIRD model RFC 0000]                                                                             
                                                                                                                                 
                The number of feathers.";
        }
    }
    
    uses bird-config {
        refine feathers-count {
            must '(. = 255)' {
                error-message "Invalid number of feathers";
            }
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
        xmlns:a="a:uri">
  <a:bird-name>Featherless parrot</a:bird-name>
  <a:feathers-count>0</a:feathers-count>
</config>
Error at (5:3): failed assert at "/nc:config/a:feathers-count": Invalid number of feathers
predi
  • 5,528
  • 32
  • 60