#! /usr/bin/env avocado-runner-avocado-classless # SPDX-License-Identifier: GPL-2.0-or-later # # Copyright Red Hat # Author: David Gibson """ Test A Simple Socket Transport meta/veth.py - Test various veth configurations """ import contextlib import ipaddress from avocado_classless.test import assert_eq, assert_eq_unordered, test from tasst.nstool import unshare_site @contextlib.contextmanager def unconfigured_veth(): with unshare_site('ns1', '-Un') as ns1: with unshare_site('ns2', '-n', parent=ns1, sudo=True) as ns2: ns1.veth('veth1', 'veth2', ns2) yield (ns1, ns2) @test def test_ifs(): with unconfigured_veth() as (ns1, ns2): assert_eq_unordered(ns1.ifs(), ['lo', 'veth1']) assert_eq_unordered(ns2.ifs(), ['lo', 'veth2']) @test def test_mtu(): with unconfigured_veth() as (ns1, ns2): assert_eq(ns1.mtu('veth1'), 1500) assert_eq(ns2.mtu('veth2'), 1500) @test def test_slaac(dad=None): TESTMAC = '02:aa:bb:cc:dd:ee' TESTIP = ipaddress.ip_interface('fe80::aa:bbff:fecc:ddee/64') with unconfigured_veth() as (ns1, ns2): ns1.fg(f'ip link set dev veth1 address {TESTMAC}', sudo=True) ns1.ifup('veth1', dad=dad) ns2.ifup('veth2') addrs = ns1.addr_wait('veth1', family='inet6', scope='link') assert_eq(addrs, [TESTIP]) @test def test_optimistic_dad(): test_slaac(dad='optimistic') @test def test_no_dad(): test_slaac(dad='disable')