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(anta): Added test case to verify dynamic vlans source #978

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

Conversation

geetanjalimanegslab
Copy link
Collaborator

@geetanjalimanegslab geetanjalimanegslab commented Dec 24, 2024

Description

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 on all the designated sources.
  3. When strict mode is enabled (`strict: true`):
    - The dynamic VLAN(s) are enabled on all the designated sources and disabled for non designated sources.

Expected Results
----------------
* Success: The test will pass if all of the following conditions are met:
    - The dynamic VLAN(s) are properly configured in the system.
    - The dynamic VLAN(s) are enabled for all of the designated sources.
    - In strict mode, The dynamic VLAN(s) are enabled on all the designated sources and disabled for non designated sources.
* Failure: The test will fail if any of the following conditions is met:
    - The dynamic VLAN(s) are disabled on any of designated sources.
    - In strict mode, dynamic VLAN(s) are disabled on any of the designated sources. or enabled for non designated sources.
* Skipped: The test will skip if the following conditions is met:
    - Dynamic VLAN(s) are not configured on the device.       

Fixes #864

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)

@geetanjalimanegslab geetanjalimanegslab changed the title Issue_864:Added test case to verify dynamic vlans source feat(anta)::Added test case to verify dynamic vlans source Dec 24, 2024
@geetanjalimanegslab geetanjalimanegslab changed the title feat(anta)::Added test case to verify dynamic vlans source feat(anta):Added test case to verify dynamic vlans source Dec 24, 2024
@geetanjalimanegslab geetanjalimanegslab changed the title feat(anta):Added test case to verify dynamic vlans source feat(anta): Added test case to verify dynamic vlans source Dec 24, 2024
Copy link

codspeed-hq bot commented Dec 24, 2024

CodSpeed Performance Report

Merging #978 will not alter performance

Comparing geetanjalimanegslab:test_dynamic_vlans (d547c26) with main (1f033f4)

Summary

✅ 22 untouched benchmarks

anta/tests/vlan.py Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
tests/units/anta_tests/test_vlan.py Outdated Show resolved Hide resolved
tests/units/anta_tests/test_vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
anta/tests/vlan.py Outdated Show resolved Hide resolved
@vitthalmagadum vitthalmagadum marked this pull request as ready for review January 7, 2025 09:48
* 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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Skipped: The test will Skip if the following conditions is met:
* Skipped: The test will skip if the following conditions is met:

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

model_config = ConfigDict(extra="forbid")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
model_config = ConfigDict(extra="forbid")

Not needed here since it is already in the parent class AntaTest.Input.

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`"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""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`."""

@@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DynamicVLANSource = Literal["dmf", "dot1x", "dynvtep", "evpn", "mlag", "mlagsync", "mvpn", "swfwd", "vccbfd"]
DynamicVlanSource = Literal["dmf", "dot1x", "dynvtep", "evpn", "mlag", "mlagsync", "mvpn", "swfwd", "vccbfd"]

"""Input model for the VerifyDynamicVlanSource test."""

model_config = ConfigDict(extra="forbid")
source: list[DynamicVLANSource]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
source: list[DynamicVLANSource]
sources: list[DynamicVLANSource]

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):
Copy link
Contributor

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.

Comment on lines 75 to 83
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.
Copy link
Contributor

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.

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Logic:

  1. 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.
  1. 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.

Copy link
Contributor

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:

  1. 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).
  1. 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).

Copy link
Collaborator

@vitthalmagadum vitthalmagadum Jan 8, 2025

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.

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.

Add the test case to verify dynamic vlans
3 participants