Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect "default" behavior in nested groups #94

Open
vlisjak opened this issue Nov 24, 2022 · 6 comments
Open

Incorrect "default" behavior in nested groups #94

vlisjak opened this issue Nov 24, 2022 · 6 comments

Comments

@vlisjak
Copy link

vlisjak commented Nov 24, 2022

Text:

router isis LAB
 <some lines removed>
 flex-algo 128
  priority 100
  metric-type delay
  advertise-definition
  prefix-metric
 !

Template: note that I define "priority" 999 so it does not match

<group name="routing.isis.LAB" default="MISSING">
router isis LAB {{ _start_ |  _exact_ }}
 
 <group name="fa128" default="MISSING">
 flex-algo 128 {{ _start_ |  _exact_ }}
  priority {{ priority | equal('999') }}
  metric-type {{ metric_type | equal('delay') }}
  advertise-definition {{ advertise_definition | set('true') }}
  prefix-metric {{ prefix_metric | set('true') }}
 !{{ _end_ }}
 </group>
 
 <group name="LEFTOVER">
 {{ LEFTOVER | _line_ | joinmatches }}
 </group>

!{{ _end_ }}
</group>

Result is wrong, because all attributes processed after "priority" are also marked MISSING (although they are supposed to match)

            fa128:
              advertise_definition: MISSING
              metric_type: MISSING
              prefix_metric: MISSING
              priority: MISSING
@vlisjak
Copy link
Author

vlisjak commented Nov 24, 2022

Just figured that when I remove that "LEFTOVER" group, matching in "fa128" is correct!

<group name="routing.isis.LAB" default="MISSING">

 <group name="fa128" default="MISSING">
 flex-algo 128 {{ _start_ |  _exact_ }}
  priority {{ priority | equal('999') }}
  metric-type {{ metric_type | equal('delay') }}
  advertise-definition {{ advertise_definition | set('true') }}
  prefix-metric {{ prefix_metric | set('true') }}
 !{{ _end_ }}
 </group>

 ##<group name="LEFTOVER">
 ##{{ LEFTOVER | _line_ | joinmatches }}
 ##</group>

!{{ _end_ }}
</group>

Result now correct - only priority is marked MISSING:

        isis:
          LAB:
            fa128:
              advertise_definition: 'true'
              metric_type: delay
              prefix_metric: 'true'
              priority: MISSING

@vlisjak
Copy link
Author

vlisjak commented Nov 24, 2022

FYI - the aim is to detect anomalies in router configurations:

  • if some attribute is not found in the config, or the value is wrong -> mark it "MISSING"
  • if some line appears in the config, but it was not defined in the TTP template -> mark it "LEFTOVER"

(hence that final "LEFTOVER" group is needed)

@dmulyalin
Copy link
Owner

Thank for raising this issue, what version of ttp and python are you using?

@vlisjak
Copy link
Author

vlisjak commented Nov 24, 2022

Ubuntu VM:

  • ttp 0.9.0
  • Python 3.8.10

MAC laptop:

  • ttp 0.9.0
  • Python 3.10.6

Same behavior on both.

@vlisjak
Copy link
Author

vlisjak commented Nov 27, 2022

Denis, FYI: if I add LEFTOVER also within nested group "fa128", the results appear correct!

Like this:

<group name="routing.isis.LAB" default="MISSING">
router isis LAB {{ _start_ |  _exact_ }}

 <skip>

 <group name="fa128" default="MISSING">
 flex-algo 128 {{ _start_ | _exact_ }}
  priority {{ priority | equal('999') }}
  metric-type {{ metric_type | equal('delay') }}
  advertise-definition {{ advertise_definition | set('true') }}
  prefix-metric {{ prefix_metric | set('true') }}
  {{ LEFTOVER | _line_  | joinmatches }}
 !{{ _end_ }}
 </group>

 <skip>

 <group name="LEFTOVER">
 {{ LEFTOVER | _line_ | joinmatches }}
 </group>
!{{ _end_ }}
</group>

Result:
(note that other attributes after priority are now correctly recognized)

    config:
      hostname: MBRH4
      routing:
        isis:
          LAB:
            LEFTOVER:
            - LEFTOVER: address-family ipv4 unicast
            - LEFTOVER: ' metric-style wide'
            - LEFTOVER: ' metric-style wide level 2'
            - LEFTOVER: ' microloop avoidance segment-routing'
            - LEFTOVER: ' advertise passive-only'
            - LEFTOVER: ' advertise link attributes'
            - LEFTOVER: ' mpls traffic-eng level-2-only'
            - LEFTOVER: ' mpls traffic-eng router-id Loopback0'
            - LEFTOVER: ' spf-interval initial-wait 50 secondary-wait 50 maximum-wait
                3200'
            - LEFTOVER: ' segment-routing mpls sr-prefer'
            - LEFTOVER: interface Loopback0
            - <skip>
            fa128:
              LEFTOVER: priority 100
              advertise_definition: 'true'
              metric_type: delay
              prefix_metric: 'true'
              priority: MISSING
            instance_id: '680500'
            is_type: level-2-only
            log_adj_changes: 'true'
            lsp_inital_wait: '1'
            lsp_max_life: '65535'
            lsp_max_wait: '3200'
            lsp_refresh: '65000'
            lsp_second_wait: '50'
            net: 49.6805.0001.0010.0100.1064.00
            ol_bit: '120'

So it is a workaround, but my goal was to consolidate all LEFTOVERs in top-level groups. Whereas now the LEFTOVERs must be distributed across all nested groups (which is less convenient from user/operational standpoint)

dmulyalin added a commit that referenced this issue Dec 3, 2022
@dmulyalin
Copy link
Owner

Added fix, could you try installing TTP from master branch and testing it:

python -m pip install git+https://github.com/dmulyalin/ttp

need to have git installed on the system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants