2025-03-17 07:33:51 +01:00
|
|
|
# Copyright (c) 2023-2025 Arista Networks, Inc.
|
2025-02-05 11:32:35 +01:00
|
|
|
# Use of this source code is governed by the Apache License 2.0
|
|
|
|
# that can be found in the LICENSE file.
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Tests for anta.tests.vlan.py."""
|
|
|
|
|
2025-02-05 11:32:35 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
2025-03-17 07:33:51 +01:00
|
|
|
from anta.tests.vlan import VerifyDynamicVlanSource, VerifyVlanInternalPolicy
|
2025-02-05 11:54:55 +01:00
|
|
|
from tests.units.anta_tests import test
|
2025-02-05 11:32:35 +01:00
|
|
|
|
|
|
|
DATA: list[dict[str, Any]] = [
|
|
|
|
{
|
|
|
|
"name": "success",
|
|
|
|
"test": VerifyVlanInternalPolicy,
|
|
|
|
"eos_data": [{"policy": "ascending", "startVlanId": 1006, "endVlanId": 4094}],
|
|
|
|
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094},
|
|
|
|
"expected": {"result": "success"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "failure-incorrect-policy",
|
|
|
|
"test": VerifyVlanInternalPolicy,
|
|
|
|
"eos_data": [{"policy": "descending", "startVlanId": 4094, "endVlanId": 1006}],
|
|
|
|
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094},
|
2025-03-17 07:33:51 +01:00
|
|
|
"expected": {
|
|
|
|
"result": "failure",
|
|
|
|
"messages": ["Incorrect VLAN internal allocation policy configured - Expected: ascending Actual: descending"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "failure-incorrect-start-end-id",
|
|
|
|
"test": VerifyVlanInternalPolicy,
|
|
|
|
"eos_data": [{"policy": "ascending", "startVlanId": 4094, "endVlanId": 1006}],
|
|
|
|
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094},
|
2025-02-05 11:32:35 +01:00
|
|
|
"expected": {
|
|
|
|
"result": "failure",
|
|
|
|
"messages": [
|
2025-03-17 07:33:51 +01:00
|
|
|
"VLAN internal allocation policy: ascending - Incorrect start VLAN id configured - Expected: 1006 Actual: 4094",
|
|
|
|
"VLAN internal allocation policy: ascending - Incorrect end VLAN id configured - Expected: 4094 Actual: 1006",
|
2025-02-05 11:32:35 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-03-17 07:33:51 +01:00
|
|
|
{
|
|
|
|
"name": "success",
|
|
|
|
"test": VerifyDynamicVlanSource,
|
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1401]}, "vccbfd": {"vlanIds": [1501]}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False},
|
|
|
|
"expected": {"result": "success"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "failure-no-dynamic-vlan-sources",
|
|
|
|
"test": VerifyDynamicVlanSource,
|
|
|
|
"eos_data": [{"dynamicVlans": {}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False},
|
|
|
|
"expected": {"result": "failure", "messages": ["Dynamic VLAN source(s) not found in configuration: evpn, mlagsync"]},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "failure-dynamic-vlan-sources-mismatch",
|
|
|
|
"test": VerifyDynamicVlanSource,
|
|
|
|
"eos_data": [{"dynamicVlans": {"vccbfd": {"vlanIds": [1500]}, "mlagsync": {"vlanIds": [1501]}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False},
|
|
|
|
"expected": {
|
|
|
|
"result": "failure",
|
|
|
|
"messages": ["Dynamic VLAN source(s) not found in configuration: evpn"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "success-strict-mode",
|
|
|
|
"test": VerifyDynamicVlanSource,
|
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1502], "vccbfd": {"vlanIds": []}}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True},
|
|
|
|
"expected": {"result": "success"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "failure-all-sources-exact-match-additional-source-found",
|
|
|
|
"test": VerifyDynamicVlanSource,
|
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1500]}, "vccbfd": {"vlanIds": [1500]}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True},
|
|
|
|
"expected": {
|
|
|
|
"result": "failure",
|
|
|
|
"messages": ["Strict mode enabled: Unexpected sources have VLANs allocated: vccbfd"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "failure-all-sources-exact-match-expected-source-not-found",
|
|
|
|
"test": VerifyDynamicVlanSource,
|
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": []}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True},
|
|
|
|
"expected": {"result": "failure", "messages": ["Dynamic VLAN source(s) exist but have no VLANs allocated: mlagsync"]},
|
|
|
|
},
|
2025-02-05 11:32:35 +01:00
|
|
|
]
|