Merging upstream version 1.1.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
50f8dbf7e8
commit
2044ea6182
196 changed files with 10121 additions and 3780 deletions
|
@ -4,9 +4,10 @@
|
|||
~ that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
# Inventory and Catalog
|
||||
The ANTA framework needs 2 important inputs from the user to run:
|
||||
|
||||
The ANTA framework needs 2 important inputs from the user to run: a **device inventory** and a **test catalog**.
|
||||
1. A **device inventory**
|
||||
2. A **test catalog**.
|
||||
|
||||
Both inputs can be defined in a file or programmatically.
|
||||
|
||||
|
@ -78,7 +79,8 @@ A test catalog is an instance of the [AntaCatalog](./api/catalog.md#anta.catalog
|
|||
|
||||
In addition to the inventory file, you also have to define a catalog of tests to execute against your devices. This catalog list all your tests, their inputs and their tags.
|
||||
|
||||
A valid test catalog file must have the following structure:
|
||||
A valid test catalog file must have the following structure in either YAML or JSON:
|
||||
|
||||
```yaml
|
||||
---
|
||||
<Python module>:
|
||||
|
@ -86,6 +88,16 @@ A valid test catalog file must have the following structure:
|
|||
<AntaTest.Input compliant dictionary>
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"<Python module>": [
|
||||
{
|
||||
"<AntaTest subclass>": <AntaTest.Input compliant dictionary>
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```yaml
|
||||
|
@ -108,7 +120,45 @@ anta.tests.connectivity:
|
|||
custom_field: "Test run by John Doe"
|
||||
```
|
||||
|
||||
or equivalent in JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"anta.tests.connectivity": [
|
||||
{
|
||||
"VerifyReachability": {
|
||||
"result_overwrite": {
|
||||
"description": "Test with overwritten description",
|
||||
"categories": [
|
||||
"Overwritten category 1"
|
||||
],
|
||||
"custom_field": "Test run by John Doe"
|
||||
},
|
||||
"filters": {
|
||||
"tags": [
|
||||
"leaf"
|
||||
]
|
||||
},
|
||||
"hosts": [
|
||||
{
|
||||
"destination": "1.1.1.1",
|
||||
"source": "Management0",
|
||||
"vrf": "MGMT"
|
||||
},
|
||||
{
|
||||
"destination": "8.8.8.8",
|
||||
"source": "Management0",
|
||||
"vrf": "MGMT"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
It is also possible to nest Python module definition:
|
||||
|
||||
```yaml
|
||||
anta.tests:
|
||||
connectivity:
|
||||
|
@ -157,7 +207,6 @@ anta.tests.system:
|
|||
All tests available as part of the ANTA framework are defined under the `anta.tests` Python module and are categorised per family (Python submodule).
|
||||
The complete list of the tests and their respective inputs is available at the [tests section](api/tests.md) of this website.
|
||||
|
||||
|
||||
To run test to verify the EOS software version, you can do:
|
||||
|
||||
```yaml
|
||||
|
@ -165,7 +214,7 @@ anta.tests.software:
|
|||
- VerifyEOSVersion:
|
||||
```
|
||||
|
||||
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 file:
|
||||
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:
|
||||
|
||||
```yaml
|
||||
anta.tests.software:
|
||||
|
@ -176,6 +225,21 @@ anta.tests.software:
|
|||
- 4.26.1F
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"anta.tests.software": [
|
||||
{
|
||||
"VerifyEOSVersion": {
|
||||
"versions": [
|
||||
"4.25.4M",
|
||||
"4.31.1F"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
The following example is a very minimal test catalog:
|
||||
|
||||
```yaml
|
||||
|
@ -247,29 +311,11 @@ Once you run `anta nrfu table`, you will see following output:
|
|||
|
||||
### Example script to merge catalogs
|
||||
|
||||
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`.
|
||||
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.
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python
|
||||
from anta.catalog import AntaCatalog
|
||||
|
||||
from pathlib import Path
|
||||
from anta.models import AntaTest
|
||||
|
||||
|
||||
CATALOG_SUFFIX = '-catalog.yml'
|
||||
CATALOG_DIR = 'intended/test_catalogs/'
|
||||
|
||||
if __name__ == "__main__":
|
||||
catalog = AntaCatalog()
|
||||
for file in Path(CATALOG_DIR).glob('*'+CATALOG_SUFFIX):
|
||||
c = AntaCatalog.parse(file)
|
||||
device = str(file).removesuffix(CATALOG_SUFFIX).removeprefix(CATALOG_DIR)
|
||||
print(f"Merging test catalog for device {device}")
|
||||
# Apply filters to all tests for this device
|
||||
for test in c.tests:
|
||||
test.inputs.filters = AntaTest.Input.Filters(tags=[device])
|
||||
catalog = catalog.merge(c)
|
||||
with open(Path('anta-catalog.yml'), "w") as f:
|
||||
f.write(catalog.dump().yaml())
|
||||
--8<-- "merge_catalogs.py"
|
||||
```
|
||||
|
||||
!!! warning
|
||||
The `AntaCatalog.merge()` method is deprecated and will be removed in ANTA v2.0. Please use the `AntaCatalog.merge_catalogs()` class method instead.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue