May 15, 2023
This blog post will cover the usage of the Nornir Network Automation Framework and Pytest Test Framework to achieve large-scale network testing. Let's start off by introducing Nornir and Pytest.
Nornir is an extremely fast and highly pluggable pure-python network automation framework. It gives us an inventory system as well as built-in concurrency which is several magnitudes faster than comparable tools like Ansible. We won't cover Nornir basics as there are tons of great tutorials out there such as the one linked here.
Pytest is a mature, feature-rich, and extensible test framework for Python. It gives us the ability to create tests that are simple to read and write, without the need of learning a domain-specific language. Pytest comes with automated test discovery, a simple-to-use CLI, and plugins that allow us to do things like have our results displayed in a shiny web dashboard. The framework also has other great features and benefits like detailed customisable feedback for test failures, only needing a low amount of boilerplate code, and the ability to write modular tests via fixtures and parameterisation.
When network engineers deploy changes into production, they need to ensure the network is in a healthy state before and after the change. They may also find it useful to ensure that the current network state matches a desired state. Similarly, a new network design should be tested before being rolled out into production.
This is where Pytest comes in. It gives us the ability to answer questions like:
Before we get to the main event, let's walk through what exactly makes up a test as well as a simple example using Netmiko.
A good pattern to follow that structures a test into distinct steps is Arrange-Act-Assert.