test: new test, verify static dhcp host leases

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-01-31 13:56:40 +01:00
parent d28fff67f2
commit d1e1c9ad33
7 changed files with 330 additions and 0 deletions
+2
View File
@@ -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[]
+3
View File
@@ -10,3 +10,6 @@
- name: server_basic
case: server_basic/test.py
- name: server_host
case: server_host/test.py
+1
View File
@@ -0,0 +1 @@
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
<<<
+168
View File
@@ -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()
@@ -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> mgmt1 | <mgmt0> mgmt0 | <mgmt2> mgmt2 }",
pos="0,12!",
requires="controller",
];
server [
label="{ <link1> link1 | <mgmt> mgmt | <link2> link2 } | server",
pos="15,12!",
requires="infix",
];
client1 [
label="{ <mgmt> mgmt | <link> link} | client1",
pos="15,18!",
requires="infix",
];
client2 [
label="{ <link> link | <mgmt> 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"]
}
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Title: server hosts Pages: 1 -->
<svg width="520pt" height="372pt"
viewBox="0.00 0.00 520.29 372.03" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 368.03)">
<title>server hosts</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-368.03 516.29,-368.03 516.29,4 -4,4"/>
<!-- host -->
<g id="node1" class="node">
<title>host</title>
<polygon fill="none" stroke="black" points="0,-147.52 0,-216.52 108,-216.52 108,-147.52 0,-147.52"/>
<text text-anchor="middle" x="25" y="-178.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">host</text>
<polyline fill="none" stroke="black" points="50,-147.52 50,-216.52 "/>
<text text-anchor="middle" x="79" y="-201.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt1</text>
<polyline fill="none" stroke="black" points="50,-193.52 108,-193.52 "/>
<text text-anchor="middle" x="79" y="-178.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt0</text>
<polyline fill="none" stroke="black" points="50,-170.52 108,-170.52 "/>
<text text-anchor="middle" x="79" y="-155.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt2</text>
</g>
<!-- server -->
<g id="node2" class="node">
<title>server</title>
<polygon fill="none" stroke="black" points="388.29,-147.52 388.29,-216.52 512.29,-216.52 512.29,-147.52 388.29,-147.52"/>
<text text-anchor="middle" x="417.29" y="-201.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">link1</text>
<polyline fill="none" stroke="black" points="388.29,-193.52 446.29,-193.52 "/>
<text text-anchor="middle" x="417.29" y="-178.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt</text>
<polyline fill="none" stroke="black" points="388.29,-170.52 446.29,-170.52 "/>
<text text-anchor="middle" x="417.29" y="-155.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">link2</text>
<polyline fill="none" stroke="black" points="446.29,-147.52 446.29,-216.52 "/>
<text text-anchor="middle" x="479.29" y="-178.32" font-family="DejaVu Sans Mono, Book" font-size="14.00">server</text>
</g>
<!-- host&#45;&#45;server -->
<g id="edge1" class="edge">
<title>host:mgmt0&#45;&#45;server:mgmt</title>
<path fill="none" stroke="lightgrey" stroke-width="2" d="M108,-182.02C108,-182.02 388.29,-182.02 388.29,-182.02"/>
</g>
<!-- client1 -->
<g id="node3" class="node">
<title>client1</title>
<polygon fill="none" stroke="black" points="388.29,-317.53 388.29,-363.53 512.29,-363.53 512.29,-317.53 388.29,-317.53"/>
<text text-anchor="middle" x="413.29" y="-348.33" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt</text>
<polyline fill="none" stroke="black" points="388.29,-340.53 438.29,-340.53 "/>
<text text-anchor="middle" x="413.29" y="-325.33" font-family="DejaVu Sans Mono, Book" font-size="14.00">link</text>
<polyline fill="none" stroke="black" points="438.29,-317.53 438.29,-363.53 "/>
<text text-anchor="middle" x="475.29" y="-336.83" font-family="DejaVu Sans Mono, Book" font-size="14.00">client1</text>
</g>
<!-- host&#45;&#45;client1 -->
<g id="edge2" class="edge">
<title>host:mgmt1&#45;&#45;client1:mgmt</title>
<path fill="none" stroke="lightgrey" stroke-width="2" d="M108,-205.02C108,-205.02 388.29,-352.53 388.29,-352.53"/>
</g>
<!-- client2 -->
<g id="node4" class="node">
<title>client2</title>
<polygon fill="none" stroke="black" points="388.29,-0.5 388.29,-46.5 512.29,-46.5 512.29,-0.5 388.29,-0.5"/>
<text text-anchor="middle" x="413.29" y="-31.3" font-family="DejaVu Sans Mono, Book" font-size="14.00">link</text>
<polyline fill="none" stroke="black" points="388.29,-23.5 438.29,-23.5 "/>
<text text-anchor="middle" x="413.29" y="-8.3" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt</text>
<polyline fill="none" stroke="black" points="438.29,-0.5 438.29,-46.5 "/>
<text text-anchor="middle" x="475.29" y="-19.8" font-family="DejaVu Sans Mono, Book" font-size="14.00">client2</text>
</g>
<!-- host&#45;&#45;client2 -->
<g id="edge3" class="edge">
<title>host:mgmt2&#45;&#45;client2:mgmt</title>
<path fill="none" stroke="lightgrey" stroke-width="2" d="M108,-159.02C108,-159.02 388.29,-11.5 388.29,-11.5"/>
</g>
<!-- server&#45;&#45;client1 -->
<g id="edge4" class="edge">
<title>server:link1&#45;&#45;client1:link</title>
<path fill="none" stroke="black" stroke-width="2" d="M417.29,-217.02C417.29,-217.02 413.29,-317.53 413.29,-317.53"/>
<text text-anchor="middle" x="362.79" y="-220.82" font-family="DejaVu Serif, Book" font-size="14.00">192.168.1.1/24</text>
</g>
<!-- server&#45;&#45;client2 -->
<g id="edge5" class="edge">
<title>server:link2&#45;&#45;client2:link</title>
<path fill="none" stroke="black" stroke-width="2" d="M417.29,-147.02C417.29,-147.02 413.29,-46.5 413.29,-46.5"/>
<text text-anchor="middle" x="362.79" y="-135.82" font-family="DejaVu Serif, Book" font-size="14.00">192.168.2.1/24</text>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.0 KiB