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.tests)!: Update VXLAN tests #287

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions anta/tests/vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@
from anta.models import AntaCommand, AntaTest


class VerifyVxlan(AntaTest):
class VerifyVxlan1Interface(AntaTest):
carl-baillargeon marked this conversation as resolved.
Show resolved Hide resolved
"""
Verifies if Vxlan1 interface is configured, and is up/up
This test verifies if the Vxlan1 interface is configured and 'up/up'.

!!! warning
The name of this test has been updated from 'VerifyVxlan' for better representation.

Expected Results:
* success: The test will pass if the Vxlan1 interface is configured with line protocol status and interface status 'up'.
* failure: The test will fail if the Vxlan1 interface line protocol status or interface status are not 'up'.
* skipped: The test will be skipped if the Vxlan1 interface is not configured.
"""

name = "VerifyVxlan"
description = "Verifies Vxlan1 status"
name = "VerifyVxlan1Interface"
description = "This test verifies if the Vxlan1 interface is configured and 'up/up'."
categories = ["vxlan"]
commands = [AntaCommand(command="show interfaces description", ofmt="json")]

@AntaTest.anta_test
def test(self) -> None:
"""Run VerifyVxlan validation"""
"""
Run VerifyVxlan1Interface validation
"""

command_output = self.instance_commands[0].json_output

Expand All @@ -37,22 +47,29 @@ def test(self) -> None:

class VerifyVxlanConfigSanity(AntaTest):
"""
Verifies that there are no VXLAN config-sanity issues flagged
This test verifies that no issues are detected with the VXLAN configuration.

Expected Results:
* success: The test will pass if no issues are detected with the VXLAN configuration.
* failure: The test will fail if issues are detected with the VXLAN configuration.
* skipped: The test will be skipped if VXLAN is not configured on the device.
"""

name = "VerifyVxlanConfigSanity"
description = "Verifies VXLAN config-sanity"
description = "This test verifies that no issues are detected with the VXLAN configuration."
categories = ["vxlan"]
commands = [AntaCommand(command="show vxlan config-sanity", ofmt="json")]

@AntaTest.anta_test
def test(self) -> None:
"""Run VerifyVxlanConfigSanity validation"""
"""
Run VerifyVxlanConfigSanity validation
"""

command_output = self.instance_commands[0].json_output

if "categories" not in command_output or len(command_output["categories"]) == 0:
self.result.is_skipped("VXLAN is not configured on this device")
self.result.is_skipped("VXLAN is not configured")
return

failed_categories = {
Expand All @@ -62,6 +79,6 @@ def test(self) -> None:
}

if len(failed_categories) > 0:
self.result.is_failure(f"Vxlan config sanity check is not passing: {failed_categories}")
self.result.is_failure(f"VXLAN config sanity check is not passing: {failed_categories}")
else:
self.result.is_success()
2 changes: 1 addition & 1 deletion docs/api/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This section describes all the available tests provided by ANTA package.
- [Software](tests.software.md)
- [STP](tests.stp.md)
- [System](tests.system.md)
- [VxLAN](tests.vxlan.md)
- [VXLAN](tests.vxlan.md)



Expand Down
2 changes: 1 addition & 1 deletion docs/api/tests.vxlan.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ANTA catalog for VxLAN tests
# ANTA catalog for VXLAN tests

::: anta.tests.vxlan
options:
Expand Down
2 changes: 1 addition & 1 deletion examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ anta.tests.system:
- VerifyNTP:

anta.tests.vxlan:
- VerifyVxlan:
- VerifyVxlan1Interface:
- VerifyVxlanConfigSanity:

anta.tests.routing:
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ nav:
- STP: api/tests.stp.md
- Software: api/tests.software.md
- System: api/tests.system.md
- VxLAN: api/tests.vxlan.md
- VXLAN: api/tests.vxlan.md
- API Documentation:
- Inventory:
- Inventory module: api/inventory.md
Expand Down
4 changes: 2 additions & 2 deletions tests/units/anta_tests/vxlan/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
],
"side_effect": [],
"expected_result": "failure",
"expected_messages": ["Vxlan config sanity check is not passing: {'localVtep': {'description': 'Local VTEP Configuration Check', "
"expected_messages": ["VXLAN config sanity check is not passing: {'localVtep': {'description': 'Local VTEP Configuration Check', "
"'allCheckPass': False, 'detail': '', 'hasWarning': True, 'items': [{'name': 'Loopback IP Address', 'checkPass': True, "
"'hasWarning': False, 'detail': ''}, {'name': 'VLAN-VNI Map', 'checkPass': False, 'hasWarning': False, 'detail': "
"'No VLAN-VNI mapping in Vxlan1'}, {'name': 'Flood List', 'checkPass': False, 'hasWarning': True, 'detail': "
Expand All @@ -405,6 +405,6 @@
],
"side_effect": [],
"expected_result": "skipped",
"expected_messages": ["VXLAN is not configured on this device"]
"expected_messages": ["VXLAN is not configured"]
},
]
10 changes: 5 additions & 5 deletions tests/units/anta_tests/vxlan/test_exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

import pytest

from anta.tests.vxlan import VerifyVxlan, VerifyVxlanConfigSanity
from anta.tests.vxlan import VerifyVxlan1Interface, VerifyVxlanConfigSanity
from tests.lib.utils import generate_test_ids_list

from .data import INPUT_VXLAN_CONFIG_SANITY, INPUT_VXLAN_STATUS


@pytest.mark.parametrize("test_data", INPUT_VXLAN_STATUS, ids=generate_test_ids_list(INPUT_VXLAN_STATUS))
def test_VerifyVxlan(mocked_device: MagicMock, test_data: Any) -> None:
"""Check VerifyVxlan"""
def test_VerifyVxlan1Interface(mocked_device: MagicMock, test_data: Any) -> None:
"""Check VerifyVxlan1Interface"""

logging.info(f"Mocked device is: {mocked_device.host}")
logging.info(f"Mocked HW is: {mocked_device.hw_model}")

test = VerifyVxlan(mocked_device, eos_data=test_data["eos_data"])
test = VerifyVxlan1Interface(mocked_device, eos_data=test_data["eos_data"])
asyncio.run(test.test())
logging.info(f"test result is: {test.result}")

Expand All @@ -34,7 +34,7 @@ def test_VerifyVxlan(mocked_device: MagicMock, test_data: Any) -> None:

@pytest.mark.parametrize("test_data", INPUT_VXLAN_CONFIG_SANITY, ids=generate_test_ids_list(INPUT_VXLAN_CONFIG_SANITY))
def test_VerifyVxlanConfigSanity(mocked_device: MagicMock, test_data: Any) -> None:
"""Check VerifyVxlan"""
"""Check VerifyVxlanConfigSanity"""

logging.info(f"Mocked device is: {mocked_device.host}")
logging.info(f"Mocked HW is: {mocked_device.hw_model}")
Expand Down
Loading