From d1e1c9ad33fd0f58357aecd13834f7bf0f55efc6 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 20 Jan 2025 23:09:19 +0100 Subject: [PATCH] test: new test, verify static dhcp host leases Signed-off-by: Joachim Wiberg --- test/case/infix_dhcp/Readme.adoc | 2 + test/case/infix_dhcp/infix_dhcp.yaml | 3 + test/case/infix_dhcp/server_host/Readme.adoc | 1 + .../infix_dhcp/server_host/server_host.adoc | 31 ++++ test/case/infix_dhcp/server_host/test.py | 168 ++++++++++++++++++ test/case/infix_dhcp/server_host/topology.dot | 42 +++++ test/case/infix_dhcp/server_host/topology.svg | 83 +++++++++ 7 files changed, 330 insertions(+) create mode 120000 test/case/infix_dhcp/server_host/Readme.adoc create mode 100644 test/case/infix_dhcp/server_host/server_host.adoc create mode 100755 test/case/infix_dhcp/server_host/test.py create mode 100644 test/case/infix_dhcp/server_host/topology.dot create mode 100644 test/case/infix_dhcp/server_host/topology.svg diff --git a/test/case/infix_dhcp/Readme.adoc b/test/case/infix_dhcp/Readme.adoc index 4457a23c..451910b5 100644 --- a/test/case/infix_dhcp/Readme.adoc +++ b/test/case/infix_dhcp/Readme.adoc @@ -10,3 +10,5 @@ include::client_default_gw/Readme.adoc[] include::client_routes/Readme.adoc[] include::server_basic/Readme.adoc[] + +include::server_host/Readme.adoc[] diff --git a/test/case/infix_dhcp/infix_dhcp.yaml b/test/case/infix_dhcp/infix_dhcp.yaml index d336235c..8be7ca02 100644 --- a/test/case/infix_dhcp/infix_dhcp.yaml +++ b/test/case/infix_dhcp/infix_dhcp.yaml @@ -10,3 +10,6 @@ - name: server_basic case: server_basic/test.py + +- name: server_host + case: server_host/test.py diff --git a/test/case/infix_dhcp/server_host/Readme.adoc b/test/case/infix_dhcp/server_host/Readme.adoc new file mode 120000 index 00000000..922c6354 --- /dev/null +++ b/test/case/infix_dhcp/server_host/Readme.adoc @@ -0,0 +1 @@ +server_host.adoc \ No newline at end of file diff --git a/test/case/infix_dhcp/server_host/server_host.adoc b/test/case/infix_dhcp/server_host/server_host.adoc new file mode 100644 index 00000000..85a5d1c2 --- /dev/null +++ b/test/case/infix_dhcp/server_host/server_host.adoc @@ -0,0 +1,31 @@ +=== DHCP Server Static Host +==== Description +Verify DHCP server can hand out static host leases based on +a very long client-id, ensuring no pool address is handed +out instead. + +==== Topology +ifdef::topdoc[] +image::{topdoc}../../test/case/infix_dhcp/server_host/topology.svg[DHCP Server Static Host topology] +endif::topdoc[] +ifndef::topdoc[] +ifdef::testgroup[] +image::server_host/topology.svg[DHCP Server Static Host topology] +endif::testgroup[] +ifndef::testgroup[] +image::topology.svg[DHCP Server Static Host topology] +endif::testgroup[] +endif::topdoc[] +==== Test sequence +. Set up topology and attach to client and server DUTs +. Configure DHCP client and server DUTs +. Verify DHCP client1 static lease +. Verify client1 hostname has *not* changed +. Verify DHCP client1 has default route via option 121 +. Verify DHCP client2 static lease +. Verify client2 hostname has changed +. Verify DHCP client2 has default gateway + + +<<< + diff --git a/test/case/infix_dhcp/server_host/test.py b/test/case/infix_dhcp/server_host/test.py new file mode 100755 index 00000000..71577582 --- /dev/null +++ b/test/case/infix_dhcp/server_host/test.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python3 +"""DHCP Server Static Host + +Verify DHCP server can hand out static host leases based on +a very long client-id, ensuring no pool address is handed +out instead. +""" +import infamy +import infamy.iface as iface +import infamy.route as route +from infamy.util import until + + +with infamy.Test() as test: + POOL1 = '192.168.1.100' + ADDRESS1 = '192.168.1.11' + GW1 = '192.168.1.2' + POOL2 = '192.168.2.100' + ADDRESS2 = '192.168.2.22' + GW2 = '192.168.2.1' + HOSTNM1 = 'foo' + HOSTNM11 = 'client1' + HOSTCID2 = 'xyzzydissiegillespiefoobarterrawinklesouponastick' + HOSTNM2 = 'bar' + HOSTNM22 = 'client2' + + with test.step("Set up topology and attach to client and server DUTs"): + env = infamy.Env() + server = env.attach("server", "mgmt") + client1 = env.attach("client1", "mgmt") + client2 = env.attach("client2", "mgmt") + + with test.step("Configure DHCP client and server DUTs"): + server.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [ + { + "name": server["link1"], + "ipv4": { + "address": [{ + "ip": "192.168.1.1", + "prefix-length": 24 + }] + } + }, { + "name": server["link2"], + "ipv4": { + "address": [{ + "ip": "192.168.2.1", + "prefix-length": 24 + }] + } + }, + ] + } + }, + "infix-dhcp-server": { + "dhcp-server": { + "option": [{ + "id": "router", "address": "auto" + }], + "subnet": [ + { + "subnet": "192.168.1.0/24", + "pool": { + "start-address": POOL1, + "end-address": POOL1 + }, + "host": [{ + "address": ADDRESS1, + "match": { + "hostname": HOSTNM1 + }, + "option": [ + { + "id": "hostname", + "name": HOSTNM11 + }, { + "id": "classless-static-route", + "static-route": [{ + "destination": "0.0.0.0/0", + "next-hop": GW1 + }] + } + ] + }] + }, { + "subnet": "192.168.2.0/24", + "pool": { + "start-address": POOL2, + "end-address": POOL2 + }, + "host": [{ + "address": ADDRESS2, + "match": { + "client-id": HOSTCID2 + }, + "option": [ + { + "id": "hostname", + "name": HOSTNM22 + } + ], + "lease-time": "infinite" + }] + }, + ] + } + }}) + + # We request hostname option just to ensure we don't get it. + client1.put_config_dicts({ + "ietf-system": { + "system": {"hostname": HOSTNM1} + }, + "infix-dhcp-client": { + "dhcp-client": { + "client-if": [{ + "if-name": client1["link"], + "option": [ + {"id": "router"}, + {"id": "hostname", "value": "auto"}, + {"id": 121} + ] + }] + } + }, + }) + + client2.put_config_dicts({ + "ietf-system": { + "system": {"hostname": HOSTNM2} + }, + "infix-dhcp-client": { + "dhcp-client": { + "client-if": [{ + "if-name": client2["link"], + "client-id": HOSTCID2, + "option": [ + {"id": "router"}, + {"id": "hostname"}, + {"id": 121} + ] + }] + } + }, + }) + + with test.step("Verify DHCP client1 static lease"): + until(lambda: iface.address_exist(client1, client1["link"], ADDRESS1)) + + with test.step("Verify client1 hostname has *not* changed"): + until(lambda: client1.get_data("/ietf-system:system")["system"]["hostname"] == HOSTNM1) + + with test.step("Verify DHCP client1 has default route via option 121"): + until(lambda: route.ipv4_route_exist(client1, "0.0.0.0/0", nexthop=GW1)) + + with test.step("Verify DHCP client2 static lease"): + until(lambda: iface.address_exist(client2, client2["link"], ADDRESS2)) + + with test.step("Verify client2 hostname has changed"): + until(lambda: client2.get_data("/ietf-system:system")["system"]["hostname"] == HOSTNM22) + + with test.step("Verify DHCP client2 has default gateway"): + until(lambda: route.ipv4_route_exist(client2, "0.0.0.0/0", nexthop=GW2)) + + test.succeed() diff --git a/test/case/infix_dhcp/server_host/topology.dot b/test/case/infix_dhcp/server_host/topology.dot new file mode 100644 index 00000000..b2e46ae3 --- /dev/null +++ b/test/case/infix_dhcp/server_host/topology.dot @@ -0,0 +1,42 @@ +graph "server hosts" { + layout="neato"; + overlap="false"; + esep="+40"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt1 | mgmt0 | mgmt2 }", + pos="0,12!", + requires="controller", + ]; + + server [ + label="{ link1 | mgmt | link2 } | server", + pos="15,12!", + + requires="infix", + ]; + + client1 [ + label="{ mgmt | link} | client1", + pos="15,18!", + + requires="infix", + ]; + + client2 [ + label="{ link | mgmt } | client2", + pos="15,6!", + + requires="infix", + ]; + + host:mgmt0 -- server:mgmt [requires="mgmt", color=lightgrey] + host:mgmt1 -- client1:mgmt [requires="mgmt", color=lightgrey] + host:mgmt2 -- client2:mgmt [requires="mgmt", color=lightgrey] + + server:link1 -- client1:link [color=black, fontcolor=black, taillabel="192.168.1.1/24"] + server:link2 -- client2:link [color=black, fontcolor=black, taillabel="192.168.2.1/24"] +} diff --git a/test/case/infix_dhcp/server_host/topology.svg b/test/case/infix_dhcp/server_host/topology.svg new file mode 100644 index 00000000..290b6f8d --- /dev/null +++ b/test/case/infix_dhcp/server_host/topology.svg @@ -0,0 +1,83 @@ + + + + + + +server hosts + + + +host + +host + +mgmt1 + +mgmt0 + +mgmt2 + + + +server + +link1 + +mgmt + +link2 + +server + + + +host:mgmt0--server:mgmt + + + + +client1 + +mgmt + +link + +client1 + + + +host:mgmt1--client1:mgmt + + + + +client2 + +link + +mgmt + +client2 + + + +host:mgmt2--client2:mgmt + + + + +server:link1--client1:link + +192.168.1.1/24 + + + +server:link2--client2:link + +192.168.2.1/24 + + +