Runner
runner ¶
ANTA runner function.
adjust_rlimit_nofile ¶
adjust_rlimit_nofile() -> tuple[int, int]
Adjust the maximum number of open file descriptors for the ANTA process.
The limit is set to the lower of the current hard limit and the value of the ANTA_NOFILE environment variable.
If the ANTA_NOFILE
environment variable is not set or is invalid, DEFAULT_NOFILE
is used.
Returns:
Type | Description |
---|---|
tuple[int, int]
|
The new soft and hard limits for open file descriptors. |
Source code in anta/runner.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
get_coroutines ¶
get_coroutines(
selected_tests: defaultdict[
AntaDevice, set[AntaTestDefinition]
],
manager: ResultManager,
) -> list[Coroutine[Any, Any, TestResult]]
Get the coroutines for the ANTA run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_tests |
defaultdict[AntaDevice, set[AntaTestDefinition]]
|
A mapping of devices to the tests to run. The selected tests are generated by the |
required |
manager |
ResultManager
|
A ResultManager |
required |
Returns:
Type | Description |
---|---|
list[Coroutine[Any, Any, TestResult]]
|
The list of coroutines to run. |
Source code in anta/runner.py
172 173 174 175 176 177 178 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 |
|
log_cache_statistics ¶
log_cache_statistics(devices: list[AntaDevice]) -> None
Log cache statistics for each device in the inventory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
devices |
list[AntaDevice]
|
List of devices in the inventory. |
required |
Source code in anta/runner.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
main
async
¶
main(
manager: ResultManager,
inventory: AntaInventory,
catalog: AntaCatalog,
devices: set[str] | None = None,
tests: set[str] | None = None,
tags: set[str] | None = None,
*,
established_only: bool = True,
dry_run: bool = False
) -> None
Run ANTA.
Use this as an entrypoint to the test framework in your script. ResultManager object gets updated with the test results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
manager |
ResultManager
|
ResultManager object to populate with the test results. |
required |
inventory |
AntaInventory
|
AntaInventory object that includes the device(s). |
required |
catalog |
AntaCatalog
|
AntaCatalog object that includes the list of tests. |
required |
devices |
set[str] | None
|
Devices on which to run tests. None means all devices. These may come from the |
None
|
tests |
set[str] | None
|
Tests to run against devices. None means all tests. These may come from the |
None
|
tags |
set[str] | None
|
Tags to filter devices from the inventory. These may come from the |
None
|
established_only |
bool
|
Include only established device(s). |
True
|
dry_run |
bool
|
Build the list of coroutine to run and stop before test execution. |
False
|
Source code in anta/runner.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 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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
prepare_tests ¶
prepare_tests(
inventory: AntaInventory,
catalog: AntaCatalog,
tests: set[str] | None,
tags: set[str] | None,
) -> (
defaultdict[AntaDevice, set[AntaTestDefinition]] | None
)
Prepare the tests to run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inventory |
AntaInventory
|
AntaInventory object that includes the device(s). |
required |
catalog |
AntaCatalog
|
AntaCatalog object that includes the list of tests. |
required |
tests |
set[str] | None
|
Tests to run against devices. None means all tests. |
required |
tags |
set[str] | None
|
Tags to filter devices from the inventory. |
required |
Returns:
Type | Description |
---|---|
defaultdict[AntaDevice, set[AntaTestDefinition]] | None
|
A mapping of devices to the tests to run or None if there are no tests to run. |
Source code in anta/runner.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
setup_inventory
async
¶
setup_inventory(
inventory: AntaInventory,
tags: set[str] | None,
devices: set[str] | None,
*,
established_only: bool
) -> AntaInventory | None
Set up the inventory for the ANTA run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inventory |
AntaInventory
|
AntaInventory object that includes the device(s). |
required |
tags |
set[str] | None
|
Tags to filter devices from the inventory. |
required |
devices |
set[str] | None
|
Devices on which to run tests. None means all devices. |
required |
established_only |
bool
|
If True use return only devices where a connection is established. |
required |
Returns:
Type | Description |
---|---|
AntaInventory | None
|
The filtered inventory or None if there are no devices to run tests on. |
Source code in anta/runner.py
80 81 82 83 84 85 86 87 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 |
|