-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: main
Are you sure you want to change the base?
feat(anta.tests): Enhanced VerifyRunningConfigLines Test Case for multiple matches #1169
Conversation
CodSpeed Performance ReportMerging #1169 will not alter performanceComparing Summary
|
0b31ffc
to
7423c24
Compare
anta/tests/configuration.py
Outdated
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=[]) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
anta/tests/configuration.py
Outdated
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=[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
anta/tests/configuration.py
Outdated
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated Thanks
fd48e94
to
086f1ae
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
|
Description
Enhanced VerifyRunningConfigLines Test Case for multiple matches
Fixes #1134
Inputs:
Checklist:
pre-commit run
)tox -e testenv
)