From a59f40d014b60fce2f0c7631eb8052ad3520ace2 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sat, 13 Apr 2024 14:04:10 +0000 Subject: [PATCH] examples: add mutest example --- Makefile | 2 +- examples/mutest/munet.yaml | 48 +++++++++++++++++++++++++++ examples/mutest/mutest_ospf.py | 35 +++++++++++++++++++ examples/mutest/r1/etc.frr/daemons | 1 + examples/mutest/r1/etc.frr/frr.conf | 12 +++++++ examples/mutest/r1/etc.frr/vtysh.conf | 1 + examples/mutest/r2/etc.frr/daemons | 1 + examples/mutest/r2/etc.frr/frr.conf | 12 +++++++ examples/mutest/r2/etc.frr/vtysh.conf | 1 + examples/mutest/r3/etc.frr/daemons | 1 + examples/mutest/r3/etc.frr/frr.conf | 12 +++++++ examples/mutest/r3/etc.frr/vtysh.conf | 1 + 12 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 examples/mutest/munet.yaml create mode 100644 examples/mutest/mutest_ospf.py create mode 100644 examples/mutest/r1/etc.frr/daemons create mode 100644 examples/mutest/r1/etc.frr/frr.conf create mode 100644 examples/mutest/r1/etc.frr/vtysh.conf create mode 100644 examples/mutest/r2/etc.frr/daemons create mode 100644 examples/mutest/r2/etc.frr/frr.conf create mode 100644 examples/mutest/r2/etc.frr/vtysh.conf create mode 100644 examples/mutest/r3/etc.frr/daemons create mode 100644 examples/mutest/r3/etc.frr/frr.conf create mode 100644 examples/mutest/r3/etc.frr/vtysh.conf diff --git a/Makefile b/Makefile index da5e11c..ccd1f59 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ ci-lint: $(POETRYRUN) pylint --disable="fixme" ./munet ./tests test: test-validate ci-lint - sudo -E $(POETRYRUN) mutest + sudo -E $(POETRYRUN) mutest tests sudo -E $(POETRYRUN) pytest -s -v --cov=munet --cov-report=xml tests clean: diff --git a/examples/mutest/munet.yaml b/examples/mutest/munet.yaml new file mode 100644 index 0000000..7d3d068 --- /dev/null +++ b/examples/mutest/munet.yaml @@ -0,0 +1,48 @@ +version: 1 + +topology: + networks-autonumber: true + networks: + - name: net1 + - name: net2 + - name: net3 + nodes: + - name: r1 + kind: frr + connections: ["net1", "net2"] + - name: r2 + kind: frr + connections: ["net1", "net3"] + - name: r3 + kind: frr + connections: ["net2", "net3"] + +kinds: + - name: frr + cap-add: + - SYS_ADMIN + - AUDIT_WRITE + cmd: | + chown frr:frr -R /var/run/frr + chown frr:frr -R /var/log/frr + /usr/lib/frr/frrinit.sh start + tail -F /var/log/frr/frr.log + # cleanup-cmd: | + # /usr/lib/frr/frrinit.sh stop + volumes: + - "./%NAME%/etc.frr:/etc/frr" + - "%RUNDIR%/var.log.frr:/var/log/frr" + - "%RUNDIR%/var.run.frr:/var/run/frr" + +cli: + commands: + - name: "" + exec: "vtysh -c '{}'" + format: "[ROUTER ...] COMMAND" + help: "execute vtysh COMMAND on the router[s]" + kinds: ["frr"] + - name: "vtysh" + exec: "/usr/bin/vtysh" + format: "vtysh ROUTER [ROUTER ...]" + new-window: true + kinds: ["frr"] diff --git a/examples/mutest/mutest_ospf.py b/examples/mutest/mutest_ospf.py new file mode 100644 index 0000000..900adf4 --- /dev/null +++ b/examples/mutest/mutest_ospf.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: GPL-2.0-or-later +# +# April 12 2024, Christian Hopps +# +# Copyright (c) 2024, LabN Consulting, L.L.C. +"""Example mutest.""" +from munet.mutest.userapi import match_step +from munet.mutest.userapi import section +from munet.mutest.userapi import wait_step + + +section("Test to verify OSPF neighbors are up.") + +wait_step( + "r1", + "vtysh -c 'show module'", + match="ospfd daemon", + desc="OSPF loaded", +) + +match_step( + "r1", + "vtysh -c 'show run'", + match="router ospf", + desc="OSPF configured", +) + +wait_step( + "r1", + "vtysh -c 'show ip ospf neigh'", + match="(.*Full){2,}", + timeout=15, + desc="Verify 2 Full neighbors on router r1", +) diff --git a/examples/mutest/r1/etc.frr/daemons b/examples/mutest/r1/etc.frr/daemons new file mode 100644 index 0000000..985e3e6 --- /dev/null +++ b/examples/mutest/r1/etc.frr/daemons @@ -0,0 +1 @@ +ospfd=1 diff --git a/examples/mutest/r1/etc.frr/frr.conf b/examples/mutest/r1/etc.frr/frr.conf new file mode 100644 index 0000000..f6f6e2a --- /dev/null +++ b/examples/mutest/r1/etc.frr/frr.conf @@ -0,0 +1,12 @@ +log file /var/log/frr/frr.log +interface eth0 + ip address 10.0.1.1/24 + ip ospf dead-interval 5 + ip ospf hello-interval 1 +interface eth1 + ip address 10.0.2.1/24 + ip ospf dead-interval 5 + ip ospf hello-interval 1 +router ospf + ospf router-id 172.16.0.1 + network 10.0.0.0/16 area 0.0.0.0 diff --git a/examples/mutest/r1/etc.frr/vtysh.conf b/examples/mutest/r1/etc.frr/vtysh.conf new file mode 100644 index 0000000..e0ab9cb --- /dev/null +++ b/examples/mutest/r1/etc.frr/vtysh.conf @@ -0,0 +1 @@ +service integrated-vtysh-config diff --git a/examples/mutest/r2/etc.frr/daemons b/examples/mutest/r2/etc.frr/daemons new file mode 100644 index 0000000..985e3e6 --- /dev/null +++ b/examples/mutest/r2/etc.frr/daemons @@ -0,0 +1 @@ +ospfd=1 diff --git a/examples/mutest/r2/etc.frr/frr.conf b/examples/mutest/r2/etc.frr/frr.conf new file mode 100644 index 0000000..48895e3 --- /dev/null +++ b/examples/mutest/r2/etc.frr/frr.conf @@ -0,0 +1,12 @@ +log file /var/log/frr/frr.log +interface eth0 + ip address 10.0.1.2/24 + ip ospf dead-interval 5 + ip ospf hello-interval 1 +interface eth1 + ip address 10.0.3.2/24 + ip ospf dead-interval 5 + ip ospf hello-interval 1 +router ospf + ospf router-id 172.16.0.2 + network 10.0.0.0/16 area 0.0.0.0 diff --git a/examples/mutest/r2/etc.frr/vtysh.conf b/examples/mutest/r2/etc.frr/vtysh.conf new file mode 100644 index 0000000..e0ab9cb --- /dev/null +++ b/examples/mutest/r2/etc.frr/vtysh.conf @@ -0,0 +1 @@ +service integrated-vtysh-config diff --git a/examples/mutest/r3/etc.frr/daemons b/examples/mutest/r3/etc.frr/daemons new file mode 100644 index 0000000..985e3e6 --- /dev/null +++ b/examples/mutest/r3/etc.frr/daemons @@ -0,0 +1 @@ +ospfd=1 diff --git a/examples/mutest/r3/etc.frr/frr.conf b/examples/mutest/r3/etc.frr/frr.conf new file mode 100644 index 0000000..ecac391 --- /dev/null +++ b/examples/mutest/r3/etc.frr/frr.conf @@ -0,0 +1,12 @@ +log file /var/log/frr/frr.log +interface eth0 + ip address 10.0.2.3/24 + ip ospf dead-interval 5 + ip ospf hello-interval 1 +interface eth1 + ip address 10.0.3.3/24 + ip ospf dead-interval 5 + ip ospf hello-interval 1 +router ospf + ospf router-id 172.16.0.3 + network 10.0.0.0/16 area 0.0.0.0 diff --git a/examples/mutest/r3/etc.frr/vtysh.conf b/examples/mutest/r3/etc.frr/vtysh.conf new file mode 100644 index 0000000..e0ab9cb --- /dev/null +++ b/examples/mutest/r3/etc.frr/vtysh.conf @@ -0,0 +1 @@ +service integrated-vtysh-config