#! /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/static_ifup - Static address configuration """ import contextlib import ipaddress from avocado_classless.test import assert_eq_unordered, test from tasst.nstool import unshare_site IFNAME = 'testveth' IFNAME_PEER = 'vethpeer' TEST_IPS = [ipaddress.ip_interface('192.0.2.1/24'), ipaddress.ip_interface('2001:db8:9a55::1/112'), ipaddress.ip_interface('10.1.2.3/8')] @contextlib.contextmanager def setup_ns(): with unshare_site('ns', '-Un') as ns: ns.veth(IFNAME, IFNAME_PEER) ns.ifup(IFNAME, *TEST_IPS, dad='disable') yield ns @test def test_addr(): with setup_ns() as ns: assert_eq_unordered(ns.addrs(IFNAME, scope='global'), TEST_IPS) @test def test_routes4(): with setup_ns() as ns: expected_routes = [i.network for i in TEST_IPS if isinstance(i, ipaddress.IPv4Interface)] actual_routes = [ipaddress.ip_interface(r['dst']).network for r in ns.routes4(dev=IFNAME)] assert_eq_unordered(expected_routes, actual_routes) @test def test_routes6(): with setup_ns() as ns: expected_routes = [i.network for i in TEST_IPS if isinstance(i, ipaddress.IPv6Interface)] actual_routes = [ipaddress.ip_interface(r['dst']).network for r in ns.routes6(dev=IFNAME)] assert_eq_unordered(expected_routes, actual_routes)