Result Manager module
Result Manager definition¶
UML Diagram¶
ResultManager ¶
ResultManager()
Helper to manage Test Results and generate reports.
Examples:
Create Inventory:
inventory_anta = AntaInventory.parse(
inventory_file='examples/inventory.yml',
username='ansible',
password='ansible',
timeout=0.5
)
Create Result Manager:
manager = ResultManager()
Run tests for all connected devices:
for device in inventory_anta.get_inventory():
manager.add_test_result(
VerifyNTP(device=device).test()
)
manager.add_test_result(
VerifyEOSVersion(device=device).test(version='4.28.3M')
)
Print result in native format:
manager.get_results()
[
TestResult(
host=IPv4Address('192.168.0.10'),
test='VerifyNTP',
result='failure',
message="device is not running NTP correctly"
),
TestResult(
host=IPv4Address('192.168.0.10'),
test='VerifyEOSVersion',
result='success',
message=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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
add_test_result ¶
add_test_result(entry: TestResult) -> None
Add a result to the list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry |
TestResult
|
TestResult data to add to the report |
required |
Source code in anta/result_manager/__init__.py
118 119 120 121 122 123 124 125 |
|
add_test_results ¶
add_test_results(entries: list[TestResult]) -> None
Add a list of results to the list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entries |
list[TestResult]
|
List of TestResult data to add to the report |
required |
Source code in anta/result_manager/__init__.py
127 128 129 130 131 132 133 134 |
|
get_hosts ¶
get_hosts() -> list[str]
Get list of IP addresses in current manager.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of IP addresses. |
Source code in anta/result_manager/__init__.py
199 200 201 202 203 204 205 206 207 208 209 210 |
|
get_json_results ¶
get_json_results() -> str
Expose list of all test results in JSON
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
JSON dumps of the list of results |
Source code in anta/result_manager/__init__.py
151 152 153 154 155 156 157 158 |
|
get_result_by_host ¶
get_result_by_host(host_ip: str) -> list[TestResult]
Get list of test result for a given host.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host_ip |
str
|
IP Address of the host to use to filter results. |
required |
output_format |
str
|
format selector. Can be either native/list. Defaults to ‘native’. |
required |
Returns:
Type | Description |
---|---|
list[TestResult]
|
list[TestResult]: List of results related to the host. |
Source code in anta/result_manager/__init__.py
173 174 175 176 177 178 179 180 181 182 183 184 |
|
get_result_by_test ¶
get_result_by_test(test_name: str) -> list[TestResult]
Get list of test result for a given test.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_name |
str
|
Test name to use to filter results |
required |
output_format |
str
|
format selector. Can be either native/list. Defaults to ‘native’. |
required |
Returns:
Type | Description |
---|---|
list[TestResult]
|
list[TestResult]: List of results related to the test. |
Source code in anta/result_manager/__init__.py
160 161 162 163 164 165 166 167 168 169 170 171 |
|
get_results ¶
get_results() -> list[TestResult]
Expose list of all test results in different format
Returns:
Name | Type | Description |
---|---|---|
any |
list[TestResult]
|
List of results. |
Source code in anta/result_manager/__init__.py
142 143 144 145 146 147 148 149 |
|
get_status ¶
get_status(ignore_error: bool = False) -> str
Returns the current status including error_status if ignore_error is False
Source code in anta/result_manager/__init__.py
136 137 138 139 140 |
|
get_testcases ¶
get_testcases() -> list[str]
Get list of name of all test cases in current manager.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of names for all tests. |
Source code in anta/result_manager/__init__.py
186 187 188 189 190 191 192 193 194 195 196 197 |
|