public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 891313f56ad00f616382591812c0a5c5bcd98a6c 3608 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
 
#! /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 os
import tempfile

from avocado_classless.test import assert_eq, assert_eq_unordered, test

from tasst.address import LOOPBACK4, LOOPBACK6
from tasst.dhcp import test_dhcp
from tasst.dhcpv6 import test_dhcpv6
from tasst.ndp import test_ndp
from tasst.nstool import unshare_site
from tasst.pasta import Pasta
from tasst.scenario.simple import (
    simple_net, IFNAME, HOST_NET6, IP4, IP6, GW_IP4, REMOTE_IP4, REMOTE_IP6
)
from tasst.transfer import test_transfers


IN_FWD_PORT = 10002
SPLICE_FWD_PORT = 10003
FWD_OPTS = f'-t {IN_FWD_PORT} -u {IN_FWD_PORT} \
             -T {SPLICE_FWD_PORT} -U {SPLICE_FWD_PORT}'


@contextlib.contextmanager
def pasta_unconfigured(opts=FWD_OPTS):
    with simple_net() as simnet:
        with unshare_site('pastans', '-Ucnpf --mount-proc',
                          parent=simnet.simhost, sudo=True) as guestns:
            with tempfile.TemporaryDirectory() as tmpdir:
                pidfile = os.path.join(tmpdir, 'pasta.pid')

                with Pasta(simnet.simhost, pidfile, opts, ns=guestns) as pasta:
                    yield simnet, pasta.ns


@test
def test_ifname():
    with pasta_unconfigured() as (_, ns):
        assert_eq_unordered(ns.ifs(), ('lo', IFNAME))


@test_ndp(IFNAME, HOST_NET6)
@contextlib.contextmanager
def pasta_ndp():
    with pasta_unconfigured() as (simnet, guestns):
        guestns.ifup(IFNAME)
        yield guestns, simnet.gw_ip6_ll.ip


@test_dhcp(IFNAME, IP4.ip, GW_IP4.ip, 65520)
@test_dhcpv6(IFNAME, IP6.ip)
@contextlib.contextmanager
def pasta_dhcp():
    with pasta_unconfigured() as (_, guestns):
        yield guestns


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


@test
def test_config_net_addr():
    with pasta_configured() as (_, ns):
        addrs = ns.addrs(IFNAME, scope='global')
        assert_eq_unordered(addrs, [IP4, IP6])


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


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


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


@test_transfers(ip4=REMOTE_IP4.ip, ip6=REMOTE_IP6.ip, port=10000)
@contextlib.contextmanager
def outward_transfer():
    with pasta_configured() as (simnet, ns):
        yield ns, simnet.gw


@test_transfers(ip4=IP4.ip, ip6=IP6.ip, port=IN_FWD_PORT,
                fromip4=REMOTE_IP4.ip, fromip6=REMOTE_IP6.ip)
@contextlib.contextmanager
def inward_transfer():
    with pasta_configured() as (simnet, ns):
        yield simnet.gw, ns


@test_transfers(ip4=LOOPBACK4, ip6=LOOPBACK6, port=SPLICE_FWD_PORT,
                listenip4=LOOPBACK4, listenip6=LOOPBACK6)
@contextlib.contextmanager
def spliced_transfer():
    with pasta_configured() as (simnet, ns):
        yield ns, simnet.simhost

debug log:

solving 891313f5 ...
found 891313f5 in https://archives.passt.top/passt-dev/20230627025429.2209702-28-david@gibson.dropbear.id.au/

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

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

index at:
100644 891313f56ad00f616382591812c0a5c5bcd98a6c	test/avocado/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).