anta
anta copied to clipboard
Implement `anta get tests` to generate a test catalog example
Implementing a new CLI that could be named 'anta get tests' to generate test catalog example is now possible leveraging pydantic-modeled test inputs.
https://github.com/ghandic/jsf is a Python library that can generate Python dictionary from the JSON schema provided by pydantic.
The following example generate test input example for the test anta.tests.connectivity.VerifyReachability:
from anta.tests.connectivity import VerifyReachability
from jsf import JSF
import yaml
faker = JSF(VerifyReachability.Input.model_json_schema())
print(yaml.dump(faker.generate()))
# hosts: []
print(yaml.dump(faker.generate()))
# hosts: []
# result_overwrite: null
print(yaml.dump(faker.generate()))
# hosts:
# - dst: 61.200.94.158
# src: 60.161.20.184
# - dst: 126.193.52.72
# src: 5.207.132.13
# vrf: culpa! veniam quas quas veniam molestias, esse
# result_overwrite:
# custom_field: dolor
# description: dolor possimus possimus illum
Requires
- [x] https://github.com/arista-netdevops-community/anta/pull/315
- [x] https://github.com/ghandic/jsf/pull/77
- [x] https://github.com/ghandic/jsf/pull/78
- [ ] Deal with the randomness: for optional fields, we must always have a value. For data structure (list, dict...) potentially empty, we must always have at least one entry.