| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Tests for anta.tests.vlan.py.""" |
| 5 |
|
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
import sys |
| 9 |
from typing import TYPE_CHECKING, Any |
| 10 |
|
| 11 |
from anta.models import AntaTest |
| 12 |
from anta.result_manager.models import AntaTestStatus |
| 13 |
from anta.tests.vlan import VerifyDynamicVlanSource, VerifyVlanInternalPolicy, VerifyVlanStatus |
| 14 |
from tests.units.anta_tests import test |
| 15 |
|
| 16 |
if TYPE_CHECKING: |
| 17 |
from tests.units.anta_tests import AntaUnitTestData |
| 18 |
|
| 19 |
DATA: AntaUnitTestData = { |
| 20 |
(VerifyVlanInternalPolicy, "success"): { |
| 21 |
"eos_data": [{"policy": "ascending", "startVlanId": 1006, "endVlanId": 4094}], |
| 22 |
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094}, |
| 23 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 24 |
}, |
| 25 |
(VerifyVlanInternalPolicy, "failure-incorrect-policy"): { |
| 26 |
"eos_data": [{"policy": "descending", "startVlanId": 4094, "endVlanId": 1006}], |
| 27 |
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094}, |
| 28 |
"expected": { |
| 29 |
"result": AntaTestStatus.FAILURE, |
| 30 |
"messages": ["Incorrect VLAN internal allocation policy configured - Expected: ascending Actual: descending"], |
| 31 |
}, |
| 32 |
}, |
| 33 |
(VerifyVlanInternalPolicy, "failure-incorrect-start-end-id"): { |
| 34 |
"eos_data": [{"policy": "ascending", "startVlanId": 4094, "endVlanId": 1006}], |
| 35 |
"inputs": {"policy": "ascending", "start_vlan_id": 1006, "end_vlan_id": 4094}, |
| 36 |
"expected": { |
| 37 |
"result": AntaTestStatus.FAILURE, |
| 38 |
"messages": [ |
| 39 |
"VLAN internal allocation policy: ascending - Incorrect start VLAN id configured - Expected: 1006 Actual: 4094", |
| 40 |
"VLAN internal allocation policy: ascending - Incorrect end VLAN id configured - Expected: 4094 Actual: 1006", |
| 41 |
], |
| 42 |
}, |
| 43 |
}, |
| 44 |
(VerifyDynamicVlanSource, "success"): { |
| 45 |
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1401]}, "vccbfd": {"vlanIds": [1501]}}}], |
| 46 |
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False}, |
| 47 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 48 |
}, |
| 49 |
(VerifyDynamicVlanSource, "failure-no-dynamic-vlan-sources"): { |
| 50 |
"eos_data": [{"dynamicVlans": {}}], |
| 51 |
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False}, |
| 52 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dynamic VLAN source(s) not found in configuration: evpn, mlagsync"]}, |
| 53 |
}, |
| 54 |
(VerifyDynamicVlanSource, "failure-dynamic-vlan-sources-mismatch"): { |
| 55 |
"eos_data": [{"dynamicVlans": {"vccbfd": {"vlanIds": [1500]}, "mlagsync": {"vlanIds": [1501]}}}], |
| 56 |
"inputs": {"sources": ["evpn", "mlagsync"], "strict": False}, |
| 57 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dynamic VLAN source(s) not found in configuration: evpn"]}, |
| 58 |
}, |
| 59 |
(VerifyDynamicVlanSource, "success-strict-mode"): { |
| 60 |
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1502], "vccbfd": {"vlanIds": []}}}}], |
| 61 |
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True}, |
| 62 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 63 |
}, |
| 64 |
(VerifyDynamicVlanSource, "failure-all-sources-exact-match-additional-source-found"): { |
| 65 |
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": [1500]}, "vccbfd": {"vlanIds": [1500]}}}], |
| 66 |
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True}, |
| 67 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Strict mode enabled: Unexpected sources have VLANs allocated: vccbfd"]}, |
| 68 |
}, |
| 69 |
(VerifyDynamicVlanSource, "failure-all-sources-exact-match-expected-source-not-found"): { |
| 70 |
"eos_data": [{"dynamicVlans": {"evpn": {"vlanIds": [1199]}, "mlagsync": {"vlanIds": []}}}], |
| 71 |
"inputs": {"sources": ["evpn", "mlagsync"], "strict": True}, |
| 72 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dynamic VLAN source(s) exist but have no VLANs allocated: mlagsync"]}, |
| 73 |
}, |
| 74 |
(VerifyVlanStatus, "success"): { |
| 75 |
"eos_data": [ |
| 76 |
{ |
| 77 |
"vlans": { |
| 78 |
"1": {"name": "default", "dynamic": False, "status": "active", "interfaces": {}}, |
| 79 |
"4092": {"name": "VLAN4092", "dynamic": True, "status": "active", "interfaces": {}}, |
| 80 |
"4094": {"name": "VLAN4094", "dynamic": True, "status": "active", "interfaces": {}}, |
| 81 |
}, |
| 82 |
"sourceDetail": "", |
| 83 |
} |
| 84 |
], |
| 85 |
"inputs": {"vlans": [{"vlan_id": 4092, "status": "active"}, {"vlan_id": 4094, "status": "active"}]}, |
| 86 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 87 |
}, |
| 88 |
(VerifyVlanStatus, "failure-vlan-not-conifgured"): { |
| 89 |
"eos_data": [{"vlans": {"1": {"name": "default", "dynamic": False, "status": "active", "interfaces": {}}}, "sourceDetail": ""}], |
| 90 |
"inputs": {"vlans": [{"vlan_id": 4092, "status": "active"}, {"vlan_id": 4094, "status": "active"}]}, |
| 91 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["VLAN: Vlan4092 - Not configured", "VLAN: Vlan4094 - Not configured"]}, |
| 92 |
}, |
| 93 |
(VerifyVlanStatus, "failure-incorrect-status"): { |
| 94 |
"eos_data": [ |
| 95 |
{ |
| 96 |
"vlans": { |
| 97 |
"1": {"name": "default", "dynamic": False, "status": "active", "interfaces": {}}, |
| 98 |
"4092": {"name": "VLAN4092", "dynamic": True, "status": "suspended", "interfaces": {}}, |
| 99 |
"4094": {"name": "VLAN4094", "dynamic": True, "status": "active", "interfaces": {}}, |
| 100 |
}, |
| 101 |
"sourceDetail": "", |
| 102 |
} |
| 103 |
], |
| 104 |
"inputs": {"vlans": [{"vlan_id": 4092, "status": "active"}, {"vlan_id": 4094, "status": "suspended"}]}, |
| 105 |
"expected": { |
| 106 |
"result": AntaTestStatus.FAILURE, |
| 107 |
"messages": [ |
| 108 |
"VLAN: Vlan4092 - Incorrect administrative status - Expected: active Actual: suspended", |
| 109 |
"VLAN: Vlan4094 - Incorrect administrative status - Expected: suspended Actual: active", |
| 110 |
], |
| 111 |
}, |
| 112 |
}, |
| 113 |
} |