Skip to content

Generic

ANTA catalog for routing-generic tests

Generic routing test functions

verify_bfd(device, result) async

Verifies there is no BFD peer in down state (all VRF, IPv4 neighbors).

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if routing-table size is OK
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/generic.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
@anta_test
async def verify_bfd(device: InventoryDevice, result: TestResult) -> TestResult:
    """
    Verifies there is no BFD peer in down state (all VRF, IPv4 neighbors).

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if routing-table size is OK
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(command="show bfd peers", ofmt="json")
    logger.debug(f"query result is: {response}")
    has_failed: bool = False
    for vrf in response["vrfs"]:
        for neighbor in response["vrfs"][vrf]["ipv4Neighbors"]:
            for interface in response["vrfs"][vrf]["ipv4Neighbors"][neighbor][
                "peerStats"
            ]:
                if (
                    response["vrfs"][vrf]["ipv4Neighbors"][neighbor]["peerStats"][
                        interface
                    ]["status"]
                    != "up"
                ):
                    intf_state = response["vrfs"][vrf]["ipv4Neighbors"][neighbor][
                        "peerStats"
                    ][interface]["status"]
                    intf_name = response["vrfs"][vrf]["ipv4Neighbors"][neighbor][
                        "peerStats"
                    ][interface]
                    has_failed = True
                    result.is_failure(
                        f"bfd state on interface {intf_name} is {intf_state} (expected up)"
                    )
    if has_failed is False:
        result.is_success()

    return result

verify_routing_protocol_model(device, result, model='multi-agent') async

Verifies the configured routing protocol model is the one we expect. And if there is no mismatch between the configured and operating routing protocol model.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
model(str)

Expected routing protocol model (multi-agent or ribd). Default is multi-agent

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if the test model parameter is missing
TestResult
  • result = “success” if routing model is well configured
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/generic.py
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
@anta_test
async def verify_routing_protocol_model(
    device: InventoryDevice, result: TestResult, model: str = "multi-agent"
) -> TestResult:

    """
    Verifies the configured routing protocol model is the one we expect.
    And if there is no mismatch between the configured and operating routing protocol model.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        model(str): Expected routing protocol model (multi-agent or ribd). Default is multi-agent

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if the test `model` parameter is missing
        * result = "success" if routing model is well configured
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    if not model:
        result.is_skipped(
            "verify_routing_protocol_model was not run as no model was given"
        )
        return result

    response = await device.session.cli(
        command={"cmd": "show ip route summary", "revision": 3}, ofmt="json"
    )
    logger.debug(f"query result is: {response}")
    configured_model = response["protoModelStatus"]["configuredProtoModel"]
    operating_model = response["protoModelStatus"]["operatingProtoModel"]
    if configured_model == operating_model == model:
        result.is_success()
    else:
        result.is_failure(
            f"routing model is misconfigured: configured:{configured_model} - "
            f"operating:{operating_model} - expected:{model} "
        )

    return result

verify_routing_table_size(device, result, minimum, maximum) async

Verifies the size of the IP routing table (default VRF). Should be between the two provided thresholds.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
minimum(int)

Expected minimum routing table (default VRF) size.

required
maximum(int)

Expected maximum routing table (default VRF) size.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if the test minimum or maximum parameters are missing
TestResult
  • result = “success” if routing-table size is correct
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/routing/generic.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@anta_test
async def verify_routing_table_size(
    device: InventoryDevice, result: TestResult, minimum: int, maximum: int
) -> TestResult:
    """
    Verifies the size of the IP routing table (default VRF).
    Should be between the two provided thresholds.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        minimum(int): Expected minimum routing table (default VRF) size.
        maximum(int): Expected maximum routing table (default VRF) size.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if the test `minimum` or `maximum` parameters are missing
        * result = "success" if routing-table size is correct
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    if not minimum or not maximum:
        result.is_skipped(
            "verify_routing_table_size was not run as no "
            "minimum or maximum were given"
        )
        return result
    response = await device.session.cli(
        command={"cmd": "show ip route summary", "revision": 3}, ofmt="json"
    )
    logger.debug(f"query result is: {response}")
    total_routes = int(response["vrfs"]["default"]["totalRoutes"])
    if minimum <= total_routes <= maximum:
        result.is_success()
    else:
        result.is_failure(
            f"routing-table has {total_routes} routes and not between min ({minimum}) and maximum ({maximum})"
        )

    return result

Last update: September 5, 2022