Skip to content

Commit

Permalink
Issue_864: Updated docstrings and variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
Geetanjali Mane authored and Geetanjali Mane committed Dec 31, 2024
1 parent d776eaf commit f4b60ad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
41 changes: 21 additions & 20 deletions anta/tests/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,25 @@ class VerifyDynamicVlanSource(AntaTest):
This test performs the following checks for each specified dynamic VLAN:
1. Ensures that dynamic VLAN(s) are properly configured in the system.
2. Confirms that dynamic VLAN(s) are active only within their designated sources.
1. Ensures that dynamic VLAN(s) are properly configured in the system.
2. Confirms that dynamic VLAN(s) are active for any of the designated sources.
3. When strict mode is enabled (`strict: true`):
- Dynamic VLAN(s) are activated for all the designated sources.
4. Confirms that the dynamic VLAN(s) are disabled for other than designated sources.
Expected Results
----------------
*Success: The test will pass if all of the following conditions are met:
1. Dynamic VLAN(s) are properly configured in the system.
2. Dynamic VLAN(s) are active only within their designated sources.
*Failure: The test will fail if any of the following conditions is met:
1. Dynamic VLAN(s) are not active within the designated source
2. Dynamic VLAN(s) are activated in other than designated sources.
*Skipped: The test will Skip if the following conditions is met:
1. Dynamic VLAN(s) are not configured on the device.
* Success: The test will pass if all of the following conditions are met:
- Dynamic VLAN(s) are properly configured in the system.
- Dynamic VLAN(s) are active for any of the designated sources.
- In strict mode, Dynamic Vlans(s) are active for all the designated sources.
- Dynamic VLAN(s) are disabled for other than designated sources.
* Failure: The test will fail if any of the following conditions is met:
- Dynamic VLAN(s) are not active within the designated source
- Dynamic VLAN(s) are active for other than designated sources.
- In strict mode, dynamic VLAN(s) are disabled for any of the designated sources.
* Skipped: The test will Skip if the following conditions is met:
- Dynamic VLAN(s) are not configured on the device.
Examples
--------
Expand All @@ -104,7 +105,7 @@ class VerifyDynamicVlanSource(AntaTest):
source:
- evpn
- mlagsync
all_source_dynamic_vlans: False
strict: False
```
"""

Expand All @@ -117,8 +118,8 @@ class Input(AntaTest.Input):
model_config = ConfigDict(extra="forbid")
source: list[DynamicVLANSource]
"""The dynamic VLAN source list."""
all_source_dynamic_vlans: bool = False
"""Flag to check that all designated sources should have dynamic VLAN(s), Defaults to `False`"""
strict: bool = False
"""If True, requires exact match of the provided dynamic VLAN sources, Defaults to `False`"""

@AntaTest.anta_test
def test(self) -> None:
Expand All @@ -137,8 +138,8 @@ def test(self) -> None:
str_expected_source = ", ".join(expected_source)
str_actual_source = ", ".join(actual_source)

# If all designated source should have dynamic VLAN(s)
if self.inputs.all_source_dynamic_vlans and sorted(actual_source) != (expected_source):
# If strict flag is True and not all designated source have dynamic VLAN(s), test fails.
if self.inputs.strict and sorted(actual_source) != (expected_source):
self.result.is_failure(f"Dynamic VLAN(s) all source are not in {str_expected_source} Actual: {str_actual_source}")
return

Expand Down
2 changes: 1 addition & 1 deletion examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ anta.tests.vlan:
source:
- evpn
- mlagsync
all_source_dynamic_vlans: False
strict: False
- VerifyVlanInternalPolicy:
# Verifies the VLAN internal allocation policy and the range of VLANs.
policy: ascending
Expand Down
16 changes: 8 additions & 8 deletions tests/units/anta_tests/test_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,56 @@
"name": "success-any-source-match",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": []}}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": False},
"inputs": {"source": ["evpn", "mlagsync"], "strict": False},
"expected": {"result": "success"},
},
{
"name": "success-all-source-match",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1500]}}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": False},
"inputs": {"source": ["evpn", "mlagsync"], "strict": False},
"expected": {"result": "success"},
},
{
"name": "failure-no-dynamic-vlans",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": False},
"inputs": {"source": ["evpn", "mlagsync"], "strict": False},
"expected": {"result": "skipped", "messages": ["Dynamic VLANs are not configured"]},
},
{
"name": "failure-dynamic-vlan-source-invalid",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {"vccbfd": {"vlanIds": [1500]}, "mlagsync": {"vlanIds": [1501]}}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": False},
"inputs": {"source": ["evpn", "mlagsync"], "strict": False},
"expected": {"result": "failure", "messages": ["Dynamic VLAN(s) source are not in evpn, mlagsync Actual: vccbfd, mlagsync"]},
},
{
"name": "failure-any-source-match-additional-source-found",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1501]}, "vccbfd": {"vlanIds": [1500]}}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": False},
"inputs": {"source": ["evpn", "mlagsync"], "strict": False},
"expected": {"result": "failure", "messages": ["Dynamic VLAN(s) source are not in evpn, mlagsync Actual: evpn, mlagsync, vccbfd"]},
},
{
"name": "success-all-source-exact-match",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1502]}}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": True},
"inputs": {"source": ["evpn", "mlagsync"], "strict": True},
"expected": {"result": "success"},
},
{
"name": "failure-all-source-exact-match-additional-source-found",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1500]}, "vccbfd": {"vlanIds": [1500]}}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": True},
"inputs": {"source": ["evpn", "mlagsync"], "strict": True},
"expected": {"result": "failure", "messages": ["Dynamic VLAN(s) all source are not in evpn, mlagsync Actual: evpn, mlagsync, vccbfd"]},
},
{
"name": "failure-all-source-exact-match-expected-source-not-found",
"test": VerifyDynamicVlanSource,
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": []}}}],
"inputs": {"source": ["evpn", "mlagsync"], "all_source_dynamic_vlans": True},
"inputs": {"source": ["evpn", "mlagsync"], "strict": True},
"expected": {"result": "failure", "messages": ["Dynamic VLAN(s) all source are not in evpn, mlagsync Actual: evpn"]},
},
]

0 comments on commit f4b60ad

Please sign in to comment.