cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3280
Views
15
Helpful
4
Replies

YANG must statement using contains

yfherzog
Cisco Employee
Cisco Employee

Hi,

 

I have this must statement which I want to use to check if a leaf-list contains a certain value:

 

must "contains(route-target, '15525')";

In the xpath trace I see this:

 

18-Jun-2019::13:38:17.870 evaluating: /vrf:vrf[device='xr-1'][vrf-name='foo']/ipv4/imports: contains(string(route-target), '15525')
18-Jun-2019::13:38:17.871 get_elem(/vrf:vrf[device='xr-1'][vrf-name='foo']/ipv4/imports/route-target) = 12:34 15525:246 23:45
18-Jun-2019::13:38:17.871 result: /vrf:vrf[device='xr-1'][vrf-name='foo']/ipv4/imports: false

I'm trying to figure out if I'm doing something wrong.

As sanity check, I tested this statement:

 

must "starts-with(route-target, '12:34')";

This one works as expected.

So, for some reason, I'm unable to use the contains function, but some other functions are working as I'd expect.

 

Any thoughts?

 

Thanks!

1 Accepted Solution

Accepted Solutions

mvolf
Cisco Employee
Cisco Employee

contains() evaluates its argument as strings; route-target is a leaf-list I suppose, i.e. it returns a node-set, and a string evaluation of a node-set is the string value of its first node. You may want something like this instead:

must "route-target[contains(., '15525')]";

 

View solution in original post

4 Replies 4

mvolf
Cisco Employee
Cisco Employee

contains() evaluates its argument as strings; route-target is a leaf-list I suppose, i.e. it returns a node-set, and a string evaluation of a node-set is the string value of its first node. You may want something like this instead:

must "route-target[contains(., '15525')]";

 

That did it!

 

Thank you very much!

 

Would you mind describing the statement in words?

How come '.' is pointing where it does?

What does the statement returns? A Boolean value? The node itself?

 

Thanks again!

It returns a node-set which is then converted to boolean - non-empty set to true, empty to false. The result can be described as all instances of route-target such that ., the instance itself, as a string contains '15525'.

Thank you for the explanation!