public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 491927a691610f6e967075a53271723049613a8b 3845 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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
#! /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>

"""
avocado/pasta.py - Basic tests for pasta mode
"""

import contextlib
import ipaddress

import exeter

from tasst import dhcp, dhcpv6, ndp, nstool
from tasst.pasta import Pasta
from tasst.scenario.simple import simple_net

IN_FWD_PORT = 10002
SPLICE_FWD_PORT = 10003
FWD_OPTS = ['-t', f'{IN_FWD_PORT}', '-u', f'{IN_FWD_PORT}',
            '-T', f'{SPLICE_FWD_PORT}', '-U', f'{SPLICE_FWD_PORT}']


@contextlib.contextmanager
def pasta_unconfigured(*opts):
    with simple_net() as simnet:
        with nstool.unshare_snh('pastans', '-Ucnpf', '--mount-proc',
                                parent=simnet.simhost, capable=True) \
                                as guestns:
            with Pasta(host=simnet.simhost, opts=opts, ns=guestns) as pasta:
                yield simnet, pasta.ns


@exeter.test
def test_ifname():
    with pasta_unconfigured() as (simnet, ns):
        expected = set(['lo', simnet.IFNAME])
        exeter.assert_eq(set(ns.ifs()), expected)


@contextlib.contextmanager
def pasta_ndp_setup():
    with pasta_unconfigured() as (simnet, guestns):
        guestns.ifup(simnet.IFNAME)
        yield ndp.NdpTestScenario(client=guestns,
                                  ifname=simnet.IFNAME,
                                  network=simnet.IP6.network,
                                  gateway=simnet.gw_ip6_ll.ip)


ndp.ndp_tests(pasta_ndp_setup)


@contextlib.contextmanager
def pasta_dhcp():
    with pasta_unconfigured() as (simnet, guestns):
        yield dhcp.DhcpTestScenario(client=guestns,
                                    ifname=simnet.IFNAME,
                                    addr=simnet.IP4.ip,
                                    gateway=simnet.GW_IP4.ip,
                                    mtu=65520)


dhcp.dhcp_tests(pasta_dhcp)


@contextlib.contextmanager
def pasta_dhcpv6():
    with pasta_unconfigured() as (simnet, guestns):
        yield dhcpv6.Dhcpv6TestScenario(client=guestns,
                                        ifname=simnet.IFNAME,
                                        addr=simnet.IP6.ip)


dhcpv6.dhcp6_tests(pasta_dhcpv6)


@contextlib.contextmanager
def pasta_configured():
    with pasta_unconfigured('--config-net', *FWD_OPTS) as (simnet, ns):
        # Wait for DAD to complete on the --config-net address
        ns.addr_wait(simnet.IFNAME, family='inet6', scope='global')
        yield simnet, ns


@exeter.test
def test_config_net_addr():
    with pasta_configured() as (simnet, ns):
        addrs = ns.addrs(simnet.IFNAME, scope='global')
        exeter.assert_eq(set(addrs), set([simnet.IP4, simnet.IP6]))


@exeter.test
def test_config_net_route4():
    with pasta_configured() as (simnet, ns):
        (defroute,) = ns.routes4(dst='default')
        gateway = ipaddress.ip_address(defroute['gateway'])
        exeter.assert_eq(gateway, simnet.GW_IP4.ip)


@exeter.test
def test_config_net_route6():
    with pasta_configured() as (simnet, ns):
        (defroute,) = ns.routes6(dst='default')
        gateway = ipaddress.ip_address(defroute['gateway'])
        exeter.assert_eq(gateway, simnet.gw_ip6_ll.ip)


@exeter.test
def test_config_net_mtu():
    with pasta_configured() as (simnet, ns):
        mtu = ns.mtu(simnet.IFNAME)
        exeter.assert_eq(mtu, 65520)


@contextlib.contextmanager
def outward_transfer():
    with pasta_configured() as (simnet, ns):
        yield ns, simnet.gw


@contextlib.contextmanager
def inward_transfer():
    with pasta_configured() as (simnet, ns):
        yield simnet.gw, ns


@contextlib.contextmanager
def spliced_transfer():
    with pasta_configured() as (simnet, ns):
        yield ns, simnet.simhost


if __name__ == '__main__':
    exeter.main()

debug log:

solving 491927a6 ...
found 491927a6 in https://archives.passt.top/passt-dev/20240805123701.1720730-23-david@gibson.dropbear.id.au/

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

Checking patch test/pasta/pasta.py...
Applied patch test/pasta/pasta.py cleanly.

index at:
100644 491927a691610f6e967075a53271723049613a8b	test/pasta/pasta.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).