Skip to content

Conversation

@jtdub
Copy link
Contributor

@jtdub jtdub commented Dec 19, 2024

In [1]: from hier_config import WorkflowRemediation, get_hconfig, Platform

In [3]: running_config_text = """
   ...: prefix-set ALL
   ...:   0.0.0.0/0 eq 32
   ...: end-set
   ...: !
   ...: prefix-set PEERINGS
   ...:   1.1.1.1/32,
   ...:   2.2.2.2/32,
   ...:   10.0.1.0/24,
   ...:   172.16.0.0/12,
   ...:   192.168.3.0/26
   ...: end-set
   ...: """
   
   In [4]: generated_config_text = """
   ...: prefix-set ALL
   ...:   0.0.0.0/0 eq 32
   ...: end-set
   ...: !
   ...: prefix-set PEERINGS
   ...:   1.1.1.1/32,
   ...:   172.16.0.0/12,
   ...:   192.168.3.0/26
   ...: end-set
   ...: """
   
   In [5]: running_config = get_hconfig(Platform.CISCO_XR, running_config_text)
   ...: generated_config = get_hconfig(Platform.CISCO_XR, generated_config_text)

In [6]: workflow = WorkflowRemediation(running_config, generated_config)

In [7]: print(workflow.remediation_config)
prefix-set PEERINGS
  1.1.1.1/32,
  172.16.0.0/12,
  192.168.3.0/26
end-set

In [8]: pfx = running_config.get_child(equals="prefix-set ALL")
   ...: pfx.sectional_exit_text_parent_level
Out[8]: True

Closes #130

@jtdub jtdub requested a review from aedwardstx December 19, 2024 01:28
@jtdub jtdub self-assigned this Dec 19, 2024
@jtdub jtdub marked this pull request as draft December 19, 2024 01:28
@jtdub jtdub changed the title add ability to set sectional exit text at the parent level POC | Sectional Exiting at Parent Level Dec 19, 2024
@jtdub jtdub force-pushed the sectional_exit_parent_level branch from a37b7d2 to dafc47a Compare January 17, 2026 17:27
@jtdub jtdub changed the title POC | Sectional Exiting at Parent Level Sectional Exiting at Parent Level Jan 17, 2026
@jtdub jtdub marked this pull request as ready for review January 17, 2026 17:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes issue #130 by implementing support for sectional exit text at the parent indentation level in Cisco XR configurations. The issue reported that commands like end-set, end-policy, and similar exit statements were being incorrectly indented in diff output when they should appear at the parent level (no indentation).

Changes:

  • Added exit_text_parent_level boolean field to SectionalExitingRule model to control exit text indentation behavior
  • Implemented sectional_exit_text_parent_level property in HConfigChild to check if a node's exit text should be at parent level
  • Updated lines() method to adjust indentation depth when generating exit text based on the parent level flag
  • Configured 7 Cisco XR sectional exiting rules to use parent-level exit text (route-policy, prefix-set, policy-map, class-map, community-set, extcommunity-set, template)
  • Added comprehensive test coverage for the new functionality

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
hier_config/models.py Added exit_text_parent_level field to SectionalExitingRule with default value False
hier_config/child.py Added sectional_exit_text_parent_level property and updated lines() method to adjust indentation depth for exit text
hier_config/platforms/cisco_xr/driver.py Configured 7 sectional exiting rules with exit_text_parent_level=True for Cisco XR constructs that require unindented exit text
tests/test_hier_config.py Added comprehensive unit tests for sectional_exit_text_parent_level property and HConfigChildren methods
tests/test_driver_cisco_xr.py Added integration tests verifying correct indentation behavior for all Cisco XR sectional exiting rules

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"prefix-set TEST_PREFIX",
" 192.0.2.0/24",
"end-set",
)
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case that verifies the specific remediation scenario described in issue #130. The test should:

  1. Create a running config with a prefix-set containing multiple entries
  2. Create a generated config with the same prefix-set but with some entries removed
  3. Generate the remediation config using config_to_get_to
  4. Verify that the remediation config outputs with 'end-set' at the parent level (no indentation)

This would directly test the fix for the reported issue where the diff output was incorrectly indenting 'end-set'.

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

IOS XR end-set should not be indented

2 participants