Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add gh-admonition plugin #966

Merged
merged 11 commits into from
Dec 16, 2024
10 changes: 6 additions & 4 deletions docs/advanced_usages/as-python-lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

ANTA is a Python library that can be used in user applications. This section describes how you can leverage ANTA Python modules to help you create your own NRFU solution.

!!! tip
If you are unfamiliar with asyncio, refer to the Python documentation relevant to your Python version - https://docs.python.org/3/library/asyncio.html
> [!TIP]
> If you are unfamiliar with asyncio, refer to the Python documentation relevant to your Python version - https://docs.python.org/3/library/asyncio.html

## [AntaDevice](../api/device.md#anta.device.AntaDevice) Abstract Class

Expand Down Expand Up @@ -47,8 +47,10 @@ The [AntaInventory](../api/inventory.md#anta.inventory.AntaInventory) class is a
--8<-- "parse_anta_inventory_file.py"
```

!!! note "How to create your inventory file"
Please visit this [dedicated section](../usage-inventory-catalog.md) for how to use inventory and catalog files.
> [!NOTE]
> **How to create your inventory file**
>
> Please visit this [dedicated section](../usage-inventory-catalog.md) for how to use inventory and catalog files.

### Run EOS commands

Expand Down
74 changes: 40 additions & 34 deletions docs/advanced_usages/custom-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
~ that can be found in the LICENSE file.
-->

!!! info
This documentation applies for both creating tests in ANTA or creating your own test package.
> [!INFO]
> This documentation applies for both creating tests in ANTA or creating your own test package.

ANTA is not only a Python library with a CLI and a collection of built-in tests, it is also a framework you can extend by building your own tests.

Expand All @@ -15,7 +15,7 @@ A test is a Python class where a test function is defined and will be run by the

ANTA provides an abstract class [AntaTest](../api/models.md#anta.models.AntaTest). This class does the heavy lifting and provide the logic to define, collect and test data. The code below is an example of a simple test in ANTA, which is an [AntaTest](../api/models.md#anta.models.AntaTest) subclass:

```python
````python
from anta.models import AntaTest, AntaCommand
from anta.decorators import skip_on_platforms

Expand Down Expand Up @@ -49,7 +49,7 @@ class VerifyTemperature(AntaTest):
self.result.is_success()
else:
self.result.is_failure(f"Device temperature exceeds acceptable limits. Current system status: '{temperature_status}'")
```
````

[AntaTest](../api/models.md#anta.models.AntaTest) also provide more advanced capabilities like [AntaCommand](../api/models.md#anta.models.AntaCommand) templating using the [AntaTemplate](../api/models.md#anta.models.AntaTemplate) class or test inputs definition and validation using [AntaTest.Input](../api/models.md#anta.models.AntaTest.Input) [pydantic](https://docs.pydantic.dev/latest/) model. This will be discussed in the sections below.

Expand All @@ -64,8 +64,8 @@ Full AntaTest API documentation is available in the [API documentation section](
- `categories` (`list[str]`): A list of categories in which the test belongs.
- `commands` (`[list[AntaCommand | AntaTemplate]]`): A list of command to collect from devices. This list **must** be a list of [AntaCommand](../api/models.md#anta.models.AntaCommand) or [AntaTemplate](../api/models.md#anta.models.AntaTemplate) instances. Rendering [AntaTemplate](../api/models.md#anta.models.AntaTemplate) instances will be discussed later.

!!! info
All these class attributes are mandatory. If any attribute is missing, a `NotImplementedError` exception will be raised during class instantiation.
> [!INFO]
> All these class attributes are mandatory. If any attribute is missing, a `NotImplementedError` exception will be raised during class instantiation.

### Instance Attributes

Expand All @@ -82,11 +82,15 @@ Full AntaTest API documentation is available in the [API documentation section](
show_root_toc_entry: false
heading_level: 10

!!! note "Logger object"
ANTA already provides comprehensive logging at every steps of a test execution. The [AntaTest](../api/models.md#anta.models.AntaTest) class also provides a `logger` attribute that is a Python logger specific to the test instance. See [Python documentation](https://docs.python.org/3/library/logging.html) for more information.

!!! note "AntaDevice object"
Even if `device` is not a private attribute, you should not need to access this object in your code.
> [!NOTE]
>
> - **Logger object**
>
> ANTA already provides comprehensive logging at every steps of a test execution. The [AntaTest](../api/models.md#anta.models.AntaTest) class also provides a `logger` attribute that is a Python logger specific to the test instance. See [Python documentation](https://docs.python.org/3/library/logging.html) for more information.
>
> - **AntaDevice object**
>
> Even if `device` is not a private attribute, you should not need to access this object in your code.

### Test Inputs

Expand Down Expand Up @@ -129,8 +133,8 @@ Full `ResultOverwrite` model documentation is available in [API documentation se
show_root_toc_entry: false
heading_level: 10

!!! note
The pydantic model is configured using the [`extra=forbid`](https://docs.pydantic.dev/latest/usage/model_config/#extra-attributes) that will fail input validation if extra fields are provided.
> [!NOTE]
> The pydantic model is configured using the [`extra=forbid`](https://docs.pydantic.dev/latest/usage/model_config/#extra-attributes) that will fail input validation if extra fields are provided.

### Methods

Expand Down Expand Up @@ -160,8 +164,8 @@ In this section, we will go into all the details of writing an [AntaTest](../api
Import [anta.models.AntaTest](../api/models.md#anta.models.AntaTest) and define your own class.
Define the mandatory class attributes using [anta.models.AntaCommand](../api/models.md#anta.models.AntaCommand), [anta.models.AntaTemplate](../api/models.md#anta.models.AntaTemplate) or both.

!!! info
Caching can be disabled per `AntaCommand` or `AntaTemplate` by setting the `use_cache` argument to `False`. For more details about how caching is implemented in ANTA, please refer to [Caching in ANTA](../advanced_usages/caching.md).
> [!NOTE]
> Caching can be disabled per `AntaCommand` or `AntaTemplate` by setting the `use_cache` argument to `False`. For more details about how caching is implemented in ANTA, please refer to [Caching in ANTA](../advanced_usages/caching.md).

```python
from anta.models import AntaTest, AntaCommand, AntaTemplate
Expand Down Expand Up @@ -193,21 +197,23 @@ class <YourTestName>(AntaTest):
]
```

!!! tip "Command revision and version"
* Most of EOS commands return a JSON structure according to a model (some commands may not be modeled hence the necessity to use `text` outformat sometimes.
* The model can change across time (adding feature, ... ) and when the model is changed in a non backward-compatible way, the **revision** number is bumped. The initial model starts with **revision** 1.
* A **revision** applies to a particular CLI command whereas a **version** is global to an eAPI call. The **version** is internally translated to a specific **revision** for each CLI command in the RPC call. The currently supported **version** values are `1` and `latest`.
* A **revision takes precedence over a version** (e.g. if a command is run with version="latest" and revision=1, the first revision of the model is returned)
* By default, eAPI returns the first revision of each model to ensure that when upgrading, integrations with existing tools are not broken. This is done by using by default `version=1` in eAPI calls.

By default, ANTA uses `version="latest"` in AntaCommand, but when developing tests, the revision MUST be provided when the outformat of the command is `json`. As explained earlier, this is to ensure that the eAPI always returns the same output model and that the test remains always valid from the day it was created. For some commands, you may also want to run them with a different revision or version.

For instance, the `VerifyBFDPeersHealth` test leverages the first revision of `show bfd peers`:

```
# revision 1 as later revision introduce additional nesting for type
commands = [AntaCommand(command="show bfd peers", revision=1)]
```
> [!TIP]
> **Command revision and version**
>
> - Most of EOS commands return a JSON structure according to a model (some commands may not be modeled hence the necessity to use `text` outformat sometimes.
> - The model can change across time (adding feature, ... ) and when the model is changed in a non backward-compatible way, the **revision** number is bumped. The initial model starts with **revision** 1.
> - A **revision** applies to a particular CLI command whereas a **version** is global to an eAPI call. The **version** is internally translated to a specific **revision** for each CLI command in the RPC call. The currently supported **version** values are `1` and `latest`.
> - A **revision takes precedence over a version** (e.g. if a command is run with version="latest" and revision=1, the first revision of the model is returned)
> - By default, eAPI returns the first revision of each model to ensure that when upgrading, integrations with existing tools are not broken. This is done by using by default `version=1` in eAPI calls.
>
> By default, ANTA uses `version="latest"` in AntaCommand, but when developing tests, the revision MUST be provided when the outformat of the command is `json`. As explained earlier, this is to ensure that the eAPI always returns the same output model and that the test remains always valid from the day it was created. For some commands, you may also want to run them with a different revision or version.
>
> For instance, the `VerifyBFDPeersHealth` test leverages the first revision of `show bfd peers`:
>
> ```python
> # revision 1 as later revision introduce additional nesting for type
> commands = [AntaCommand(command="show bfd peers", revision=1)]
> ```

### Inputs definition

Expand Down Expand Up @@ -242,8 +248,8 @@ You can also leverage [anta.custom_types](../api/types.md) that provides reusabl

Regarding required, optional and nullable fields, refer to this [documentation](https://docs.pydantic.dev/latest/migration/#required-optional-and-nullable-fields) on how to define them.

!!! note
All the `pydantic` features are supported. For instance you can define [validators](https://docs.pydantic.dev/latest/usage/validators/) for complex input validation.
> [!NOTE]
> All the `pydantic` features are supported. For instance you can define [validators](https://docs.pydantic.dev/latest/usage/validators/) for complex input validation.

### Template rendering

Expand Down Expand Up @@ -338,8 +344,8 @@ class VerifyTemperature(AntaTest):

## Access your custom tests in the test catalog

!!! warning ""
This section is required only if you are not merging your development into ANTA. Otherwise, just follow [contribution guide](../contribution.md).
> [!WARNING]
> This section is required only if you are not merging your development into ANTA. Otherwise, just follow [contribution guide](../contribution.md).

For that, you need to create your own Python package as described in this [hitchhiker's guide](https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/) to package Python code. We assume it is well known and we won't focus on this aspect. Thus, your package must be importable by ANTA hence available in the module search path `sys.path` (you can use `PYTHONPATH` for example).

Expand Down
5 changes: 3 additions & 2 deletions docs/cli/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Options:
--help Show this message and exit.
```

> [!TIP]
> `username`, `password`, `enable-password`, `enable`, `timeout` and `insecure` values are the same for all devices

### Example
Expand Down Expand Up @@ -162,8 +163,8 @@ Run templated command 'show vlan {vlan_id}' with {'vlan_id': '10'} on DC1-LEAF1A

### Example of multiple arguments

!!! warning
If multiple arguments of the same key are provided, only the last argument value will be kept in the template parameters.
> [!WARNING]
> If multiple arguments of the same key are provided, only the last argument value will be kept in the template parameters.

```bash
anta -log DEBUG debug run-template --template "ping {dst} source {src}" dst "8.8.8.8" src Loopback0 --device DC1-SPINE1    
Expand Down
12 changes: 8 additions & 4 deletions docs/cli/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Options:
--help Show this message and exit.
```

> [!TIP]
> `username`, `password`, `enable-password`, `enable`, `timeout` and `insecure` values are the same for all devices

### Example
Expand Down Expand Up @@ -242,6 +243,7 @@ Options:
--help Show this message and exit.
```

> [!TIP]
> `username`, `password`, `enable-password`, `enable`, `timeout` and `insecure` values are the same for all devices

When executed, this command fetches tech-support files and downloads them locally into a device-specific subfolder within the designated folder. You can specify the output folder with the `--output` option.
Expand All @@ -250,15 +252,17 @@ ANTA uses SCP to download files from devices and will not trust unknown SSH host

The configuration `aaa authorization exec default` must be present on devices to be able to use SCP.

!!! warning Deprecation
ANTA can automatically configure `aaa authorization exec default local` using the `anta exec collect-tech-support --configure` option but this option is deprecated and will be removed in ANTA 2.0.0.
> [!CAUTION]
> **Deprecation**
>
> ANTA can automatically configure `aaa authorization exec default local` using the `anta exec collect-tech-support --configure` option but this option is deprecated and will be removed in ANTA 2.0.0.

If you require specific AAA configuration for `aaa authorization exec default`, like `aaa authorization exec default none` or `aaa authorization exec default group tacacs+`, you will need to configure it manually.

The `--latest` option allows retrieval of a specific number of the most recent tech-support files.

!!! warning
By default **all** the tech-support files present on the devices are retrieved.
> [!WARNING]
> By default **all** the tech-support files present on the devices are retrieved.

### Example

Expand Down
4 changes: 2 additions & 2 deletions docs/cli/get-inventory-information.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Options:
--help Show this message and exit.
```

!!! tip
By default, `anta get inventory` only provides information that doesn't rely on a device connection. If you are interested in obtaining connection-dependent details, like the hardware model, use the `--connected` option.
> [!TIP]
> By default, `anta get inventory` only provides information that doesn't rely on a device connection. If you are interested in obtaining connection-dependent details, like the hardware model, use the `--connected` option.

### Example

Expand Down
9 changes: 4 additions & 5 deletions docs/cli/get-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Options:
--help Show this message and exit.
```

!!! tip
By default, `anta get tests` will retrieve all tests available in ANTA.
> [!TIP]
> By default, `anta get tests` will retrieve all tests available in ANTA.

### Examples

Expand Down Expand Up @@ -91,9 +91,8 @@ anta.tests.aaa:
vrf: MGMT
```

!!! tip

You can filter tests by providing a prefix - ANTA will return all tests that start with your specified string.
> [!TIP]
> You can filter tests by providing a prefix - ANTA will return all tests that start with your specified string.

```yaml title="anta get tests --test VerifyTacacs"
anta.tests.aaa:
Expand Down
13 changes: 7 additions & 6 deletions docs/cli/inv-from-ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ Options:
--help Show this message and exit.
```

!!! warning "Warnings"

* `anta get from-ansible` does not support inline vaulted variables, comment them out to generate your inventory.
If the vaulted variable is necessary to build the inventory (e.g. `ansible_host`), it needs to be unvaulted for `from-ansible` command to work."

* The current implementation only considers devices directly attached to a specific Ansible group and does not support inheritance when using the `--ansible-group` option.
> [!WARNING]
>
> - `anta get from-ansible` does not support inline vaulted variables, comment them out to generate your inventory.
>
> - If the vaulted variable is necessary to build the inventory (e.g. `ansible_host`), it needs to be unvaulted for `from-ansible` command to work."
>
> - The current implementation only considers devices directly attached to a specific Ansible group and does not support inheritance when using the `--ansible-group` option.

By default, if user does not provide `--output` file, anta will save output to configured anta inventory (`anta --inventory`). If the output file has content, anta will ask user to overwrite when running in interactive console. This mechanism can be controlled by triggers in case of CI usage: `--overwrite` to force anta to overwrite file. If not set, anta will exit

Expand Down
4 changes: 2 additions & 2 deletions docs/cli/inv-from-cvp.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ anta_inventory:
- pod2
```

!!! warning
The current implementation only considers devices directly attached to a specific container when using the `--cvp-container` option.
> [!WARNING]
> The current implementation only considers devices directly attached to a specific container when using the `--cvp-container` option.

## Creating an inventory from multiple containers

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/nrfu.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ANTA provides a set of commands for performing NRFU tests on devices. These comm

All commands under the `anta nrfu` namespace require a catalog yaml file specified with the `--catalog` option and a device inventory file specified with the `--inventory` option.

!!! info
> [!TIP]
Issuing the command `anta nrfu` will run `anta nrfu table` without any option.
gmuloc marked this conversation as resolved.
Show resolved Hide resolved

### Tag management
Expand Down
11 changes: 6 additions & 5 deletions docs/cli/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ Then, run the CLI without options:
anta nrfu
```

!!! note
All environment variables may not be needed for every commands.
Refer to `<command> --help` for the comprehensive environment variables names.
> [!NOTE]
> All environment variables may not be needed for every commands.
>
> Refer to `<command> --help` for the comprehensive environment variables names.

Below are the environment variables usable with the `anta nrfu` command:

Expand All @@ -63,8 +64,8 @@ Below are the environment variables usable with the `anta nrfu` command:
| ANTA_ENABLE | Whether it is necessary to go to enable mode on devices. | No |
| ANTA_ENABLE_PASSWORD | The optional enable password, when this variable is set, ANTA_ENABLE or `--enable` is required. | No |

!!! info
Caching can be disabled with the global parameter `--disable-cache`. For more details about how caching is implemented in ANTA, please refer to [Caching in ANTA](../advanced_usages/caching.md).
> [!NOTE]
> Caching can be disabled with the global parameter `--disable-cache`. For more details about how caching is implemented in ANTA, please refer to [Caching in ANTA](../advanced_usages/caching.md).

## ANTA Exit Codes

Expand Down
9 changes: 5 additions & 4 deletions docs/cli/tag-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ anta.tests.interfaces:
tags: ['spine']
```

> A tag used to filter a test can also be a device name

!!! tip "Use different input values for a specific test"
Leverage tags to define different input values for a specific test. See the `VerifyUptime` example above.
> [!TIP]
>
> - A tag used to filter a test can also be a device name
>
> - **Use different input values for a specific test**: Leverage tags to define different input values for a specific test. See the `VerifyUptime` example above.

## Using tags

Expand Down
4 changes: 2 additions & 2 deletions docs/contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ Success: no issues found in 82 source files

> NOTE: Typing is configured quite strictly, do not hesitate to reach out if you have any questions, struggles, nightmares.

## Unit tests
## Unit tests with Pytest

To keep high quality code, we require to provide a Pytest for every tests implemented in ANTA.
To keep high quality code, we require to provide a **Pytest** for every tests implemented in ANTA.

All submodule should have its own pytest section under `tests/units/anta_tests/<submodule-name>.py`.

Expand Down
Loading
Loading