You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-64Lines changed: 29 additions & 64 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,26 +9,26 @@ One major difference between unit tests in programming and
9
9
network tests is the definition of what a test actually is.
10
10
In programming, unit tests normally focus on testing edge cases,
11
11
since the amount of non-edge cases is not definable.
12
-
In the network testing domain, tests are less about edge cases, but more about testing existing configurations with
12
+
In the network testing domain, tests are less about edge cases, but more about testing existing network states with
13
13
pre-defined test cases. Such a single test case might be "can host A reach neighbors X, Y, Z?" on many different devices.
14
14
This is what nuts tries to achieve:
15
-
Apply test cases based on your pre-defined network topology to your actual network and have the tests confirm the correct configuration.
15
+
Apply test cases based on your pre-defined network topology to your actual network and have the tests confirm the correct state.
16
16
17
17
The project relies on the [pytest framework](https://docs.pytest.org/) to setup and execute the tests.
18
18
Nuts itself is written as a custom pytest plugin. In the background, [nornir](https://nornir.readthedocs.io/)
19
19
executes specific network tasks for the actual tests.
20
20
21
-
Additionally, nuts treats the test definition and the so-called test bundle as separate entities.
21
+
Additionally, nuts treats the test definition and the so-called test bundle as separate entities. The *test definition* is modeled as a custom `pytest.Class`, and a predefined set of test definitions can be found in the module `base_tests`. New test definitions can be added easily by the user of the plugin.
22
22
23
-
The test definition is modelled as a custom `pytest.Class`, and a predefined set of test definitions can be found in the module `base_tests`. New test definitions can be added easily by the user of the plugin.
24
-
25
-
The test bundle is a file that is parsed by pytest. The file provides data on the actual network configuration and describes which test definitions should be collected and executed by pytest.
23
+
The *test bundle* is a file that is parsed by pytest. The file provides data on the desired network state and describes which test definitions should be collected and executed by pytest.
26
24
The structure of the test bundle should enable people without in-depth python knowledge to add new test bundles or update existing ones to reflect changes in the network.
27
25
26
+
While the readme here is only a short overview, find the [documentation of nuts on readthedocs](https://nuts.readthedocs.io/en/latest/).
27
+
28
28
## Test bundle structure
29
29
30
30
Currently only yaml files are supported as test bundles,
31
-
but other sources such as other file formats or database entries can be considered in later versions.
31
+
but other sources such as other file formats or database entries can be considered in later nuts versions.
32
32
33
33
Each test bundle contains the following structure:
34
34
```yaml
@@ -50,11 +50,11 @@ Note that currently every test in this class will be executed.
50
50
`label`: Additional identifier that can be used to distinguish between multiple occurrences of the same
51
51
test class in a test bundle.
52
52
53
-
`test_execution`: Data that is exposed as part of the `nuts_parameters` property (explanation see below).
53
+
`test_execution`: Data that is exposed as part of the `nuts_parameters` property.
54
54
By convention this contains additional information that is passed directly to the nornir task in the background.
55
55
Therefore the key-value pairs must be consistent with the key-value pairs of the specific nornir task.
56
56
As an example, the test definition `napalm_ping.py` calls a nornir task to execute napalm's ping-command.
57
-
This allows the additional `max_drop` parameter in `test execution`, since it is in turn pre-defined by napalm.
57
+
This allows the additional `max_drop` parameter in `test_execution`, since it is in turn pre-defined by napalm.
58
58
59
59
`test_data`: Data that is used to parametrize the tests in the test class which have the `pytest.mark.nuts` annotation. It is additionally part of the `nuts_parameters` property.
60
60
@@ -64,68 +64,60 @@ This example creates three different tests, one for each entry in the `test_data
During test collection, the custom pytest marker "nuts" uses the data that has been defined in the test bundle mentioned above.
101
-
This annotation is a wrapper around the `pytest.mark.parametrize` annotation and allows the plugin to use the data entries
102
-
from the test bundle. For each entry in the `test_data` section of the test bundle, the custom marker generates a single test case.
103
-
Each entry is a dictionary, but `pytest.mark.parametrize` expects a list of n-tuples as input.
104
-
The plugin therefore transforms those dictionary entries from `test_data` into tuples.
105
-
This transformation is currently fixed, but more flexibility is very likely to come at a later stage.
97
+
When nuts is executed, pytest converts the test bundles (the yaml files) into tests. During test collection, the custom pytest marker `nuts` uses the data that has been defined in the test bundle mentioned above.
98
+
This annotation is a wrapper around the `pytest.mark.parametrize` annotation and allows the plugin to use the data entries from the test bundle. For each entry in the `test_data` section of the test bundle, the custom marker generates a single test case. To achieve this, the plugin transforms the entries into n-tuples, since `pytest.mark.parametrize` expects a list of n-tuples as input.
106
99
107
100
The custom nuts marker takes two arguments: The first argument of the annotation determines the required fields.
108
101
For each entry in `test_data` these fields are extracted and transformed to a tuple considering the correct order.
109
102
If any of these fields are not present in an entry of `test_data`, the corresponding test case will be skipped.
110
-
The second argument determines optional fields that can also be used in a test case as well - non-present values are passed into the function as `None`.
103
+
A second argument determines optional fields that can also be used in a test case as well - non-present values are passed into the function as `None`.
111
104
112
105
#### Example of a test class with custom marker
113
106
114
107
```python
115
108
@pytest.mark.usefixtures("check_nuts_result") # see below
This testrun of CDP neighbors checks the local port.
115
+
This test-run of CDP neighbors checks the local port.
123
116
124
117
Before each test evaluation, the fixture `@pytest.mark.usefixtures("check_nuts_result")` checks the result of the network information that has been gathered by nornir in the background: It asserts that that no exception was thrown while doing so.
125
118
126
119
The required fields are `host`, `remote_host` and `local_port` - they must be present in the custom marker,
127
120
but also be provided as argument to the test method itself.
128
-
`management_ip` is an optional field and not necessary for the test - an entry in `test_data` is not required to have it.
129
121
130
122
`single_result` uses the `host` field and provides the result that has been processed via the specific context of a test.
131
123
@@ -136,40 +128,13 @@ Currently, the predefined test classes use [nornir](https://nornir.readthedocs.i
136
128
with the network devices, therefore the test classes derive all from a more specific `NornirNutsContext`,
137
129
which provides a nornir instance and nornir-specific helpers.
138
130
139
-
This context class is then integrated into pytest fixtures. It is passed on to another fixture called `sincle_result` that returns a per-host result of one test.
140
-
141
131
## Development
142
-
Nuts uses [poetry](https://python-poetry.org/) as a dependency manager.
143
-
If you have not installed poetry, please read their [installation instructions](https://python-poetry.org/docs/#installation).
144
-
145
-
### Installation requirements
146
132
147
-
```bash
148
-
poetry install
149
-
```
150
-
151
-
### Open shell with venv
152
-
153
-
```bash
154
-
poetry shell
155
-
```
156
-
157
-
### SonarQube
158
-
Our [sonarqube server](sonarqube.ins.work) automatically analyses our project via Gitlab CI.
159
-
If you prefer to run your analysis without pushing, you can trigger the analysis locally after executing the tests with coverage.
Copy file name to clipboardExpand all lines: docs/source/index.rst
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,6 @@ Enhance NUTS
42
42
Since NUTS is written as a pytest plugin and in python, you can customize it yourself and write your own test classes. Please see the :doc:`development section <dev/index>` to see how NUTS is structured and how to write your own test classes.
Copy file name to clipboardExpand all lines: docs/source/tutorial/firststeps.rst
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
First Steps with NUTS
2
2
=====================
3
3
4
-
This tutorial guides you through a minimal setup of NUTS.
4
+
This tutorial guides you through a minimal setup of the NetTowel Unit Testing System (NUTS, or nuts).
5
5
6
-
Two major components are needed for NUTS:
6
+
Two major components are needed for nuts:
7
7
8
8
#. A network inventory
9
9
#. Test bundles
@@ -71,7 +71,7 @@ If you set up the above folders and files, you're ready to write test bundles.
71
71
72
72
A test bundle is a collection of tests are logically related to each other, for example tests that all revolve around "information on BGP neighbors". The test bundle describes which test definition should be collected and executed and provides data for those tests. The bundles are written as individual entries in a YAML file.
73
73
74
-
Currently only YAML files are supported as test bundle format, but other data sources could be integrated in later versions of NUTS.
74
+
Currently only YAML files are supported as test bundle format, but other data sources could be integrated in later versions of nuts.
75
75
76
76
Structure of a Test Bundle
77
77
**************************
@@ -93,7 +93,7 @@ Each test bundle contains the following structure:
93
93
``label``: Optional. Additional identifier that can be used to distinguish between multiple occurrences of the same
94
94
test class in a test bundle.
95
95
96
-
``test_execution``: Optional. NUTS uses nornir tasks to automatically interact with the network. This field contains additional information that is directly passed to the nornir task in the background. Therefore the key-value pairs must be consistent with the key-value pairs of the specific nornir task.
96
+
``test_execution``: Optional. Nuts uses nornir tasks to automatically interact with the network. This field contains additional information that is directly passed to the nornir task in the background. Therefore the key-value pairs must be consistent with the key-value pairs of the specific nornir task.
97
97
As an example, the test definition ``TestNapalmPing`` calls a nornir task to execute napalm's ping-command.
98
98
This allows the additional ``count`` parameter in ``test execution``, since it is in turn pre-defined by napalm. Please see the :doc:`chapter on test bundles <../testbundles/alltestbundles>` for more detailed explanations.
0 commit comments