public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 816c0ea9ca26214316d2f93d9a7c56cde9f6cea8 2214 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
 
#! /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_addr(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_addr)(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

debug log:

solving 816c0ea9 ...
found 816c0ea9 in https://archives.passt.top/passt-dev/20230627025429.2209702-26-david@gibson.dropbear.id.au/

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

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

index at:
100644 816c0ea9ca26214316d2f93d9a7c56cde9f6cea8	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).