Debian Codegraph @

docs/usage-inventory-catalog.md

raw symbols SCIP
1 ---
2 title: Inventory and Test catalog
3 hide:
4 - tags
5 tags:
6 - Inventory
7 - Catalog
8 - Configuration
9 ---
10
11 <!--
12 ~ Copyright (c) 2023-2026 Arista Networks, Inc.
13 ~ Use of this source code is governed by the Apache License 2.0
14 ~ that can be found in the LICENSE file.
15 -->
16
17 The ANTA framework needs 2 important inputs from the user to run:
18
19 1. A **device inventory**
20 2. A **test catalog**.
21
22 Both inputs can be defined in a file or programmatically.
23
24 ## Device Inventory
25
26 A device inventory is an instance of the [AntaInventory](./api/inventory.md#anta.inventory.AntaInventory) class.
27
28 ### Device Inventory File
29
30 The ANTA device inventory can easily be defined as a YAML file.
31 The file must comply with the following structure:
32
33 ```yaml
34 anta_inventory:
35 hosts:
36 - host: < ip address value >
37 port: < TCP port for eAPI. Default is 443 (Optional)>
38 name: < name to display in report. Default is host:port (Optional) >
39 tags: < list of tags to use to filter inventory during tests >
40 disable_cache: < Disable cache per hosts. Default is False. >
41 use_session_auth: < Enable session-based authentication for this host. Default is False. >
42 networks:
43 - network: < network using CIDR notation >
44 tags: < list of tags to use to filter inventory during tests >
45 disable_cache: < Disable cache per network. Default is False. >
46 use_session_auth: < Enable session-based authentication for all hosts in this network. Default is False. >
47 ranges:
48 - start: < first ip address value of the range >
49 end: < last ip address value of the range >
50 tags: < list of tags to use to filter inventory during tests >
51 disable_cache: < Disable cache per range. Default is False. >
52 use_session_auth: < Enable session-based authentication for all hosts in this range. Default is False. >
53 ```
54
55 The inventory file must start with the `anta_inventory` key then define one or multiple methods:
56
57 - `hosts`: define each device individually
58 - `networks`: scan a network for devices accessible via eAPI
59 - `ranges`: scan a range for devices accessible via eAPI
60
61 A full description of the inventory model is available in [API documentation](api/inventory.md)
62
63 !!! info
64 Caching can be disabled per device, network or range by setting the `disable_cache` key to `True` in the inventory file. For more details about how caching is implemented in ANTA, please refer to [Caching in ANTA](advanced_usages/caching.md).
65
66 !!! info
67 Session-based authentication can be enabled per device, network or range by setting `use_session_auth: true`. The per-device value can be overridden globally via the `--use-session-auth` / `--no-session-auth` CLI flags or the `ANTA_USE_SESSION_AUTH` environment variable. Session-based authentication is only available on device types that advertise the `supports_session_auth` capability (e.g. `AsyncEOSDevice`). If `use_session_auth` is enabled in the inventory for a device type that does not support it, ANTA raises an exception during inventory loading; if it is requested globally from the CLI or environment variable, ANTA logs a warning for unsupported devices.
68
69 ### Example
70
71 ```yaml
72 ---
73 anta_inventory:
74 hosts:
75 - host: 192.168.0.10
76 name: spine01
77 tags: ['fabric', 'spine']
78 - host: 192.168.0.11
79 name: spine02
80 tags: ['fabric', 'spine']
81 networks:
82 - network: '192.168.110.0/24'
83 tags: ['fabric', 'leaf']
84 ranges:
85 - start: 10.0.0.9
86 end: 10.0.0.11
87 tags: ['fabric', 'l2leaf']
88 ```
89
90 ## Test Catalog
91
92 A test catalog is an instance of the [AntaCatalog](./api/catalog.md#anta.catalog.AntaCatalog) class.
93
94 ### Test Catalog File
95
96 In addition to the inventory file, you also have to define a catalog of tests to execute against your devices. This catalog lists all your tests, their inputs and their tags.
97
98 A valid test catalog file must have the following structure in either YAML or JSON:
99
100 ```yaml
101 ---
102 <Python module>:
103 - <AntaTest subclass>:
104 <AntaTest.Input compliant dictionary>
105 ```
106
107 ```json
108 {
109 "<Python module>": [
110 {
111 "<AntaTest subclass>": <AntaTest.Input compliant dictionary>
112 }
113 ]
114 }
115 ```
116
117 ### Example
118
119 ```yaml
120 ---
121 anta.tests.connectivity:
122 - VerifyReachability:
123 hosts:
124 - source: Management0
125 destination: 1.1.1.1
126 vrf: MGMT
127 - source: Management0
128 destination: 8.8.8.8
129 vrf: MGMT
130 filters:
131 tags: ['leaf']
132 result_overwrite:
133 categories:
134 - "Overwritten category 1"
135 description: "Test with overwritten description"
136 custom_field: "Test run by John Doe"
137 ```
138
139 or equivalent in JSON:
140
141 ```json
142 {
143 "anta.tests.connectivity": [
144 {
145 "VerifyReachability": {
146 "result_overwrite": {
147 "description": "Test with overwritten description",
148 "categories": [
149 "Overwritten category 1"
150 ],
151 "custom_field": "Test run by John Doe"
152 },
153 "filters": {
154 "tags": [
155 "leaf"
156 ]
157 },
158 "hosts": [
159 {
160 "destination": "1.1.1.1",
161 "source": "Management0",
162 "vrf": "MGMT"
163 },
164 {
165 "destination": "8.8.8.8",
166 "source": "Management0",
167 "vrf": "MGMT"
168 }
169 ]
170 }
171 }
172 ]
173 }
174 ```
175
176 It is also possible to nest Python module definition:
177
178 ```yaml
179 anta.tests:
180 connectivity:
181 - VerifyReachability:
182 hosts:
183 - source: Management0
184 destination: 1.1.1.1
185 vrf: MGMT
186 - source: Management0
187 destination: 8.8.8.8
188 vrf: MGMT
189 filters:
190 tags: ['leaf']
191 result_overwrite:
192 categories:
193 - "Overwritten category 1"
194 description: "Test with overwritten description"
195 custom_field: "Test run by John Doe"
196 ```
197
198 [This test catalog example](https://github.com/aristanetworks/anta/blob/main/examples/tests.yaml) is maintained with all the tests defined in the `anta.tests` Python module.
199
200 ### Test tags
201
202 All tests can be defined with a list of user defined tags. These tags will be mapped with device tags: when at least one tag is defined for a test, this test will only be executed on devices with the same tag. If a test is defined in the catalog without any tags, the test will be executed on all devices.
203
204 ```yaml
205 anta.tests.system:
206 - VerifyUptime:
207 minimum: 10
208 filters:
209 tags: ['demo', 'leaf']
210 - VerifyReloadCause:
211 - VerifyCoredump:
212 - VerifyAgentLogs:
213 - VerifyCPUUtilization:
214 filters:
215 tags: ['leaf']
216 ```
217
218 !!! info
219 When using the CLI, you can filter the NRFU execution using tags. Refer to [this section](cli/tag-management.md) of the CLI documentation.
220
221 ### Tests available in ANTA
222
223 All tests available as part of the ANTA framework are defined under the `anta.tests` Python module and are categorised per family (Python submodule).
224 The complete list of the tests and their respective inputs is available at the [tests section](api/tests.md) of this website.
225
226 To run a test to verify the EOS software version, you can do:
227
228 ```yaml
229 anta.tests.software:
230 - VerifyEOSVersion:
231 ```
232
233 It will load the test `VerifyEOSVersion` located in `anta.tests.software`. But since this test has mandatory inputs, we need to provide them as a dictionary in the YAML or JSON file:
234
235 ```yaml
236 anta.tests.software:
237 - VerifyEOSVersion:
238 # List of allowed EOS versions.
239 versions:
240 - 4.25.4M
241 - 4.26.1F
242 ```
243
244 ```json
245 {
246 "anta.tests.software": [
247 {
248 "VerifyEOSVersion": {
249 "versions": [
250 "4.25.4M",
251 "4.31.1F"
252 ]
253 }
254 }
255 ]
256 }
257 ```
258
259 The following example is a very minimal test catalog:
260
261 ```yaml
262 ---
263 # Load anta.tests.software
264 anta.tests.software:
265 # Verifies the device is running one of the allowed EOS version.
266 - VerifyEOSVersion:
267 # List of allowed EOS versions.
268 versions:
269 - 4.25.4M
270 - 4.26.1F
271
272 # Load anta.tests.system
273 anta.tests.system:
274 # Verifies the device uptime is higher than a value.
275 - VerifyUptime:
276 minimum: 1
277
278 # Load anta.tests.configuration
279 anta.tests.configuration:
280 # Verifies ZeroTouch is disabled.
281 - VerifyZeroTouch:
282 - VerifyRunningConfigDiffs:
283 ```
284
285 ### Catalog with custom tests
286
287 In case you want to leverage your own tests collection, use your own Python package in the test catalog.
288 So for instance, if my custom tests are defined in the `custom.tests.system` Python module, the test catalog will be:
289
290 ```yaml
291 custom.tests.system:
292 - VerifyPlatform:
293 type: ['cEOS-LAB']
294 ```
295
296 !!! tip
297 **How to create custom tests**
298
299 To create your custom tests, you should refer to this [documentation](advanced_usages/custom-tests.md)
300
301 ### Customize test description and categories
302
303 It might be interesting to use your own categories and customized test description to build a better report for your environment. ANTA comes with a handy feature to define your own `categories` and `description` in the report.
304
305 In your test catalog, use `result_overwrite` dictionary with `categories` and `description` to just overwrite these values in your report:
306
307 ```yaml
308 anta.tests.configuration:
309 - VerifyZeroTouch: # Verifies ZeroTouch is disabled.
310 result_overwrite:
311 categories: ['demo', 'pr296']
312 description: A custom test
313 - VerifyRunningConfigDiffs:
314 anta.tests.interfaces:
315 - VerifyInterfaceUtilization:
316 ```
317
318 Once you run `anta nrfu table`, you will see following output:
319
320 ```bash
321 ┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
322 ┃ Device IP ┃ Test Name ┃ Test Status ┃ Message(s) ┃ Test description ┃ Test category ┃
323 ┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
324 │ spine01 │ VerifyZeroTouch │ success │ │ A custom test │ demo, pr296 │
325 │ spine01 │ VerifyRunningConfigDiffs │ success │ │ │ configuration │
326 │ spine01 │ VerifyInterfaceUtilization │ success │ │ Verifies interfaces utilization is below 75%. │ interfaces │
327 └───────────┴────────────────────────────┴─────────────┴────────────┴───────────────────────────────────────────────┴───────────────┘
328 ```
329
330 ### Example script to merge catalogs
331
332 The following script reads all the files in `intended/test_catalogs/` with names `<device_name>-catalog.yml` and merge them together inside one big catalog `anta-catalog.yml` using the new `AntaCatalog.merge_catalogs()` class method.
333
334 ```python
335 --8<-- "merge_catalogs.py"
336 ```
337
338 !!! warning
339 The `AntaCatalog.merge()` method is deprecated and will be removed in ANTA v2.0. Please use the `AntaCatalog.merge_catalogs()` class method instead.