summaryrefslogtreecommitdiffstats
path: root/anta/tests/configuration.py
blob: 060782af0ef483926accb7241ffadd14cb13052f (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
# 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.
"""
Test functions related to the device configuration
"""
# Mypy does not understand AntaTest.Input typing
# mypy: disable-error-code=attr-defined
from __future__ import annotations

from anta.models import AntaCommand, AntaTest


class VerifyZeroTouch(AntaTest):
    """
    Verifies ZeroTouch is disabled
    """

    name = "VerifyZeroTouch"
    description = "Verifies ZeroTouch is disabled"
    categories = ["configuration"]
    commands = [AntaCommand(command="show zerotouch")]

    @AntaTest.anta_test
    def test(self) -> None:
        command_output = self.instance_commands[0].output
        assert isinstance(command_output, dict)
        if command_output["mode"] == "disabled":
            self.result.is_success()
        else:
            self.result.is_failure("ZTP is NOT disabled")


class VerifyRunningConfigDiffs(AntaTest):
    """
    Verifies there is no difference between the running-config and the startup-config
    """

    name = "VerifyRunningConfigDiffs"
    description = "Verifies there is no difference between the running-config and the startup-config"
    categories = ["configuration"]
    commands = [AntaCommand(command="show running-config diffs", ofmt="text")]

    @AntaTest.anta_test
    def test(self) -> None:
        command_output = self.instance_commands[0].output
        if command_output is None or command_output == "":
            self.result.is_success()
        else:
            self.result.is_failure()
            self.result.is_failure(str(command_output))