public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob ab119ae738dd0f6173f9c6b3b1d926755f993a2b 2471 bytes (raw)

 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
#! /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

import exeter

from . import address, dhcp


def dhclientv6(snh, ifname):
    return dhcp.dhclient(snh, ifname, '6')


class Dhcpv6TestScenario:
    def __init__(self, *, client, ifname, addr):
        self.client = client
        self.ifname = ifname
        self.addr = addr


def test_dhcp6_addr(setup):
    with setup as scn, dhclientv6(scn.client, scn.ifname):
        addrs = [a.ip for a in scn.client.addrs(scn.ifname, family='inet6',
                                                scope='global')]
        assert scn.addr in addrs  # Might also have a SLAAC address


DHCP6_TESTS = [test_dhcp6_addr]


def dhcp6_tests(setup):
    for t in DHCP6_TESTS:
        testid = f'{setup.__qualname__}|{t.__qualname__}'
        exeter.register_pipe(testid, setup, t)


DHCPD = 'dhcpd'
SUBNET = address.TEST_NET6_TASST_A
ipa = address.IpiAllocator(SUBNET)
(SERVER_IP6,) = ipa.next_ipis()
(CLIENT_IP6,) = ipa.next_ipis()
IFNAME = 'clientif'


@contextlib.contextmanager
def setup_dhcpdv6():
    server_ifname = 'serverif'

    with dhcp.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', '-d', '-6', '-cf', f'{confpath}',
                '-lf', f'{leasepath}', '-pf', f'{pidfile}']
        server.fg(f'{DHCPD}', '-t', *opts)  # test config
        with server.bg(f'{DHCPD}', *opts, capable=True, check=False) as dhcpd:
            yield Dhcpv6TestScenario(client=client, ifname=IFNAME,
                                     addr=CLIENT_IP6.ip)
            dhcpd.terminate()


dhcp6_tests(setup_dhcpdv6)

debug log:

solving ab119ae7 ...
found ab119ae7 in https://archives.passt.top/passt-dev/20240805123701.1720730-21-david@gibson.dropbear.id.au/

applying [1/1] https://archives.passt.top/passt-dev/20240805123701.1720730-21-david@gibson.dropbear.id.au/
diff --git a/test/tasst/dhcpv6.py b/test/tasst/dhcpv6.py
new file mode 100644
index 00000000..ab119ae7

Checking patch test/tasst/dhcpv6.py...
Applied patch test/tasst/dhcpv6.py cleanly.

index at:
100644 ab119ae738dd0f6173f9c6b3b1d926755f993a2b	test/tasst/dhcpv6.py

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).