#! /usr/bin/python3 # SPDX-License-Identifier: GPL-2.0-or-later # # tasst - Test A Simple Socket Transport # library of test helpers for passt & pasta # # tasst/metatest/veth - Test the veth creation helper # # These test code from tasst.site, but require additional support from # tasst.nstool. # # Copyright Red Hat # Author: David Gibson import contextlib import ipaddress import avocado from tasst import Tasst from tasst.site import REAL_HOST from tasst.nstool import UnshareSite from tasst.transfer import BaseTransferTasst, MetaTcpUploadTasst, MetaUdpTransferTasst, TransferTasstInfo from tasst.address import IpiAllocator class BaseVethTasst(Tasst): @contextlib.contextmanager def setup_veth(self): with UnshareSite(type(self).__name__ + '.1', '-Un') as ns1: with UnshareSite(type(self).__name__ + '.2', '-n', parent=ns1, sudo=True) as ns2: ns1.veth('veth1', 'veth2', ns2) yield (ns1, ns2) class VethTasst(BaseVethTasst): """ Test helpers for creating veths between namespaces :avocado: tags=meta """ def test_ifs(self): with self.setup_veth() as (ns1, ns2): self.assertCountEqual(ns1.ifs(), ['lo', 'veth1']) self.assertCountEqual(ns2.ifs(), ['lo', 'veth2']) def test_mtu(self): with self.setup_veth() as (ns1, ns2): self.assertEquals(ns1.mtu('veth1'), 1500) self.assertEquals(ns2.mtu('veth2'), 1500) def test_slaac(self, dad=None): TESTMAC = '02:aa:bb:cc:dd:ee' TESTIP = ipaddress.ip_interface('fe80::aa:bbff:fecc:ddee/64') with self.setup_veth() as (ns1, ns2): ns1.fg('ip link set dev veth1 address {}'.format(TESTMAC), sudo=True) ns1.ifup('veth1', dad=dad) ns2.ifup('veth2') addrs = ns1.addr_wait('veth1', family='inet6', scope='link') self.assertEqual(addrs, [TESTIP]) def test_optimistic_dad(self): self.test_slaac(dad='optimistic') def test_no_dad(self): self.test_slaac(dad='disable') class VethTransferTasst(BaseVethTasst, MetaTcpUploadTasst, MetaUdpTransferTasst): """ Test basic transfers over veth :avocado: tags=meta """ @contextlib.contextmanager def setup_transfer(self): with self.setup_veth() as (ns1, ns2): ipa = IpiAllocator() ns1_ip4, ns1_ip6 = ipa.next_ipis() ns1.ifup('lo') ns1.ifup('veth1', ns1_ip4, ns1_ip6, dad='disable') ns2_ip4, ns2_ip6 = ipa.next_ipis() ns2.ifup('lo') ns2.ifup('veth2', ns2_ip4, ns2_ip6, dad='disable') yield TransferTasstInfo('test/small.bin', ns1, ns2, ns2_ip4.ip, ns2_ip6.ip, 10000)