1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| | #! /usr/bin/env avocado-runner-avocado-classless
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright Red Hat
# Author: David Gibson <david@gibson.dropbear.id.au>
"""
Test A Simple Socket Transport
dhcpv6.py - Helpers for testing DHCPv6
"""
import contextlib
import os
from avocado_classless.test import assert_in, test_output
from tasst.address import IpiAllocator, TEST_NET6_TASST_A
from tasst.dhcp import dhclient, setup_dhcpd_common
def dhclientv6(site, ifname):
return dhclient(site, ifname, '6')
def test_dhcpv6(ifname, expected_addr):
def dec(setupfn):
def test_addr6(setup):
with setup as site, dhclientv6(site, ifname):
addrs = [a.ip for a in site.addrs(ifname, family='inet6',
scope='global')]
assert_in(expected_addr, addrs) # Might also have a SLAAC address
return test_output(test_addr6)(setupfn)
return dec
DHCPD = 'dhcpd'
SUBNET = TEST_NET6_TASST_A
ipa = IpiAllocator(SUBNET)
(SERVER_IP6,) = ipa.next_ipis()
(CLIENT_IP6,) = ipa.next_ipis()
IFNAME = 'clientif'
@test_dhcpv6(IFNAME, CLIENT_IP6.ip)
@contextlib.contextmanager
def setup_dhcpdv6():
server_ifname = 'serverif'
with setup_dhcpd_common(IFNAME, server_ifname) as (client, server, tmpdir):
# Sort out link local addressing
server.ifup('lo')
server.ifup(server_ifname, SERVER_IP6)
client.ifup('lo')
client.ifup(IFNAME)
server.addr_wait(server_ifname, family='inet6', scope='link')
# Configure the DHCP server
confpath = os.path.join(tmpdir, 'dhcpd.conf')
open(confpath, 'w', encoding='UTF-8').write(
f'''subnet6 {SUBNET} {{
range6 {CLIENT_IP6.ip} {CLIENT_IP6.ip};
}}''')
pidfile = os.path.join(tmpdir, 'dhcpd.pid')
leasepath = os.path.join(tmpdir, 'dhcpd.leases')
open(leasepath, 'wb').write(b'')
opts = f'-f -d -6 -cf {confpath} -lf {leasepath} -pf {pidfile}'
server.fg(f'{DHCPD} -t {opts}') # test config
with server.bg(f'{DHCPD} {opts}', sudo=True, ignore_status=True,
pidfile=pidfile):
yield client
|