2025-03-17 07:33:45 +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:38:32 +01:00
|
|
|
"""Tests for anta.tests.vlan.py."""
|
|
|
|
|
2025-02-05 11:32:35 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
import sys
|
|
|
|
from typing import TYPE_CHECKING, Any
|
2025-02-05 11:32:35 +01:00
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
from anta.models import AntaTest
|
|
|
|
from anta.result_manager.models import AntaTestStatus
|
|
|
|
from anta.tests.vlan import VerifyDynamicVlanSource, VerifyVlanInternalPolicy, VerifyVlanStatus
|
2025-02-05 11:54:23 +01:00
|
|
|
from tests.units.anta_tests import test
|
2025-02-05 11:32:35 +01:00
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from tests.units.anta_tests import AntaUnitTestDataDict
|
|
|
|
|
|
|
|
DATA: AntaUnitTestDataDict = {
|
|
|
|
(VerifyVlanInternalPolicy, "success"): {
|
2025-02-05 11:32:35 +01:00
|
|
|
"eos_data": [{"policy": "ascending", "startVlanId": 1006, "endVlanId": 4094}],
|
|
|
|
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyVlanInternalPolicy, "failure-incorrect-policy"): {
|
2025-02-05 11:32:35 +01:00
|
|
|
"eos_data": [{"policy": "descending", "startVlanId": 4094, "endVlanId": 1006}],
|
|
|
|
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094},
|
2025-03-17 07:33:45 +01:00
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-03-17 07:33:45 +01:00
|
|
|
"messages": ["Incorrect VLAN internal allocation policy configured - Expected: ascending Actual: descending"],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyVlanInternalPolicy, "failure-incorrect-start-end-id"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"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": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-02-05 11:32:35 +01:00
|
|
|
"messages": [
|
2025-03-17 07:33:45 +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-05-15 09:34:27 +02:00
|
|
|
(VerifyDynamicVlanSource, "success"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1401]}, "vccbfd": {"vlanIds": [1501]}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyDynamicVlanSource, "failure-no-dynamic-vlan-sources"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dynamicVlans": {}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dynamic VLAN source(s) not found in configuration: evpn, mlagsync"]},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyDynamicVlanSource, "failure-dynamic-vlan-sources-mismatch"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dynamicVlans": {"vccbfd": {"vlanIds": [1500]}, "mlagsync": {"vlanIds": [1501]}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dynamic VLAN source(s) not found in configuration: evpn"]},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyDynamicVlanSource, "success-strict-mode"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1502], "vccbfd": {"vlanIds": []}}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyDynamicVlanSource, "failure-all-sources-exact-match-additional-source-found"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1500]}, "vccbfd": {"vlanIds": [1500]}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Strict mode enabled: Unexpected sources have VLANs allocated: vccbfd"]},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyDynamicVlanSource, "failure-all-sources-exact-match-expected-source-not-found"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": []}}}],
|
|
|
|
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dynamic VLAN source(s) exist but have no VLANs allocated: mlagsync"]},
|
|
|
|
},
|
|
|
|
(VerifyVlanStatus, "success"): {
|
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vlans": {
|
|
|
|
"1": {"name": "default", "dynamic": False, "status": "active", "interfaces": {}},
|
|
|
|
"4092": {"name": "VLAN4092", "dynamic": True, "status": "active", "interfaces": {}},
|
|
|
|
"4094": {"name": "VLAN4094", "dynamic": True, "status": "active", "interfaces": {}},
|
|
|
|
},
|
|
|
|
"sourceDetail": "",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"inputs": {"vlans": [{"vlan_id": 4092, "status": "active"}, {"vlan_id": 4094, "status": "active"}]},
|
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
|
|
|
},
|
|
|
|
(VerifyVlanStatus, "failure-vlan-not-conifgured"): {
|
|
|
|
"eos_data": [{"vlans": {"1": {"name": "default", "dynamic": False, "status": "active", "interfaces": {}}}, "sourceDetail": ""}],
|
|
|
|
"inputs": {"vlans": [{"vlan_id": 4092, "status": "active"}, {"vlan_id": 4094, "status": "active"}]},
|
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["VLAN: Vlan4092 - Not configured", "VLAN: Vlan4094 - Not configured"]},
|
|
|
|
},
|
|
|
|
(VerifyVlanStatus, "failure-incorrect-status"): {
|
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vlans": {
|
|
|
|
"1": {"name": "default", "dynamic": False, "status": "active", "interfaces": {}},
|
|
|
|
"4092": {"name": "VLAN4092", "dynamic": True, "status": "suspended", "interfaces": {}},
|
|
|
|
"4094": {"name": "VLAN4094", "dynamic": True, "status": "active", "interfaces": {}},
|
|
|
|
},
|
|
|
|
"sourceDetail": "",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"inputs": {"vlans": [{"vlan_id": 4092, "status": "active"}, {"vlan_id": 4094, "status": "suspended"}]},
|
|
|
|
"expected": {
|
|
|
|
"result": AntaTestStatus.FAILURE,
|
|
|
|
"messages": [
|
|
|
|
"VLAN: Vlan4092 - Incorrect administrative status - Expected: active Actual: suspended",
|
|
|
|
"VLAN: Vlan4094 - Incorrect administrative status - Expected: suspended Actual: active",
|
|
|
|
],
|
|
|
|
},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|