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

feat(junos): improve _convert_to_set_commands #132

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

Frazew
Copy link
Contributor

@Frazew Frazew commented Jun 5, 2024

This is a proposed follow-up for #125 to make the parsing of set-based configurations more robust:

  • properly skip line comments
  • use self.options["negation"] instead of the hardcoded delete when checking if the line is already a "set" line
  • use the block indicators {/} instead of the indentation to build the configuration tree
  • various minor implementation details
    • split("\n") -> splitlines(): to handle different line breaks
    • replace(";", "") -> .rstrip(";"): rstrip feels safer in that it doesn't remove a semicolon appearing elsewhere in the line (not sure it could happen to have a string containing a semicolon but better safe than sorry?)
    • move if self.options["syntax_style"] == "juniper": out of the function to remove unnecessary indentation and improve readability

I believe relying on indentation as is currently done could lead to unexpected results (if the generated configuration is not perfectly indented for example) especially since the configuration format provides a way to traverse the tree using braces and doesn't rely on indentation to be parsed. This new implementation can also properly error out on invalid configuration (unterminated blocks / extra braces).

I'm curious to know if there was a specific reason I'm not seeing to use indentation instead of parsing the blocks directly?

@Frazew Frazew force-pushed the fhorta/improve-junos-set-conversion branch from 6a6b5a0 to 963650c Compare June 5, 2024 11:58
@jtdub jtdub self-requested a review September 19, 2024 13:38
Copy link
Contributor

@jtdub jtdub left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for your contribution!

@jtdub jtdub merged commit 32ee81f into netdevops:master Sep 19, 2024
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.

2 participants