public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob b7d5ee2e9776bccd2e3ee308fddd01b967966680 4113 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
 
#! /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
from typing import Any, Iterator

import exeter

import tasst
from tasst import cmdsite, dhcp, ndp, pasta, unshare
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: str) -> Iterator[tuple[Any, unshare.Unshare]]:
    with simple_net() as simnet:
        with unshare.unshare('pastans', '-Ucnpf', '--mount-proc',
                             parent=simnet.simhost, privilege=True) \
                             as guestns:
            with pasta.pasta(simnet.simhost, guestns, *opts) as p:
                yield simnet, p.ns


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


@ndp.NdpScenario.test
def pasta_ndp_setup() -> Iterator[ndp.NdpScenario]:
    with pasta_unconfigured() as (simnet, guestns):
        tasst.ip.ifup(guestns, simnet.IFNAME)
        yield ndp.NdpScenario(client=guestns,
                              ifname=simnet.IFNAME,
                              network=simnet.IP6.network,
                              gateway=simnet.gw_ip6_ll.ip)


@dhcp.Dhcp4Scenario.test
def pasta_dhcp() -> Iterator[dhcp.Dhcp4Scenario]:
    with pasta_unconfigured() as (simnet, guestns):
        yield dhcp.Dhcp4Scenario(client=guestns,
                                 ifname=simnet.IFNAME,
                                 addr=simnet.IP4.ip,
                                 gateway=simnet.GW_IP4.ip,
                                 mtu=65520)


@dhcp.Dhcp6Scenario.test
def pasta_dhcpv6() -> Iterator[dhcp.Dhcp6Scenario]:
    with pasta_unconfigured() as (simnet, guestns):
        yield dhcp.Dhcp6Scenario(client=guestns,
                                 ifname=simnet.IFNAME,
                                 addr=simnet.IP6.ip)


@contextlib.contextmanager
def pasta_configured() -> Iterator[tuple[Any, unshare.Unshare]]:
    with pasta_unconfigured('--config-net', *FWD_OPTS) as (simnet, ns):
        # Wait for DAD to complete on the --config-net address
        tasst.ip.addr_wait(ns, simnet.IFNAME, family='inet6', scope='global')
        yield simnet, ns


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


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


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


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


@contextlib.contextmanager
def outward_transfer() -> Iterator[tuple[Any, cmdsite.CmdSite]]:
    with pasta_configured() as (simnet, ns):
        yield ns, simnet.gw


@contextlib.contextmanager
def inward_transfer() -> Iterator[tuple[Any, cmdsite.CmdSite]]:
    with pasta_configured() as (simnet, ns):
        yield simnet.gw, ns


@contextlib.contextmanager
def spliced_transfer() -> Iterator[tuple[cmdsite.CmdSite, cmdsite.CmdSite]]:
    with pasta_configured() as (simnet, ns):
        yield ns, simnet.simhost


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

debug log:

solving b7d5ee2e ...
found b7d5ee2e in https://archives.passt.top/passt-dev/20240826020942.545155-16-david@gibson.dropbear.id.au/

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

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

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