8000 feat(anta.tests): Enhanced VerifyRunningConfigLines Test Case for multiple matches by geetanjalimanegslab · Pull Request #1169 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(anta.tests): Enhanced VerifyRunningConfigLines Test Case for multiple matches #1169

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

geetanjalimanegslab
Copy link
Collaborator
@geetanjalimanegslab geetanjalimanegslab commented Apr 15, 2025

Description

Enhanced VerifyRunningConfigLines Test Case for multiple matches

Fixes #1134

Inputs:

  - VerifyRunningConfigLines:
      # Verifies the given regular expression patterns are present in the running-config.
      # Check specific sections
      sections:
        - section: router bgp 65101
          regex_patterns:
            - neighbor 10.111.1.0 peer group SPINE
            - router-id 10.111.254.1
        - section: interface ethernet1
          regex_patterns:
            - switchport mode trunk
      # Check the full config
      regex_patterns:
        - "^enable password.*$"
        - "bla bla"

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

Copy link
codspeed-hq bot commented Apr 15, 2025

CodSpeed Performance Report

Merging #1169 will not alter performance

Comparing geetanjalimanegslab:issue_1134_run_config (234796a) with main (6890d3f)

Summary

✅ 26 untouched benchmarks

@geetanjalimanegslab geetanjalimanegslab marked this pull request as ready for review April 17, 2025 11:52
categories: ClassVar[list[str]] = ["configuration"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show running-config", ofmt="text")]

class Input(AntaTest.Input):
"""Input model for the VerifyRunningConfigLines test."""

regex_patterns: list[RegexString]
"""List of regular expressions."""
sections: list[RunningConfigSection] = Field(default=[])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change the default to an empty list? We usually use None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi, @carl-baillargeon

The reason behind this choice is to help reduce cognitive complexity. If we were to use None as the default, we would need to add additional conditional checks to verify whether inputs.sections and regex_patterns are provided before using them. This would require extra if statements, particularly before iterating, to avoid errors when attempting to loop over a None value..

By defaulting to an empty list, we can simplify the logic and avoid unnecessary checks.
Please feel free to correct me if I’m mistaken, or share your thoughts—I'm happy to consider any suggestions or improvements.

Thanks! Geetanjali

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I understand the reason but we should still use None to be consistent with other tests. Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed @carl-baillargeon, updated test with default value as None

Thanks!

1. section: router bgp 65101, regex_patterns: router-id 10.111.254.1
2. section: router isis 1 regex_patterns: address-family ipv4 unicast
"""
regex_patterns: list[RegexString] = Field(default=[])
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

else:
self.result.is_failure("Following patterns were not found: " + ", ".join(failure_msgs))
re_search = re.compile(pattern, re.IGNORECASE | re.MULTILINE)
if not re_search.search(self.instance_commands[0].text_output):
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of calling self.instance_commands[0].text_output everytime, you should assign this to a running_config variable outside of the loops.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated Thanks

Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link

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.

Enhance VerifyRunningConfigLines Test Case for multiple matches
2 participants
0