diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-15 20:30:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-15 20:32:01 +0000 |
commit | e45744e7c5b9916c398fe41273194ffb671fcdac (patch) | |
tree | 620ad07a959cf23c8fef76d2967d31eb9c29e6ec /examples/merge_catalogs.py | |
parent | Releasing debian version 1.0.0-1. (diff) | |
download | anta-e45744e7c5b9916c398fe41273194ffb671fcdac.tar.xz anta-e45744e7c5b9916c398fe41273194ffb671fcdac.zip |
Merging upstream version 1.1.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/merge_catalogs.py')
-rw-r--r-- | examples/merge_catalogs.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/merge_catalogs.py b/examples/merge_catalogs.py new file mode 100644 index 0000000..1d594be --- /dev/null +++ b/examples/merge_catalogs.py @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Arista Networks, Inc. +# Use of this source code is governed by the Apache License 2.0 +# that can be found in the LICENSE file. +"""Script that merge a collection of catalogs into one AntaCatalog.""" + +from pathlib import Path + +from anta.catalog import AntaCatalog +from anta.models import AntaTest + +CATALOG_SUFFIX = "-catalog.yml" +CATALOG_DIR = "intended/test_catalogs/" + +if __name__ == "__main__": + catalogs = [] + for file in Path(CATALOG_DIR).glob("*" + CATALOG_SUFFIX): + device = str(file).removesuffix(CATALOG_SUFFIX).removeprefix(CATALOG_DIR) + print(f"Loading test catalog for device {device}") + catalog = AntaCatalog.parse(file) + # Add the device name as a tag to all tests in the catalog + for test in catalog.tests: + test.inputs.filters = AntaTest.Input.Filters(tags={device}) + catalogs.append(catalog) + + # Merge all catalogs + merged_catalog = AntaCatalog.merge_catalogs(catalogs) + + # Save the merged catalog to a file + with Path("anta-catalog.yml").open("w") as f: + f.write(merged_catalog.dump().yaml()) |