Test models
Anta Test definition¶
UML Diagram¶
AntaTest ¶
AntaTest(device: AntaDevice, template_params: list[dict[str, Any]] | None = None, result_description: str | None = None, result_categories: list[str] | None = None, result_custom_field: str | None = None, eos_data: list[dict[Any, Any] | str] | None = None, labels: list[str] | None = None)
Bases: ABC
Abstract class defining a test for Anta
The goal of this class is to handle the heavy lifting and make writing a test as simple as possible.
TODO - complete doctstring with example
Doc to be completed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_custom_field |
str
|
a free string that is included in the TestResult object |
None
|
Source code in anta/models.py
164 165 166 167 168 169 170 171 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 205 206 207 208 209 210 211 212 213 214 215 |
|
all_data_collected ¶
all_data_collected() -> bool
returns True if output is populated for every command
Source code in anta/models.py
225 226 227 |
|
anta_test
staticmethod
¶
anta_test(function: F) -> Callable[..., Coroutine[Any, Any, TestResult]]
Decorator for anta_test that handles injecting test data if given and collecting it using asyncio if missing
Source code in anta/models.py
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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
collect
async
¶
collect() -> None
Method used to collect outputs of all commands of this test class from the device of this test instance.
Source code in anta/models.py
245 246 247 248 249 250 251 252 253 254 |
|
get_failed_commands ¶
get_failed_commands() -> List[AntaCommand]
returns a list of all the commands that have a populated failed field
Source code in anta/models.py
229 230 231 |
|
save_commands_data ¶
save_commands_data(eos_data: list[dict[Any, Any] | str]) -> None
Called at init or at test execution time
Source code in anta/models.py
217 218 219 220 221 222 223 |
|
test
abstractmethod
¶
test() -> Coroutine[Any, Any, TestResult]
This abstract method is the core of the test. It MUST set the correct status of self.result with the appropriate error messages
it must be implemented as follow
@AntaTest.anta_test def test(self) -> None: ‘’’ assert code ‘’‘
Source code in anta/models.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
update_progress
classmethod
¶
update_progress() -> None
Update progress bar for all AntaTest objects if it exists
Source code in anta/models.py
320 321 322 323 324 325 326 |
|
Anta Command definition¶
UML Diagram¶
AntaCommand ¶
Bases: BaseModel
Class to define a test command with its API version
Attributes:
Name | Type | Description |
---|---|---|
command |
str
|
Device command |
version |
Literal[1, 'latest']
|
eAPI version - valid values are 1 or “latest” - default is “latest” |
revision |
Optional[conint(ge=1, le=99)]
|
Revision of the command. Valid values are 1 to 99. Revision has precedence over version. |
ofmt |
Literal['json', 'text']
|
eAPI output - json or text - default is json |
template |
Optional[AntaTemplate]
|
AntaTemplate object used to render this command |
params |
Optional[Dict[str, Any]]
|
dictionary of variables with string values to render the template |
failed |
Optional[Exception]
|
If the command execution fails, the Exception object is stored in this field |
Template command definition¶
UML Diagram¶
AntaTemplate ¶
Bases: BaseModel
Class to define a test command with its API version
Attributes:
Name | Type | Description |
---|---|---|
template |
str
|
Python f-string. Example: ‘show vlan {vlan_id}’ |
version |
Literal[1, 'latest']
|
eAPI version - valid values are 1 or “latest” - default is “latest” |
revision |
Optional[conint(ge=1, le=99)]
|
Revision of the command. Valid values are 1 to 99. Revision has precedence over version. |
ofmt |
Literal['json', 'text']
|
eAPI output - json or text - default is json |
render ¶
render(params: Dict[str, Any]) -> AntaCommand
Render an AntaCommand from an AntaTemplate instance. Keep the parameters used in the AntaTemplate instance.
Args: params: dictionary of variables with string values to render the Python f-string
Returns: AntaCommand: The rendered AntaCommand. This AntaCommand instance have a template attribute that references this AntaTemplate instance.
Source code in anta/models.py
53 54 55 56 57 58 59 60 61 62 63 64 65 |
|