Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4cd6d17
Delete .gitlab-ci.yml
marcom4rtinez Oct 11, 2021
f8ff14a
Merge branch 'INSRapperswil:master' into master
marcom4rtinez Oct 13, 2021
a53e593
ignore vscode files
marcom4rtinez Oct 13, 2021
ebabba5
add napalm vlan test
Sevitama Oct 18, 2021
f727e96
improve quality
marcom4rtinez Oct 20, 2021
f464515
save progress #1
marcom4rtinez Oct 25, 2021
2ac331e
flake8 syntax
marcom4rtinez Oct 25, 2021
035bab1
restructure result from extractor
Sevitama Nov 3, 2021
029c58b
blackify
Sevitama Nov 3, 2021
35284b3
fix mistake
Sevitama Nov 13, 2021
08683ce
fix tox errors
Sevitama Nov 13, 2021
9d00f7f
add vlan test
Sevitama Nov 13, 2021
801022b
move file
Sevitama Nov 13, 2021
5e68e48
add test for second class
Sevitama Nov 13, 2021
44e73c7
add test case
Sevitama Nov 15, 2021
22798ed
restructure to one file
Sevitama Nov 17, 2021
f184a3d
remove unused file
Sevitama Nov 17, 2021
9b67806
fix syntax
Sevitama Nov 17, 2021
0588daf
rename file
Sevitama Nov 17, 2021
fe0c937
remove typos, superfluous signs, make names consistent
bytinbit Nov 18, 2021
43ea0ca
update naming, add other entry to SelfTestData
bytinbit Nov 18, 2021
bd3ca42
add test for key-converter
bytinbit Nov 18, 2021
a6c0f4c
conftest: add missing hosts to nornir inventory fixture
bytinbit Nov 18, 2021
bd5de7f
vlan-self-tests: add integration test
bytinbit Nov 18, 2021
dbe5916
blackify
bytinbit Nov 18, 2021
febc7e6
rename defined vlan selftest
bytinbit Nov 18, 2021
1eb0df1
remove self-test for defined vlans
bytinbit Nov 18, 2021
0167db0
add fixture for taglist testdata
bytinbit Nov 18, 2021
ed70039
cleanup
bytinbit Nov 18, 2021
89b88cf
add test_class to index
Sevitama Nov 22, 2021
27ca209
remove comments
Sevitama Nov 22, 2021
142436e
Merge branch '1-test-bundle-prototyp-vlan-test' into 'master'
Sevitama Nov 24, 2021
43f48d6
add interface to vlan tests
marcom4rtinez Dec 2, 2021
f838c29
Merge branch '5-extended-vlan-test-bundle' into 'master'
marcom4rtinez Dec 6, 2021
f9b15e5
add new Test-Bundle for ARP checks
Sevitama Dec 8, 2021
888fe9f
blackify
marcom4rtinez Dec 8, 2021
5efd623
save progress
marcom4rtinez Dec 8, 2021
03f57aa
add new test class
Sevitama Dec 9, 2021
88a00c4
fix integration test
marcom4rtinez Dec 9, 2021
0bba14e
Apply 1 suggestion(s) to 1 file(s)
Sevitama Dec 9, 2021
1c61474
exclude file, output of nornir cannot be shortened
marcom4rtinez Dec 9, 2021
651cabf
add vrf test
Sevitama Dec 9, 2021
c1929b3
fix issues / blackify
marcom4rtinez Dec 9, 2021
a012c5a
Merge branch '6-configuration-test-bundle' into 'master'
marcom4rtinez Dec 9, 2021
04c3252
Merge branch '8-test-bundle-arp' into 'master'
marcom4rtinez Dec 9, 2021
80688f3
Merge branch '9-extend-cdp-and-lldp-neighbors-test-bundle' into 'master'
marcom4rtinez Dec 9, 2021
b602029
Merge branch '10-test-bundle-vrf'
marcom4rtinez Dec 9, 2021
bc5e73f
Merge branch 'master' into 57-nuts-sa
Jan 11, 2022
671abf6
Fix formatting and mypy issues
Jan 11, 2022
09927d3
Add the documentation parts of the newly integrated tests.
Jan 18, 2022
a57bb96
Rename the LLDP and CDP neighbors count test classes and attributes t…
Jan 18, 2022
9d474fb
Some minor refactorings and fixes.
Jan 20, 2022
defd42b
VRF tests are already available as "network_instance"-tests. So add t…
Jan 20, 2022
19b6be2
Remove Méline as a maintainer :-(, welcome Marco & Severin as authors…
Jan 21, 2022
b315523
Fix tests and flake8 errors
Jan 21, 2022
0b0404c
Fix error in get_config test
Jan 21, 2022
6c415db
Fix some formatting issues (black)
Jan 21, 2022
5167f59
add changelog for upcoming release v3.1.0
Jan 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ venv/
.venv/
pytest_nuts.egg-info/
__pycache__

.vscode/
docs/build/

.pytest-cache/
inventory/
nr-config.yaml
.pytest_cache/
.tox/

test-reports/
Expand Down
222 changes: 219 additions & 3 deletions docs/source/testbundles/alltestbundles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,58 @@ Note that you need an inventory of network devices for the tests to work. Please
In some test bundles you can directly pass arguments to the nornir task, i.e. the network query that is executed in the background. For those test bundles we indicate the specific task which is used to query the devices, so that you can look up all available arguments.


ARP Table
---------

**Test Bundle:** Tests if the desired ARP table entries exist on a device. It is checked whether predefined entries consisting of interface and ip are available in the arp table on the device.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNapalmArp
test_data:
- host: <host name, required>
interface: <interface name, required>
ip: <IP address, required>

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNapalmArp
test_data:
- host: S1
interface: Vlan1
ip: 10.0.0.30


ARP Table - Entries Count
-------------------------

**Test Bundle:** Tests if the number of ARP table entries on the device is in a specific range.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNapalmArpRange
test_data:
- host: <host name, required>
min: <minimum expected ARP table entries, required>
max: <maximum expected ARP table entries, required>

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNapalmArpRange
test_data:
- host: S1
min: 13
max: 20


BGP Neighbors - Information
---------------------------

Expand Down Expand Up @@ -124,8 +176,56 @@ Required fields for specific tests in this bundle:
remote_port: GigabitEthernet2


CDP Neighbors - Count
----------------------

**Test Bundle:** Tests the amount of CDP neighbors a host should have.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNetmikoCdpNeighborsCount
test_data:
- host: <host name, required>
neighbor_count: <number of neighbors, required>

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNetmikoCdpNeighborsCount
test_data:
- host: S1
neighbor_count: 3


Configuration - Startup vs. Running
-----------------------------------

**Test Bundle:** Tests if the running configuration matches the startup configuration of the device. With this test "configuration drifts" can be found.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNapalmConfig
test_data:
- host: <host name, required>
startup_equals_running_config: <True|False, required>

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNapalmConfig
test_data:
- host: S1
startup_equals_running_config: True


Interfaces
--------------
----------

**Test Bundle:** Tests if an interface exists on a host and has the required attributes.

Expand Down Expand Up @@ -165,6 +265,7 @@ Required fields for specific tests in this bundle:
mtu: 1500
speed: 1000


iperf - Bandwidth Test
----------------------

Expand Down Expand Up @@ -200,6 +301,7 @@ iperf - Bandwidth Test
destination: 10.20.2.12
min_expected: 10000000


LLDP Neighbors
--------------

Expand Down Expand Up @@ -233,6 +335,30 @@ Required fields for specific tests in this bundle:
remote_port: GigabitEthernet2


LLDP Neighbors - Count
----------------------

**Test Bundle:** Tests the amount of LLDP neighbors a host should have.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNapalmLldpNeighborsCount
test_data:
- host: <host name, required>
neighbor_count: <number of neighbors, required>

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNapalmLldpNeighborsCount
test_data:
- host: S1
neighbor_count: 3


Network Instances
-----------------

Expand All @@ -252,6 +378,7 @@ Network Instances

Required fields for specific tests in this bundle:

* Test network instance is configured: ``host, network_instance``
* Test interfaces that belong to a VRF: ``host, network_instance, interfaces``
* Test route-distinguisher: ``host, network_instance, route_distinguisher``

Expand All @@ -270,6 +397,7 @@ Required fields for specific tests in this bundle:
- Loopback0
route_distinguisher: "1:1"


OSPF Neighbors - Information
----------------------------

Expand Down Expand Up @@ -311,7 +439,7 @@ Required fields for specific tests in this bundle:


OSPF Neighbors - Count
----------------------------
----------------------

**Test Bundle:** Tests the amount of OSPF neighbors a host should have.

Expand Down Expand Up @@ -391,7 +519,6 @@ There is only one test in this bundle, i.e. ping another host. All fields are th
Users - Information
-------------------


**Test Bundle:** Tests pre-defined users of a device.

**Test Bundle Structure:**
Expand Down Expand Up @@ -422,6 +549,7 @@ Required fields for specific tests in this bundle:
password: stark
level: 15


Users - No Rogue Users
----------------------

Expand All @@ -447,3 +575,91 @@ Users - No Rogue Users
usernames:
- cisco
- arya


VLAN - Information
------------------

**Test Bundle:** Test if the defined VLAN's are available on a device. Additionally the assignment of VLAN-tags to VLAN-names can be checked.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNapalmVlans
test_data:
- host: <host name, required>
vlan_tag: <vlan tag, required>
vlan_name: <vlan name>

Required fields for specific tests in this bundle:

* Test VLAN is defined: ``host, vlan_tag``
* Test VLAN tag -> name assignment: ``host, vlan_tag, vlan_name``

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNapalmVlans
test_data:
- host: S1
vlan_tag: 1
vlan_name: default
- host: S2
vlan_tag: 200


VLAN - Interface Assignment
---------------------------

**Test Bundle:** Tests if an interface is assigned to the correct VLAN.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNapalmInterfaceInVlan
test_data:
- host: <host name, required>
vlan_tag: <vlan tag, required>
interface: <interface name, required>

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNapalmInterfaceInVlan
test_data:
- host: S2
vlan_tag: 200
interface: GigabitEthernet0/3


VLAN - No Rogue VLANs
---------------------

**Test Bundle:** Tests that only pre-defined VLAN's exist on a device, i.e. there are no rogue VLAN's.

**Test Bundle Structure:**

.. code:: yaml

- test_class: TestNapalmOnlyDefinedVlansExist
test_data:
- host: <host name, required>
vlan_tags: <vlan tag list, required>
- <tag>

**Test Bundle Example:**

.. code:: yaml

- test_class: TestNapalmOnlyDefinedVlansExist
test_data:
- host: S2
vlan_tags:
- 1
- 200
- 1002
- 1003
43 changes: 43 additions & 0 deletions nuts/base_tests/napalm_get_arp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Query arp table of a device."""
from typing import Dict, Callable, List, Any, Text

import pytest
from nornir.core.task import MultiResult, Result
from nornir_napalm.plugins.tasks import napalm_get

from nuts.context import NornirNutsContext
from nuts.helpers.result import AbstractHostResultExtractor


class ArpExtractor(AbstractHostResultExtractor):
def single_transform(self, single_result: MultiResult) -> List[Dict[Text, Any]]:
result = []
for entry in self._simple_extract(single_result)["arp_table"]:
result.append({"interface": entry["interface"], "ip": entry["ip"]})
return result


class ArpContext(NornirNutsContext):
def nuts_task(self) -> Callable[..., Result]:
return napalm_get

def nuts_arguments(self) -> Dict[str, List[str]]:
return {"getters": ["arp_table"]}

def nuts_extractor(self) -> ArpExtractor:
return ArpExtractor(self)


CONTEXT = ArpContext


class TestNapalmArp:
@pytest.mark.nuts("interface,ip")
def test_arp_entry(self, single_result, interface, ip):
assert single_result.result.count({"interface": interface, "ip": ip}) >= 1


class TestNapalmArpRange:
@pytest.mark.nuts("min,max")
def test_amount_of_arp_entries(self, single_result, min, max):
assert min <= len(single_result.result) <= max
42 changes: 42 additions & 0 deletions nuts/base_tests/napalm_get_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Query config of a device."""
from typing import Dict, Callable, List, Any

import pytest
from nornir.core.task import MultiResult, Result
from nornir_napalm.plugins.tasks import napalm_get

from nuts.context import NornirNutsContext
from nuts.helpers.result import AbstractHostResultExtractor


class ConfigExtractor(AbstractHostResultExtractor):
def single_transform(self, single_result: MultiResult) -> Dict[int, Any]:
return self._simple_extract(single_result)


class ConfigContext(NornirNutsContext):
def nuts_task(self) -> Callable[..., Result]:
return napalm_get

def nuts_arguments(self) -> Dict[str, List[str]]:
return {"getters": ["config"]}

def nuts_extractor(self) -> ConfigExtractor:
return ConfigExtractor(self)


CONTEXT = ConfigContext


class TestNapalmConfig:
@pytest.mark.nuts("startup_equals_running_config")
def test_startup_equals_running_config(
self, single_result, startup_equals_running_config
):
assert (
bool(
single_result.result["config"]["startup"]
== single_result.result["config"]["running"]
)
== startup_equals_running_config
)
Loading