Network automation lab 16 of 27
Testing network automation: unit tests, mocks, pre/post snapshots and a pipeline
Write the tests first: unit-test a small network library with saved device output and a mocked connection, then validate a real OSPF change with before-and-after snapshots, a structured diff and explicit checks, all chained into a pipeline that stops at the first failure.
Run this lab
It needs Lite: its 4 nodes are set to 4 vCPU and 2,560 MB in total. That fits the free demo too.
In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 16 - Testing network automation - unit tests mocks pre-post snapshots and a pipeline
- Level
- Advanced
- Time
- About 85 minutes
- Nodes need
- 4 vCPU, 2,560 MB
- Smallest plan
- Lite
The scenario
Kestrel Freight's change board has a new rule: no automated change goes out without tests. The change today is small (r1 should reach r2's loopback through r3, so the r1–r2 link can be upgraded next week), but you'll build the safety net properly: unit tests for the team's netcheck library that run without any router, snapshots before and after the change, a diff that shows exactly what moved, a validation script that says PASS only if the network did what was intended and nothing else, and a pipeline that chains it all.
| Router | Mgmt | Links | Loopback0 |
|---|---|---|---|
| r1 | 10.10.20.11 | Gi0/1 10.1.12.1 → r2 · Gi0/2 10.1.13.1 → r3 | 10.255.0.1 |
| r2 | 10.10.20.12 | Gi0/1 10.1.12.2 → r1 · Gi0/2 10.1.23.1 → r3 | 10.255.0.2 |
| r3 | 10.10.20.13 | Gi0/1 10.1.13.2 → r1 · Gi0/2 10.1.23.2 → r2 | 10.255.0.3 |
OSPF area 0 runs on every link and loopback. Files in ~/lab: netcheck.py (function stubs), tests/test_netcheck.py (two finished tests and three TODOs), tests/data/ (saved r1 output), snapshot.py and diff.py (ready to use). Login netops / NetOps-Lab1.
What you’ll practise
- Apply test-driven development: write a failing test, make it pass, refactor
- Unit-test parsing and logic with saved output and unittest.mock instead of live devices
- Capture structured pre- and post-change snapshots and diff them
- Validate that a change did exactly what was intended and nothing else
- Chain lint, test, pre-check, deploy, post-check and validation into a CI/CD-style pipeline
The tasks
- Red, green, refactor
- Write the test, then the code: ospf_healthy()
- Test a parser with saved output
- Replace the router with a mock
- Snapshot the network before the change
- Make the change, snapshot again, diff
- Validate: intended changes only
- Chain it into a pipeline
The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.
Topology and devices
The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.
Every link, as text
- devbox
eth0to Mgmt (network) - r1
Gi0/0to Mgmt (network) - r2
Gi0/0to Mgmt (network) - r3
Gi0/0to Mgmt (network) - r1
Gi0/1to r2Gi0/1 - r1
Gi0/2to r3Gi0/1 - r2
Gi0/2to r3Gi0/2
| Node | Device | Image in Add Node | Set to |
|---|---|---|---|
| devbox | EVE-NG GUI server (Docker) | eve-gui-server:latest | 1 vCPU, 1,024 MB |
| r1 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
| r2 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
| r3 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
How to open this lab
Sign in to your workspace at
lab.cloudlabbox.com.In File Manager, open Shared, then the folder
Network Automation - CCNA and CCNP Automation guided labs.Open
16 - Testing network automation - unit tests mocks pre-post snapshots and a pipelineand start its nodes, then open Lab Tasks for the scenario and the steps.
The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.
More Network automation labs
Related labs in other courses
CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.