ConfD User Community

Must statement with in leaf-list


#1

I have two nodes

    leaf xyz{                            
         type uint8 {                         
             range "1..32";                   
         }                                    
         mandatory true;                      
     }                                        
     leaf-list aaa {                        
                                              
         must "(count(.) == ../xyz)" {
             error-message "Number of elements in leaf-list aaa must be equal to number of xyz";
         }                                                                     
         type uint8;                                                           
         min-elements 1;                                                       
     }         

But I get “error: XPath error: XPath syntax error”. Can anyone please suggest a way to fix this ?


#2

A single ’=’ instead of ’==’ should do the trick


#3

Thanks for quick response. I have tried changing it to single ‘=’ and from cli my config looks like

admin(config)# xyz_configs xyz_name sample1 xyz 3 aaa [ 1 2 3 ] status enabled
admin(config)# commit
Aborted: xyz_configs xyz_name sample1 aaa’ (value “1”): Number of elements in aaa must be equal to number of xyz
admin(config)#

what am I doing wrong here. I was expecting it to take since aaa list has 3 elements which is equal to xyz value ‘3’ ?


#4

It worked now. I was using “must” in wrong place.

Thanks so much for the help


#5

Magic.
My next suggestion would have been:
must "count(/aaa) = number(/xyz)"
since:
$ confd_cli -u admin -C
# devtools true
# config
# aaa [ 1 2 3 ]
# xyz 3
(config)# xpath eval count(/aaa)
3
(config)# xpath eval xyz
/xyz :: 3
# xpath eval number(xyz)
3
# xpath must count(/aaa) = number(/xyz)
true