Debian Codegraph @

examples/merge_catalogs.py

raw symbols SCIP
1 # Copyright (c) 2024 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the LICENSE file.
4 """Script that merge a collection of catalogs into one AntaCatalog."""
5
6 from pathlib import Path
7
8 from anta.catalog import AntaCatalog
9 from anta.models import AntaTest
10
11 CATALOG_SUFFIX = "-catalog.yml"
12 CATALOG_DIR = "intended/test_catalogs/"
13
14 if __name__ == "__main__":
15 catalogs = []
16 for file in Path(CATALOG_DIR).glob("*" + CATALOG_SUFFIX):
17 device = str(file).removesuffix(CATALOG_SUFFIX).removeprefix(CATALOG_DIR)
18 print(f"Loading test catalog for device {device}")
19 catalog = AntaCatalog.parse(file)
20 # Add the device name as a tag to all tests in the catalog
21 for test in catalog.tests:
22 test.inputs.filters = AntaTest.Input.Filters(tags={device})
23 catalogs.append(catalog)
24
25 # Merge all catalogs
26 merged_catalog = AntaCatalog.merge_catalogs(catalogs)
27
28 # Save the merged catalog to a file
29 with Path("anta-catalog.yml").open("w") as f:
30 f.write(merged_catalog.dump().yaml())