Result Manager definition¶
UML Diagram¶
ResultManager ¶
ResultManager()
Helper to manage Test Results and generate reports.
Examples
Create Inventory:
inventory_anta = AntaInventory.parse(
filename='examples/inventory.yml',
username='ansible',
password='ansible',
)
Create Result Manager:
manager = ResultManager()
Run tests for all connected devices:
for device in inventory_anta.get_inventory().devices:
manager.add(
VerifyNTP(device=device).test()
)
manager.add(
VerifyEOSVersion(device=device).test(version='4.28.3M')
)
Print result in native format:
manager.results
[
TestResult(
name="pf1",
test="VerifyZeroTouch",
categories=["configuration"],
description="Verifies ZeroTouch is disabled",
result="success",
messages=[],
custom_field=None,
),
TestResult(
name="pf1",
test='VerifyNTP',
categories=["software"],
categories=['system'],
description='Verifies if NTP is synchronised.',
result='failure',
messages=["The device is not synchronized with the configured NTP server(s): 'NTP is disabled.'"],
custom_field=None,
),
]
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 is set to True.
Source code in anta/result_manager/__init__.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
add ¶
add(result: TestResult) -> None
Add a result to the ResultManager instance.
Args:
result: TestResult to add to the ResultManager instance.
Source code in anta/result_manager/__init__.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
filter ¶
filter(hide: set[TestStatus]) -> ResultManager
Get a filtered ResultManager based on test status.
Args:
hide: set of TestStatus literals to select tests to hide based on their status.
Returns:
Type | Description |
---|---|
A filtered `ResultManager`.
|
|
Source code in anta/result_manager/__init__.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
filter_by_devices ¶
filter_by_devices(devices: set[str]) -> ResultManager
Get a filtered ResultManager that only contains specific devices.
Args:
devices: Set of device names to filter the results.
Returns:
Type | Description |
---|---|
A filtered `ResultManager`.
|
|
Source code in anta/result_manager/__init__.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
filter_by_tests ¶
filter_by_tests(tests: set[str]) -> ResultManager
Get a filtered ResultManager that only contains specific tests.
Args:
tests: Set of test names to filter the results.
Returns:
Type | Description |
---|---|
A filtered `ResultManager`.
|
|
Source code in anta/result_manager/__init__.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
get_devices ¶
get_devices() -> set[str]
Get the set of all the device names.
Returns:
Type | Description |
---|---|
Set of device names.
|
|
Source code in anta/result_manager/__init__.py
199 200 201 202 203 204 205 206 |
|
get_status ¶
get_status(*, ignore_error: bool = False) -> str
Return the current status including error_status if ignore_error is False.
Source code in anta/result_manager/__init__.py
141 142 143 |
|
get_tests ¶
get_tests() -> set[str]
Get the set of all the test names.
Returns:
Type | Description |
---|---|
Set of test names.
|
|
Source code in anta/result_manager/__init__.py
190 191 192 193 194 195 196 197 |
|