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

Foreach in own tag fails while in-tag doesn't

u.avsec
Spotlight
Spotlight

Hi,
I stumbled into a situation I can't explain to myself:

<?foreach {/ce-pe-port/static/customer-routes}?>
    <ip-route-forwarding-list>
        <prefix>{customer-prefix}</prefix>
        <mask>{customer-prefix-mask}</mask>
        <forwarding-address>{customer-prefix-nh}</forwarding-address>
    </ip-route-forwarding-list>
<?end?>

This fails on packages reload with `Invalid parameters for processing instruction foreach`.

This on the other hand:

<ip-route-forwarding-list foreach="{/ce-pe-port/static/customer-routes}">
    <prefix>{customer-prefix}</prefix>
    <mask>{customer-prefix-mask}</mask>
    <forwarding-address>{customer-prefix-nh}</forwarding-address>
</ip-route-forwarding-list>

Works just fine.

Model in question is `/container/container/list`. Between the two containers there is a choice and case and the list has a 3 part combined key of "customer-prefix*" nodes seen in the example.

I'm really curious what is going on here. NSO version is 5.8.7.

Thanks

2 Replies 2

hazad
Cisco Employee
Cisco Employee

What does your yang models look like? I don't get the error when I use the following template:

<config-template xmlns="http://tail-f.com/ns/config/1.0" servicepoint="template-service-servicepoint">
  <test xmlns="http://com/example/templateservice">
  <?foreach {/ce-pe-port/static/customer-routes}?>
    <ip-route-forwarding-list>
      <prefix>{customer-prefix}</prefix>
      <mask>{customer-prefix-mask}</mask>
      <forwarding-address>{customer-prefix-nh}</forwarding-address>
    </ip-route-forwarding-list>
  <?end?>
  </test>
</config-template>

 And the following yang:

container test {
    list ip-route-forwarding-list {
      key "prefix mask forwarding-address";
      leaf prefix {
        type string;
      }
      leaf mask {
        type string;
      }
      leaf forwarding-address {
        type string;
      }
    }

  }

  list template-service {
    key name;
    leaf name {
      type string;
    }

    container ce-pe-port {
      container static {
        list customer-routes {
          key "customer-prefix customer-prefix-mask customer-prefix-nh";
          leaf customer-prefix {
            type string; 
          }
          leaf customer-prefix-mask {
            type string;
          }
          leaf customer-prefix-nh {
            type string;
          }
        }
      }
    }

    uses ncs:service-data;
    ncs:servicepoint template-service-servicepoint;
  }

The template works as expected:

admin@ncs% commit dry-run 
cli {
    local-node {
        data  test {
             +    ip-route-forwarding-list a b c {
             +    }
             +    ip-route-forwarding-list d e f {
             +    }
              }
             +template-service test {
             +    ce-pe-port {
             +        static {
             +            customer-routes a b c;
             +            customer-routes d e f;
             +        }
             +    }
             +}
    }
}

Hey,

thanks for trying to look into this.

A string of things happened in an interesting way:

Unfortunately there was a typo in the templates; it is not ce-pe-port but ce-pe-prot in the actual model.

Why stuff above works partially is interesting though. The stand-alone foreach is evaluated by the NSO while the in-tag foreach isn't. The xpath was wrong in both cases but packages reload failed only in first case.

Now, the reason I didn't spot the prot/port typo initially is due to the fact that the NSO actually loops without the need for the foreach in this case. So it went like this:

  1. Trying stand-alone foreach -> package reload fails
  2. Trying same faulty xpath with in-tag foreach -> package reload succeeds
  3. Run test instance -> configuration is actually generated
    1. Foreach actually failed because of faulty xpath
    2. NSO looped through the list data automatically anyway based on the xpath in <prefix></prefix>

 

Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?