Skip to content

System

ANTA catalog for system tests

Test functions related to system-level features and protocols

verify_agent_logs(device, result) async

Verifies there is no agent crash reported on the device.

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 there is no agent crash
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@anta_test
async def verify_agent_logs(device: InventoryDevice, result: TestResult) -> TestResult:
    """
    Verifies there is no agent crash reported on the device.

    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 there is no agent crash
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show agent logs crash", ofmt="text")
    logger.debug(f"query result is: {response}")
    if len(response) == 0:
        result.is_success()
    else:
        result.is_failure(f"device reported some agent crashes: {response}")

    return result

verify_coredump(device, result) async

Verifies there is no core file.

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 device has no core-dump
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@anta_test
async def verify_coredump(device: InventoryDevice, result: TestResult) -> TestResult:
    """
    Verifies there is no core file.

    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 device has no core-dump
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    device.assert_enable_password_is_not_none("verify_coredump")

    response = await device.session.cli(
        commands=[
            {"cmd": "enable", "input": str(device.enable_password)},
            "bash timeout 10 ls /var/core",
        ],
        ofmt="text",
    )
    logger.debug(f"query result is: {response}")
    response_data = response[1]
    if len(response_data) == 0:
        result.is_success()
    else:
        result.is_failure(f"Core-dump(s) have been found: {response_data}")

    return result

verify_cpu_utilization(device, result) async

Verifies the CPU utilization is less than 75%.

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 CPU usage is lower than 75%
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@anta_test
async def verify_cpu_utilization(
    device: InventoryDevice, result: TestResult
) -> TestResult:
    """
    Verifies the CPU utilization is less than 75%.

    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 CPU usage is lower than 75%
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(command="show processes top once", ofmt="json")
    logger.debug(f"query result is: {response}")
    response_data = response["cpuInfo"]["%Cpu(s)"]["idle"]
    if response_data > 25:
        result.is_success()
    else:
        result.is_failure(f"device reported a high CPU utilization ({response_data}%)")

    return result

verify_filesystem_utilization(device, result) async

Verifies each partition on the disk is used less than 75%.

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 disk is used less than 75%
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
@anta_test
async def verify_filesystem_utilization(
    device: InventoryDevice, result: TestResult
) -> TestResult:

    """
    Verifies each partition on the disk is used less than 75%.

    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 disk is used less than 75%
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(
        commands=[
            {"cmd": "enable", "input": device.enable_password},
            "bash timeout 10 df -h",
        ],
        ofmt="text",
    )
    logger.debug(f"query result is: {response}")
    result.is_success()
    for line in response[1].split("\n")[1:]:
        if (
            "loop" not in line
            and len(line) > 0
            and int(line.split()[4].replace("%", "")) > 75
        ):
            result.is_failure(
                f'mount point {line} is higher than 75% (reprted {int(line.split()[4].replace(" % ", ""))})'
            )

    return result

verify_memory_utilization(device, result) async

Verifies the memory utilization is less than 75%.

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 memory usage is lower than 75%
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
@anta_test
async def verify_memory_utilization(
    device: InventoryDevice, result: TestResult
) -> TestResult:
    """
    Verifies the memory utilization is less than 75%.

    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 memory usage is lower than 75%
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(command="show version", ofmt="json")
    logger.debug(f"query result is: {response}")
    memory_usage = float(response["memFree"]) / float(response["memTotal"])
    if memory_usage > 0.25:
        result.is_success()
    else:
        result.is_failure(f"device report a high memory usage: {memory_usage*100}%")

    return result

verify_ntp(device, result) async

Verifies NTP is synchronised.

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 synchronized with NTP server
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
@anta_test
async def verify_ntp(device: InventoryDevice, result: TestResult) -> TestResult:

    """
    Verifies NTP is synchronised.

    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 synchronized with NTP server
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(command="show ntp status", ofmt="text")
    logger.debug(f"query result is: {response}")
    if response.split("\n")[0].split(" ")[0] == "synchronised":
        result.is_success()
    else:
        data = response.split("\n")[0]
        result.is_failure(f"not sync with NTP server ({data})")

    return result

verify_reload_cause(device, result) async

Verifies the last reload of the device was requested by a user.

Test considers the following messages as normal and will return success. Failure is for other messages * Reload requested by the user. * Reload requested after FPGA upgrade

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 reload cause is standard
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
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
80
81
82
83
84
85
@anta_test
async def verify_reload_cause(
    device: InventoryDevice, result: TestResult
) -> TestResult:
    """
    Verifies the last reload of the device was requested by a user.

    Test considers the following messages as normal and will return success. Failure is for other messages
    * Reload requested by the user.
    * Reload requested after FPGA upgrade

    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 reload cause is standard
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show reload cause", ofmt="json")
    logger.debug(f"query result is: {response}")
    if "resetCauses" not in response.keys() or len(response["resetCauses"]) == 0:
        result.is_error("no reload cause available")
        return result

    response_data = response.get("resetCauses")[0].get("description")
    if response_data in [
        "Reload requested by the user.",
        "Reload requested after FPGA upgrade",
    ]:
        result.is_success()
    else:
        result.is_failure(f"Reload cause is {response_data}")

    return result

verify_syslog(device, result) async

Verifies the device had no syslog message with a severity of warning (or a more severe message) during the last 7 days.

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 syslog has no WARNING message
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@anta_test
async def verify_syslog(device: InventoryDevice, result: TestResult) -> TestResult:
    """
    Verifies the device had no syslog message with a severity of warning (or a more severe message)
    during the last 7 days.

    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 syslog has no WARNING message
        * result = "failure" otherwise.
        * result = "error" if any exception is caught
    """
    response = await device.session.cli(
        command="show logging last 7 days threshold warnings", ofmt="text"
    )
    logger.debug(f"query result is: {response}")
    if len(response) == 0:
        result.is_success()
    else:
        result.is_failure(
            "Device has some log messages with a severity WARNING or higher"
        )

    return result

verify_uptime(device, result, minimum=None) async

Verifies the device uptime is higher than a value.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
minimum int

Minimum uptime in seconds.

None

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if the minimum parameter is missing
TestResult
  • result = “success” if uptime is greater than minimun
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/system.py
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
@anta_test
async def verify_uptime(
    device: InventoryDevice, result: TestResult, minimum: Optional[int] = None
) -> TestResult:
    """
    Verifies the device uptime is higher than a value.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        minimum (int): Minimum uptime in seconds.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if the `minimum` parameter is  missing
        * result = "success" if uptime is greater than minimun
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    if not minimum:
        result.is_skipped("verify_uptime was not run as no minimum were given")
        return result

    response = await device.session.cli(command="show uptime", ofmt="json")
    logger.debug(f"query result is: {response}")
    if response["upTime"] > minimum:
        result.is_success()
    else:
        result.is_failure(f"Uptime is {response['upTime']}")

    return result

Last update: September 5, 2022