Skip to content

VLAN

ANTA catalog for vlan tests

Test functions related to VLAN

VerifyVlanInternalPolicy

Bases: AntaTest

This class checks if the VLAN internal allocation policy is ascending or descending and if the VLANs are within the specified range.

Expected Results
  • Success: The test will pass if the VLAN internal allocation policy is either ascending or descending and the VLANs are within the specified range.
  • Failure: The test will fail if the VLAN internal allocation policy is neither ascending nor descending or the VLANs are outside the specified range.
Source code in anta/tests/vlan.py
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
class VerifyVlanInternalPolicy(AntaTest):
    """
    This class checks if the VLAN internal allocation policy is ascending or descending and
    if the VLANs are within the specified range.

    Expected Results:
      * Success: The test will pass if the VLAN internal allocation policy is either ascending or descending
                 and the VLANs are within the specified range.
      * Failure: The test will fail if the VLAN internal allocation policy is neither ascending nor descending
                 or the VLANs are outside the specified range.
    """

    name = "VerifyVlanInternalPolicy"
    description = "This test checks the VLAN internal allocation policy and the range of VLANs."
    categories = ["vlan"]
    commands = [AntaCommand(command="show vlan internal allocation policy")]

    class Input(AntaTest.Input):
        """Inputs for the VerifyVlanInternalPolicy test."""

        policy: Literal["ascending", "descending"]
        """The VLAN internal allocation policy."""
        start_vlan_id: Vlan
        """The starting VLAN ID in the range."""
        end_vlan_id: Vlan
        """The ending VLAN ID in the range."""

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

        keys_to_verify = ["policy", "startVlanId", "endVlanId"]
        actual_policy_output = {key: get_value(command_output, key) for key in keys_to_verify}
        expected_policy_output = {"policy": self.inputs.policy, "startVlanId": self.inputs.start_vlan_id, "endVlanId": self.inputs.end_vlan_id}

        # Check if the actual output matches the expected output
        if actual_policy_output != expected_policy_output:
            failed_log = "The VLAN internal allocation policy is not configured properly:"
            failed_log += get_failed_logs(expected_policy_output, actual_policy_output)
            self.result.is_failure(failed_log)
        else:
            self.result.is_success()

Input

Bases: Input

Inputs for the VerifyVlanInternalPolicy test.

Source code in anta/tests/vlan.py
35
36
37
38
39
40
41
42
43
class Input(AntaTest.Input):
    """Inputs for the VerifyVlanInternalPolicy test."""

    policy: Literal["ascending", "descending"]
    """The VLAN internal allocation policy."""
    start_vlan_id: Vlan
    """The starting VLAN ID in the range."""
    end_vlan_id: Vlan
    """The ending VLAN ID in the range."""

end_vlan_id instance-attribute

end_vlan_id: Vlan

The ending VLAN ID in the range.

policy instance-attribute

policy: Literal['ascending', 'descending']

The VLAN internal allocation policy.

start_vlan_id instance-attribute

start_vlan_id: Vlan

The starting VLAN ID in the range.