Skip to content

Commit

Permalink
docs for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Sep 10, 2024
1 parent 0b51fc0 commit 89e9f68
Show file tree
Hide file tree
Showing 16 changed files with 284 additions and 124 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<img src="https://github.com/amyasnikov/validity/actions/workflows/ci.yml/badge.svg" alt="CI">
<img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/amyasnikov/9e518ae8babd18b7edd8ee5aad58146b/raw/cov.json" alt="Coverage">
<img src="https://img.shields.io/badge/Python-3.10+-blue.svg" alt="Python version">
<img src="https://img.shields.io/badge/NetBox-3.6|3.7|4.0-blue.svg" alt="NetBox version">
<img src="https://img.shields.io/badge/NetBox-3.7|4.0|4.1-blue.svg" alt="NetBox version">
</p>
</div>

<!--mkdocs-start-->
## What?
Validity is the [NetBox](https://netbox.dev) plugin to write "auto tests" for your network devices. You define compliance tests and Validity checks device state or configuration against these tests. The two most obvious use cases for such a functionality include:
Validity is the [NetBox](https://netboxlabs.com/oss/netbox/) plugin to write "auto tests" for your network devices. You define compliance tests and Validity checks device state or configuration against these tests. The two most obvious use cases for such a functionality include:

* **Configuration compliance**. You can make sure your devices are provisioned properly, and their config follows the rules you have defined via tests.
* **Pre- / post-configuration checks**. You can make sure your network is in the expected state before or/and after configuration changes have been made. You can use Validity API to include these checks into your automation pipelines.
Expand Down Expand Up @@ -56,6 +56,8 @@ Validity aims to support **the latest 3 major/minor releases of NetBox**.

For example, if latest NetBox version is 4.1, then latest Validity is going to support NetBox 4.1, 4.0 and 3.7.

Check out [compatibility matrix](https://validity.readthedocs.io/en/latest/installation/netbox_compatibility/) for the details.


## Download and Install

Expand Down
10 changes: 4 additions & 6 deletions docs/entities/results_and_reports.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Test Results

Test Results are produced by Validity as a result of [Run Compliance Tests](scripts.md#run-compliance-tests) script execution.
Test Results are produced by Validity as a result of [Run Tests](scripts.md#run-tests) script execution.

One Test Result represents the execution of one Compliance Test against one Device.

Old Test Results are the subject for auto-deletion. See [Settings](../plugin_settings.md#store_last_results) for details.
Old Test Results are the subject for auto-deletion. See [Settings](../installation/plugin_settings.md#store_reports) for details.

## Fields

Expand Down Expand Up @@ -33,7 +33,7 @@ Boolean result of the Compliance Test Expression execution. PASSED or FAILED.

#### Report

Report this test is bound to. Compliance test may not be bound to any Report. You can define it at the start of [Run Compliance Tests](scripts.md#run-compliance-tests) using "Create Report" checkmark.
Report this test is bound to. Compliance test may not be bound to any Report. You can define it at the start of [Run Tests](scripts.md#run-tests) using "Create Report" checkmark.

#### Explanation

Expand All @@ -58,9 +58,7 @@ For this expression you can get the following explanation:

# Reports

Report ties together Test Results generated from one execution of the [Run Compliance Tests](scripts.md#run-compliance-tests) script.

A user may choose either to create a report together with the Test Results during the Run Compliance Tests script execution or no.
Report ties together Test Results generated from one execution of the [Run Tests](scripts.md#run-tests) script.

At the report page you can observe test result statistics (total and grouped by severity). Moreover, in web GUI you can choose an additional param to group the results by and display the statistics for each group.

Expand Down
48 changes: 35 additions & 13 deletions docs/entities/scripts.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
# Custom Scripts
# Scripts

Validity is shipped together with some [Custom Scripts](https://docs.netbox.dev/en/stable/customization/custom-scripts/).
**Scripts** is the way Validity executes long-running tasks. Previously Validity used [NetBox Custom Scripts](https://netboxlabs.com/docs/netbox/en/stable/customization/custom-scripts/) feature for this purpose, but since **release 3.0.0** Validity uses [RQ](https://python-rq.org/) directly to execute its long-running jobs (out of habit, still called "scripts").

The scripts are available under `Customization > Scripts` GUI menu.
## Run Tests

## Run Compliance Tests
This script executes Compliance Tests and creates Report and Test Result instances.

This script executes Compliance Tests and creates Test Result instances.
The script also performs a bunch of auxiliary actions such as:

This script also deletes the old Test Results and Reports if they exceed the maximum number from [settings](../plugin_settings.md).
* Related Data Sources Sync (if requested from user)
* Deletion of old Reports and Tests Results (see [store_reports](../installation/plugin_settings.md#store_reports) setting)

The script may generate a lot of DB queries. To spread the queries over time you can adjust [sleep_between_tests](../plugin_settings.md#sleep_between_tests) setting.

#### Params
### Parallel Tests Execution

Validity allows splitting Tests Execution between multiple RQ workers. In this case each RQ worker executes its own portion of the work reducing the overall time required to process all amount of Tests.

Tests Execution is divided between multiple workers on a per-device basis. It means that all the Tests for one particular Device will always be executed on one single worker.

For example if you have 100 devices and want to execute the Tests for them on 3 workers in parallel, just choose `workers_num=3`, it will lead to two of the workers serving 33 devices each and the last one serving 34.

!!! note
It's the responsibility of NetBox administrator to spawn multiple RQ workers. In most of the deployments there is only one worker by default.


### Execution Params

| **Param** | **API Param** | **Description** |
|-----------------------------|---------------|-------------------------------------------------------------------|
| Sync Data Sources | sync_datasources | Sync all Data Sources which are bound to Devices<br/> participating in the script execution|
| Make Compliance<br/>Report | make_report | Create Report together with Test Results |
| Sync Data Sources | sync_datasources | Sync all Data Sources which are bound to Devices participating in the script execution|
| Specific Selectors | selectors | Run the tests only for a limited number of selectors |
| Specific Devices | devices | Run the tests only for a limited number of devices. |
| Specific Test Tags | test_tags | Run only those tests which have at least one of<br/> the specified tags|
| Explanation Verbosity<br/>Level | explanation_verbosity | **0** - No explanation at all.<br/>**1** - Explanation of the calculation steps<br/>**2** - the same as **1** plus deepdiff value in case of<br/> comparisons|
| Override DataSource | override_datasource| Ignore Data Sources bound to Devices and use<br/> this one instead. It may be useful if you want to<br/> use **Validity Polling** Data Source just to run some<br/> operational tests only for now.|
| Specific Test Tags | test_tags | Run only those tests which have at least one of the specified tags|
| Explanation Verbosity Level | explanation_verbosity | **0** - No explanation at all.**1** - Explanation of the calculation steps**2** - the same as **1** plus deepdiff value in case of comparisons|
| Number of Workers | workers_num | Number of RQ workers to split test execution between them |
| Override DataSource | overriding_datasource| Ignore Data Sources bound to Devices and use this one instead. It may be useful if you want to use **Validity Polling** Data Source just to run some operational tests only for now.|


### Stages
Internally Run Tests script has 3 stages:

* **split**: synchronizes Data Sources (if requested by user) and splits test execution into splices
* **apply**: Executes portion of tests assigned to it at split stage and saves the results to database. Only this stage can be executed on multiple workers in parallel
* **combine**: collects the overall statistics, fires webhook (if configured)

Each stage has its own timeout which can be adjusted in [Plugin Settings](../installation/plugin_settings.md#script_timeouts)
2 changes: 1 addition & 1 deletion docs/entities/serializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Validity has an option to parse MikroTik RouterOS config files. You just need `R

!!! warning
Parser works only with **configuration** which structure strictly follows the `/export` command format.
If you want to work with operational state (`print`-commands), the easiest way would be to leverage MikroTik REST API and [YAML](#YAML) serializer.
If you want to work with operational state (`print`-commands), the easiest way would be to leverage MikroTik REST API and [JSON/YAML](#yaml) serializer.

**Input data:**
```
Expand Down
3 changes: 3 additions & 0 deletions docs/extra_styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.md-grid {
max-width: 1470px;
}
21 changes: 15 additions & 6 deletions docs/features/webhooks.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Webhooks

NetBox has a built-in feature called [Webhooks](https://docs.netbox.dev/en/stable/integrations/webhooks/). This feature allows a user to provision a webhook to a custom endpoint when some NetBox model is created/updated/deleted.
NetBox has a built-in feature called [Event Rules](https://netboxlabs.com/docs/netbox/en/stable/models/extras/eventrule/) and [Webhooks](https://netboxlabs.com/docs/netbox/en/stable/models/extras/webhook/). This feature allows a user to provision a webhook to a custom endpoint when some NetBox model is created/updated/deleted.

The webhook may be provisioned to capture Compliance Report creation. Using this approach you can notify some third party system (OSS/BSS/Monitoring/etc.) about the overall compliance state of your network.

Let's create a webhook using [pynetbox](https://github.com/netbox-community/pynetbox) library.
Let's create a webhook and an event rule using [pynetbox](https://github.com/netbox-community/pynetbox) library.

You may do the same thing using web GUI (`Other > Webhooks` menu)

Expand All @@ -15,16 +15,25 @@ token = 'get api token via web gui and place it here'

nb = Api(url='http://127.0.0.1:8000', token=token)

nb.extras.webhooks.create(
webhook = nb.extras.webhooks.create(
name='sample_webhook',
type_create=True, # bind webhook to object creation event
payload_url='http://localhost:9000/api/webhook/',
http_method='POST',
content_types=['validity.compliancereport']
ssl_verification=False,
)

nb.extras.event_rules.create(
name="sample_event",
object_types=["validity.compliancereport"],
event_types=["object_created"],
action_type="webhook",
action_object_type="extras.webhook",
action_object=webhook.id
)

```

It's done. Now when Run Compliance Tests script finishes its work, it will trigger a webhook to the `http://localhost:9000/api/webhook/` handle.
It's done. Now when Run Compliance Tests script finishes its work, it will trigger the webhook to the `http://localhost:9000/api/webhook/` handle.


Here is the example contents of the webhook configured above:
Expand Down
6 changes: 3 additions & 3 deletions docs/installation.md → docs/installation/installation.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Installation


Validity is the [NetBox](https://netbox.dev/) plugin. So, before installing validity you have to install NetBox first. Please refer [NetBox docs](https://docs.netbox.dev/en/stable/installation/) for how to do it.
Validity is the [NetBox](https://netboxlabs.com/oss/netbox/) plugin. So, before installing Validity you have to install NetBox first. Please refer [NetBox docs](https://netboxlabs.com/docs/netbox/en/stable/installation/) for how to do it.

## System Requirements
## System Requirements (latest version)

| **Python** | **NetBox** |
|------------|-----------------|
| >=3.10 | 3.6 &#124; 3.7 &#124; 4.0 |
| >=3.10 | 3.7 &#124; 4.0 &#124; 4.1 |

## Installation steps
Once you have installed NetBox, you should follow these steps
Expand Down
77 changes: 77 additions & 0 deletions docs/installation/netbox_compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# NetBox Compatibility

Each Validity version supports 3 NetBox releases: the current one (at the moment of the release) plus two previous ones.

In the table below you can find appropriate Validity version according to your NetBox version.

!!! info
Only the most appropriate Validity versions are listed in the table. For example, v2.0 is not listed in favor of v2.2 (v2.0 and v2.2 support the same set of NetBox versions, but v2.2 has more features).



#### NetBox Compatibility Table

<style type="text/css">
.tg {border-collapse:collapse;border-color:#9ABAD9;border-spacing:0;}
.tg td{background-color:#EBF5FF;border-color:#9ABAD9;border-style:solid;border-width:1px;color:#444;
font-family:Arial, sans-serif;font-size:14px;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{background-color:#409cff;border-color:#9ABAD9;border-style:solid;border-width:1px;color:#fff;
font-family:Arial, sans-serif;font-size:14px;font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-r82u{background-color:#ebf5ff;border-color:#330001;text-align:center;vertical-align:top}
.tg .tg-c6ba{border-color:#330001;font-weight:bold;text-align:center;vertical-align:top}
.tg .tg-5gjp{background-color:#ebf5ff;border-color:#330001;color:#444444;font-weight:bold;text-align:center;vertical-align:top}
.tg .tg-5iin{background-color:#409cff;border-color:#330001;color:#ebf5ff;font-weight:bold;text-align:center;vertical-align:top}
.tg .tg-8g55{border-color:#330001;text-align:center;vertical-align:top}
</style>
<table class="tg"><thead>
<tr>
<th class="tg-r82u" colspan="2" rowspan="2"></th>
<th class="tg-c6ba" colspan="6">NetBox<br></th>
</tr>
<tr>
<th class="tg-5gjp">v3.4</th>
<th class="tg-5gjp">v3.5</th>
<th class="tg-5gjp">v3.6</th>
<th class="tg-5gjp">v3.7</th>
<th class="tg-5gjp">v4.0</th>
<th class="tg-5gjp">v4.1</th>
</tr></thead>
<tbody>
<tr>
<td class="tg-5iin" rowspan="4">Validity<br><br></td>
<td class="tg-c6ba">v1.4</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55"></td>
<td class="tg-8g55"></td>
<td class="tg-8g55"></td>
</tr>
<tr>
<td class="tg-c6ba">v2.2</td>
<td class="tg-8g55"></td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55"></td>
<td class="tg-8g55"></td>
</tr>
<tr>
<td class="tg-c6ba">v2.3</td>
<td class="tg-8g55"></td>
<td class="tg-8g55"></td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55"></td>
</tr>
<tr>
<td class="tg-c6ba">v3.0</td>
<td class="tg-8g55"></td>
<td class="tg-8g55"></td>
<td class="tg-8g55"></td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
<td class="tg-8g55">✅</td>
</tr>
</tbody></table>
86 changes: 86 additions & 0 deletions docs/installation/plugin_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Plugin Settings


Validity has some settings which can be changed through [PLUGINS_CONFIG](https://docs.netbox.dev/en/stable/plugins/#configure-plugin) variable inside your `configuration.py`.

## Settings

### result_batch_size

*Default:* `500`

*Type:* `int`

Execution of the Tests and producing Test Results is carried out in batches. As soon as each batch reaches its maximum size (specified via this variable) all the Test Results within a batch will be uploaded into a DB.


### store_reports

*Default:* `5`

*Type:* `int`

How many [Reports](../entities/results_and_reports.md#reports) should the system store.

If the system creates a new Report and the overall reports count exceeds *store_reports*, then the oldest exceeding report(s) will be deleted.

!!! note
Test Results bound to the Report will be deleted as well.


### polling_threads

*Default:* `500`

*Type:* `int`

Validity uses threads to perform device polling. This setting defines the upper limit of these threads number. If you have extremely large amount of devices (e.g. 100 000), you may want to increase this number to speed up the overall polling process.


### runtests_queue

*Default:* `"default"`

*Type:* `str`

RQ queue name for running the tests. May be useful if you want to move tests execution into separate queue (e.g. handled by separate set of workers)


### script_timeouts

*Type:* `dict`

This setting defines the timeouts for RQ jobs started by Validity (e.g. for running the tests). Timeout defines the maximum amount of time some job can run. If a job exceeds the timeout, it gets terminated.

As was mentioned in the [corresponding article](../entities/scripts.md#stages), **Run Tests** encompass 3 stages (split, apply, combine) where each stage has its own timeout.

| Timeout | Default Value |
|------------------|---------------|
| runtests_split | 10m |
| runtests_apply | 30m |
| runtests_combine | 10m |



## Settings Example

Here is the full example of Validity settings:

```python
# configuration.py

PLUGINS_CONFIG = {
'validity': {
'result_batch_size': 300,
'store_reports': 7,
'polling_threads': 100,
'runtests_queue': 'validity_tests',
'script_timeouts': {
'runtests_split': '15m',
'runtests_apply': '1h',
'runtests_combine': '5m',
},
},
# other plugins configuration
}
```
31 changes: 31 additions & 0 deletions docs/installation/upgrading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Upgrading to a new Validity release

Upgrade process is pretty straightforward:

* Make sure your NetBox version [is compatible](./netbox_compatibility.md) with the new Validity version

* Update the package version through pip

```
pip install --upgrade netbox-validity
```

* Run `migrate` and `collectstatic` management commands

```
./manage.py migrate
./manage.py collectstatic
```


## Major release upgrade

Major version upgrade (e.g. v2.x -> v3.x) may require some additional rules:

* Don't skip major version upgrades (e.g. don't upgrade 1.4.1 directly to 3.0.0)
* Before upgrading major version number, install the latest minor version first

For example, you want to upgrade from 2.1.1 to 3.0.0. To do this you have to

* install 2.3.3 (the latest available v2 release) first according to the procedure described above
* install 3.0.0
Loading

0 comments on commit 89e9f68

Please sign in to comment.