summaryrefslogtreecommitdiffstats
path: root/anta/tests/greent.py
blob: b7632422bb33c0d0effaece6a384467399adb2c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Module related to GreenT (Postcard Telemetry) tests."""

from __future__ import annotations

from typing import TYPE_CHECKING, ClassVar

from anta.models import AntaCommand, AntaTest

if TYPE_CHECKING:
    from anta.models import AntaTemplate


class VerifyGreenTCounters(AntaTest):
    """Verifies if the GreenT (GRE Encapsulated Telemetry) counters are incremented.

    Expected Results
    ----------------
    * Success: The test will pass if the GreenT counters are incremented.
    * Failure: The test will fail if the GreenT counters are not incremented.

    Examples
    --------
    ```yaml
    anta.tests.greent:
      - VerifyGreenT:
    ```
    """

    name = "VerifyGreenTCounters"
    description = "Verifies if the GreenT counters are incremented."
    categories: ClassVar[list[str]] = ["greent"]
    commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show monitor telemetry postcard counters", revision=1)]

    @AntaTest.anta_test
    def test(self) -> None:
        """Main test function for VerifyGreenTCounters."""
        command_output = self.instance_commands[0].json_output

        if command_output["grePktSent"] > 0:
            self.result.is_success()
        else:
            self.result.is_failure("GreenT counters are not incremented")


class VerifyGreenT(AntaTest):
    """Verifies if a GreenT (GRE Encapsulated Telemetry) policy other than the default is created.

    Expected Results
    ----------------
    * Success: The test will pass if a GreenT policy is created other than the default one.
    * Failure: The test will fail if no other GreenT policy is created.

    Examples
    --------
    ```yaml
    anta.tests.greent:
      - VerifyGreenTCounters:
    ```
    """

    name = "VerifyGreenT"
    description = "Verifies if a GreenT policy is created."
    categories: ClassVar[list[str]] = ["greent"]
    commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show monitor telemetry postcard policy profile", revision=1)]

    @AntaTest.anta_test
    def test(self) -> None:
        """Main test function for VerifyGreenT."""
        command_output = self.instance_commands[0].json_output

        profiles = [profile for profile in command_output["profiles"] if profile != "default"]

        if profiles:
            self.result.is_success()
        else:
            self.result.is_failure("No GreenT policy is created")