-
Notifications
You must be signed in to change notification settings - Fork 29
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(anta): Added test case to verify dynamic vlans source #978
base: main
Are you sure you want to change the base?
feat(anta): Added test case to verify dynamic vlans source #978
Conversation
CodSpeed Performance ReportMerging #978 will not alter performanceComparing Summary
|
29babe0
to
6651f5a
Compare
f4b60ad
to
66ce5b0
Compare
anta/tests/vlan.py
Outdated
* Failure: The test will fail if any of the following conditions is met: | ||
- The dynamic VLAN(s) are disabled on all designated sources, or active on non designated sources. | ||
- In strict mode, dynamic VLAN(s) are disabled on any of the designated sources. | ||
* Skipped: The test will Skip if the following conditions is met: |
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.
* Skipped: The test will Skip if the following conditions is met: | |
* Skipped: The test will skip if the following conditions is met: |
anta/tests/vlan.py
Outdated
class Input(AntaTest.Input): | ||
"""Input model for the VerifyDynamicVlanSource test.""" | ||
|
||
model_config = ConfigDict(extra="forbid") |
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.
model_config = ConfigDict(extra="forbid") |
Not needed here since it is already in the parent class AntaTest.Input
.
anta/tests/vlan.py
Outdated
source: list[DynamicVLANSource] | ||
"""The dynamic VLAN(s) source list.""" | ||
strict: bool = False | ||
"""If True, requires exact match of the provided dynamic VLAN(s) sources, Defaults to `False`""" |
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.
"""If True, requires exact match of the provided dynamic VLAN(s) sources, Defaults to `False`""" | |
"""If True, requires exact match of the provided dynamic VLAN(s) sources. Defaults to `False`.""" |
anta/custom_types.py
Outdated
@@ -238,3 +238,4 @@ def validate_regex(value: str) -> str: | |||
"Route Cache Route", | |||
"CBF Leaked Route", | |||
] | |||
DynamicVLANSource = Literal["dmf", "dot1x", "dynvtep", "evpn", "mlag", "mlagsync", "mvpn", "swfwd", "vccbfd"] |
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.
DynamicVLANSource = Literal["dmf", "dot1x", "dynvtep", "evpn", "mlag", "mlagsync", "mvpn", "swfwd", "vccbfd"] | |
DynamicVlanSource = Literal["dmf", "dot1x", "dynvtep", "evpn", "mlag", "mlagsync", "mvpn", "swfwd", "vccbfd"] |
anta/tests/vlan.py
Outdated
"""Input model for the VerifyDynamicVlanSource test.""" | ||
|
||
model_config = ConfigDict(extra="forbid") | ||
source: list[DynamicVLANSource] |
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.
source: list[DynamicVLANSource] | |
sources: list[DynamicVLANSource] |
anta/tests/vlan.py
Outdated
str_actual_source = ", ".join(actual_source) | ||
|
||
# If strict flag is True and dynamic VLAN(s) are disabled on any of the designated sources, test fails. | ||
if self.inputs.strict and sorted(actual_source) != (expected_source): |
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.
This could lead to false negatives if expected_source
is unsorted.
anta/tests/vlan.py
Outdated
class VerifyDynamicVlanSource(AntaTest): | ||
"""Verifies dynamic VLAN(s) source. | ||
This test performs the following checks for specified dynamic VLAN(s): | ||
1. Ensures that dynamic VLAN(s) are properly configured in the system. | ||
2. Confirms that dynamic VLAN(s) are enabled for any/all the designated sources and disabled for all others. | ||
3. When strict mode is enabled (`strict: true`): | ||
- Dynamic VLAN(s) are enabled for all designated sources. |
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.
Can you clarify the intent of the test?
It could be difficult for users to know which services will appear in the output. Also, a service (or source) being present in the dynamic VLANs output just means it's registered as a potential consumer and having no VLANs allocated (empty vlanIds
list) doesn't necessarily mean it's an issue. Example: EVPN being "activated" but showing an empty vlanIds
list is perfectly normal if it doesn't need any dynamic VLANs.
If the goal is to check that the provided services have dynamic VLANs registered, the test logic could be simplified a lot by looping over the input sources list, check if the source is present, if it is check if its vlanIds
list is not empty.
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 actual test criteria is If there are any dynamic VLANs, then these should only have source of "evpn" or "mlagsync" ie. all other sources must be "NONE"
.
We are taking the sources as input and providing an option for exact match. On the other hand, if strict is set to False(default option), the test will pass as long as the dynamic VLANs are assigned to any of the input sources.
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 in that case we need to update the docstring and logic to reflect this because, in my opinion, a service with an empty vlanIds
list doesn't mean it's not configured/enabled. It just means the service doesn't use any dynamic VLANs.
The test should pass if all provided source(s) have dynamic VLANs registered (vlanIds
not empty), if not, we just say there are no dynamic VLANs for the source(s) concerned. If strict is set, the test would fail if other sources (not provided by the user) have dynamic VLANs registered.
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.
Logic:
- Strict: False
- If all provided source(s) have dynamic VLANs registered, Test should pass
- If not then passing the test as there are no dynamic VLANs for the source(s) concerned.
- If dynamic vlans are assigned to sources other than provided, Test should fail.
- Strict: True
- If all provided source(s) have dynamic VLANs registered, Test should pass
- If not, Then test should fail saying dynamic vlans are not assigned to given sources.
- If dynamic vlans are assigned to sources other than provided, Test should fail.
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.
Apologies if I was not super clear. Here's what I have in mind:
- Strict: False
- If all provided source(s) have dynamic VLANs registered, test should pass.
- If not, then test should fail saying dynamic VLANs are not assigned to given sources.
- If dynamic VLANs are assigned to sources other than provided, test should pass (we don't care about other sources not provided by the user, we just explicity check the provided ones).
- Strict: True
- If all provided source(s) have dynamic VLANs registered, test should pass.
- If not, then test should fail saying dynamic VLANs are not assigned to given sources.
- If dynamic VLANs are assigned to sources other than provided, test should fail (we do care about other sources now, we are not expecting other dynamic VLANs on other sources).
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.
Thank you @carl-baillargeon for clarifying the additional context and explanation, makes things much clearer.
Quality Gate passedIssues Measures |
Description
This test performs the following checks for specified dynamic VLAN(s):
Fixes #864
Checklist:
pre-commit run
)tox -e testenv
)