ANTA Result API
ResultManager
¶
ResultManager()
Manager of ANTA Results.
The status of the class is initialized to “unset”
Then when adding a test with a status that is NOT ‘error’ the following table shows the updated status:
Current Status | Added test Status | Updated Status |
---|---|---|
unset | Any | Any |
skipped | unset, skipped | skipped |
skipped | success | success |
skipped | failure | failure |
success | unset, skipped, success | success |
success | failure | failure |
failure | unset, skipped success, failure | failure |
If the status of the added test is error, the status is untouched and the
error_status
attribute is set to True.
Attributes:
Name | Type | Description |
---|---|---|
results |
list[TestResult]
|
|
dump |
list[dict[str, Any]]
|
|
status |
AntaTestStatus
|
Status rerpesenting all the results. |
error_status |
bool
|
Will be |
results_by_status |
dict[AntaTestStatus, list[TestResult]]
|
|
dump |
list[dict[str, Any]]
|
|
json |
str
|
|
device_stats |
dict[str, DeviceStats]
|
|
category_stats |
dict[str, CategoryStats]
|
|
test_stats |
dict[str, TestStats]
|
|
results_by_status
cached
property
¶
results_by_status: dict[AntaTestStatus, list[TestResult]]
A cached property that returns the results grouped by status.
sorted_category_stats
property
¶
A property that returns the category_stats dictionary sorted by key name.
add
¶
add(result: TestResult) -> None
Add a result to the ResultManager instance.
The result is added to the internal list of results and the overall status of the ResultManager instance is updated based on the added test status.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
TestResult
|
TestResult to add to the ResultManager instance. |
required |
Source code in anta/result_manager/__init__.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
filter
¶
filter(hide: set[AntaTestStatus]) -> ResultManager
Get a filtered ResultManager based on test status.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hide
|
set[AntaTestStatus]
|
Set of AntaTestStatus enum members to select tests to hide based on their status. |
required |
Returns:
Type | Description |
---|---|
ResultManager
|
A filtered |
Source code in anta/result_manager/__init__.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
filter_by_devices
deprecated
¶
filter_by_devices(devices: set[str]) -> ResultManager
Deprecated
This method is deprecated. This will be removed in ANTA v2.0.0.
Get a filtered ResultManager that only contains specific devices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
devices
|
set[str]
|
Set of device names to filter the results. |
required |
Returns:
Type | Description |
---|---|
ResultManager
|
A filtered |
Source code in anta/result_manager/__init__.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
filter_by_tests
deprecated
¶
filter_by_tests(tests: set[str]) -> ResultManager
Deprecated
This method is deprecated. This will be removed in ANTA v2.0.0.
Get a filtered ResultManager that only contains specific tests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tests
|
set[str]
|
Set of test names to filter the results. |
required |
Returns:
Type | Description |
---|---|
ResultManager
|
A filtered |
Source code in anta/result_manager/__init__.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
get_devices
deprecated
¶
Deprecated
This method is deprecated. This will be removed in ANTA v2.0.0.
Get the set of all the device names.
Returns:
Type | Description |
---|---|
set[str]
|
Set of device names. |
Source code in anta/result_manager/__init__.py
366 367 368 369 370 371 372 373 374 375 |
|
get_results
¶
get_results(
status: set[AntaTestStatus] | None = None,
sort_by: list[str] | None = None,
) -> list[TestResult]
Get the results, optionally filtered by status and sorted by TestResult fields.
If no status is provided, all results are returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status
|
set[AntaTestStatus] | None
|
Optional set of AntaTestStatus enum members to filter the results. |
None
|
sort_by
|
list[str] | None
|
Optional list of TestResult fields to sort the results. |
None
|
Returns:
Type | Description |
---|---|
list[TestResult]
|
List of results. |
Source code in anta/result_manager/__init__.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
get_status
¶
Return the current status including error_status if ignore_error is False.
Source code in anta/result_manager/__init__.py
282 283 284 |
|
get_tests
deprecated
¶
Deprecated
This method is deprecated. This will be removed in ANTA v2.0.0.
Get the set of all the test names.
Returns:
Type | Description |
---|---|
set[str]
|
Set of test names. |
Source code in anta/result_manager/__init__.py
355 356 357 358 359 360 361 362 363 364 |
|
get_total_results
¶
Get the total number of results, optionally filtered by status.
If no status is provided, the total number of results is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status
|
set[AntaTestStatus] | None
|
Optional set of AntaTestStatus enum members to filter the results. |
None
|
Returns:
Type | Description |
---|---|
int
|
Total number of results. |
Source code in anta/result_manager/__init__.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
reset
¶
reset() -> None
Create or reset the attributes of the ResultManager instance.
Source code in anta/result_manager/__init__.py
75 76 77 78 79 80 81 82 |
|
sort
¶
sort(sort_by: list[str]) -> ResultManager
Sort the ResultManager results based on TestResult fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sort_by
|
list[str]
|
List of TestResult fields to sort the results. |
required |
Source code in anta/result_manager/__init__.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
TestResult
¶
Bases: BaseModel
Describe the result of a test from a single device.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Name of the device where the test was run. |
test |
str
|
Name of the test run on the device. |
categories |
list[str]
|
List of categories the TestResult belongs to. Defaults to the AntaTest categories. |
description |
str
|
Description of the TestResult. Defaults to the AntaTest description. |
result |
AntaTestStatus
|
Result of the test. Must be one of the AntaTestStatus Enum values: unset, success, failure, error or skipped. |
messages |
list[str]
|
Messages to report after the test, if any. |
custom_field |
str | None
|
Custom field to store a string for flexibility in integrating with ANTA. |
is_error
¶
is_error(message: str | None = None) -> None
Set status to error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str | None
|
Optional message related to the test. |
None
|
Source code in anta/result_manager/models.py
94 95 96 97 98 99 100 101 102 103 |
|
is_failure
¶
is_failure(message: str | None = None) -> None
Set status to failure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str | None
|
Optional message related to the test. |
None
|
Source code in anta/result_manager/models.py
72 73 74 75 76 77 78 79 80 81 |
|
is_skipped
¶
is_skipped(message: str | None = None) -> None
Set status to skipped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str | None
|
Optional message related to the test. |
None
|
Source code in anta/result_manager/models.py
83 84 85 86 87 88 89 90 91 92 |
|
is_success
¶
is_success(message: str | None = None) -> None
Set status to success.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str | None
|
Optional message related to the test. |
None
|
Source code in anta/result_manager/models.py
61 62 63 64 65 66 67 68 69 70 |
|