Debian Codegraph @

docs/cli/tag-management.md

raw symbols SCIP
1 ---
2 title: Tag Management
3 hide:
4 - tags
5 tags:
6 - CLI
7 - Inventory
8 - Catalog
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 ANTA uses tags to define test-to-device mappings (tests run on devices with matching tags) and the `--tags` CLI option acts as a filter to execute specific test/device combinations.
18
19 ## Defining tags
20
21 ### Device tags
22
23 Device tags can be defined in the inventory:
24
25 ```yaml
26 anta_inventory:
27 hosts:
28 - name: leaf1
29 host: leaf1.anta.arista.com
30 tags: ["leaf"]
31 - name: leaf2
32 host: leaf2.anta.arista.com
33 tags: ["leaf"]
34 - name: spine1
35 host: spine1.anta.arista.com
36 tags: ["spine"]
37 ```
38
39 Each device also has its own name automatically added as a tag:
40
41 ```bash
42 $ anta get inventory
43 Current inventory content is:
44 {
45 'leaf1': AsyncEOSDevice(
46 name='leaf1',
47 tags={'leaf', 'leaf1'}, <--
48 [...]
49 host='leaf1.anta.arista.com',
50 [...]
51 ),
52 'leaf2': AsyncEOSDevice(
53 name='leaf2',
54 tags={'leaf', 'leaf2'}, <--
55 [...]
56 host='leaf2.anta.arista.com',
57 [...]
58 ),
59 'spine1': AsyncEOSDevice(
60 name='spine1',
61 tags={'spine1', 'spine'}, <--
62 [...]
63 host='spine1.anta.arista.com',
64 [...]
65 )
66 }
67 ```
68
69 ### Test tags
70
71 Tags can be defined in the test catalog to restrict tests to tagged devices:
72
73 ```yaml
74 anta.tests.system:
75 - VerifyUptime:
76 minimum: 10
77 filters: tags: [spine]
78 - VerifyUptime:
79 minimum: 9
80 filters:
81 tags: [leaf]
82 - VerifyReloadCause:
83 filters:
84 tags: [spine, leaf]
85 - VerifyCoredump:
86 - VerifyAgentLogs:
87 - VerifyCPUUtilization:
88 - VerifyMemoryUtilization:
89 - VerifyFileSystemUtilization:
90 - VerifyNTP:
91
92 anta.tests.mlag:
93 - VerifyMlagStatus:
94 filters:
95 tags: [leaf]
96
97 anta.tests.interfaces:
98 - VerifyL3MTU:
99 mtu: 1500
100 filters:
101 tags: [spine]
102 ```
103
104 !!! tip
105
106 - A tag used to filter a test can also be a device name
107
108 - **Use different input values for a specific test**: Leverage tags to define different input values for a specific test. See the `VerifyUptime` example above.
109
110 ## Using tags
111
112 | Command | Description |
113 | ------- | ----------- |
114 | No `--tags` option | Run all tests on all devices according to the `tag` definitions in your inventory and test catalog.<br/> Tests without tags are executed on all devices. |
115 | `--tags leaf` | Run all tests marked with the `leaf` tag on all devices configured with the `leaf` tag.<br/> All other tests are ignored. |
116 | `--tags leaf,spine` | Run all tests marked with the `leaf` tag on all devices configured with the `leaf` tag.<br/>Run all tests marked with the `spine` tag on all devices configured with the `spine` tag.<br/> All other tests are ignored. |
117
118 ### Examples
119
120 The following examples use the inventory and test catalog defined above.
121
122 #### No `--tags` option
123
124 Tests without tags are run on all devices.
125 Tests with tags will only run on devices with matching tags.
126
127 ```bash
128 $ anta nrfu table --group-by device
129 ╭────────────────────── Settings ──────────────────────╮
130 │ - ANTA Inventory contains 3 devices (AsyncEOSDevice) │
131 │ - Tests catalog contains 11 tests │
132 ╰──────────────────────────────────────────────────────╯
133
134 --- ANTA NRFU Run Information ---
135 Number of devices: 3 (3 established)
136 Total number of selected tests: 27
137 ---------------------------------
138 Summary per device
139 ┏━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
140 ┃ Device ┃ # of success ┃ # of skipped ┃ # of failure ┃ # of errors ┃ List of failed or error test cases ┃
141 ┡━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
142 │ leaf1 │ 9 │ 0 │ 0 │ 0 │ │
143 ├────────┼──────────────┼──────────────┼──────────────┼─────────────┼────────────────────────────────────┤
144 │ leaf2 │ 7 │ 1 │ 1 │ 0 │ VerifyAgentLogs │
145 ├────────┼──────────────┼──────────────┼──────────────┼─────────────┼────────────────────────────────────┤
146 │ spine1 │ 9 │ 0 │ 0 │ 0 │ │
147 └────────┴──────────────┴──────────────┴──────────────┴─────────────┴────────────────────────────────────┘
148 ```
149
150 #### Single tag
151
152 With a tag specified, only tests matching this tag will be run on matching devices.
153
154 ```bash
155 $ anta nrfu --tags leaf text
156 ╭────────────────────── Settings ──────────────────────╮
157 │ - ANTA Inventory contains 3 devices (AsyncEOSDevice) │
158 │ - Tests catalog contains 11 tests │
159 ╰──────────────────────────────────────────────────────╯
160
161 --- ANTA NRFU Run Information ---
162 Number of devices: 3 (2 established)
163 Total number of selected tests: 6
164 ---------------------------------
165
166 leaf1 :: VerifyReloadCause :: SUCCESS
167 leaf1 :: VerifyUptime :: SUCCESS
168 leaf1 :: VerifyMlagStatus :: SUCCESS
169 leaf2 :: VerifyReloadCause :: SUCCESS
170 leaf2 :: VerifyUptime :: SUCCESS
171 leaf2 :: VerifyMlagStatus :: SKIPPED (MLAG is disabled)
172 ```
173
174 In this case, only `leaf` devices defined in the inventory are used to run tests marked with the `leaf` in the test catalog.
175
176 #### Multiple tags
177
178 It is possible to use multiple tags using the `--tags tag1,tag2` syntax.
179
180 ```bash
181 $ anta nrfu --tags leaf,spine text
182 ╭────────────────────── Settings ──────────────────────╮
183 │ - ANTA Inventory contains 3 devices (AsyncEOSDevice) │
184 │ - Tests catalog contains 11 tests │
185 ╰──────────────────────────────────────────────────────╯
186
187 --- ANTA NRFU Run Information ---
188 Number of devices: 3 (3 established)
189 Total number of selected tests: 15
190 ---------------------------------
191
192 leaf1 :: VerifyReloadCause :: SUCCESS
193 leaf1 :: VerifyMlagStatus :: SUCCESS
194 leaf1 :: VerifyUptime :: SUCCESS
195 leaf1 :: VerifyL3MTU :: SUCCESS
196 leaf1 :: VerifyUptime :: SUCCESS
197 leaf2 :: VerifyReloadCause :: SUCCESS
198 leaf2 :: VerifyMlagStatus :: SKIPPED (MLAG is disabled)
199 leaf2 :: VerifyUptime :: SUCCESS
200 leaf2 :: VerifyL3MTU :: SUCCESS
201 leaf2 :: VerifyUptime :: SUCCESS
202 spine1 :: VerifyReloadCause :: SUCCESS
203 spine1 :: VerifyMlagStatus :: SUCCESS
204 spine1 :: VerifyUptime :: SUCCESS
205 spine1 :: VerifyL3MTU :: SUCCESS
206 spine1 :: VerifyUptime :: SUCCESS
207 ```
208
209 ## Obtaining all configured tags
210
211 As most ANTA commands accommodate tag filtering, this command is useful for enumerating all tags configured in the inventory. Running the `anta get tags` command will return a list of all tags configured in the inventory.
212
213 ### Command overview
214
215 ```bash
216 --8<-- "anta_get_tags_help.txt"
217 ```
218
219 ### Example
220
221 To get the list of all configured tags in the inventory, run the following command:
222
223 ```bash
224 $ anta get tags
225 Tags defined in inventory:
226 [
227 "leaf",
228 "leaf1",
229 "leaf2",
230 "spine",
231 "spine1"
232 ]
233 ```