#! /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 avocado from tasst import Tasst from tasst.site import REAL_HOST from tasst.nstool import UnshareSite class VethTasst(Tasst): """ Test helpers for creating veths between namespaces :avocado: tags=meta """ @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) def test_ifs(self): with self.setup_veth() as (ns1, ns2): self.assertCountEqual(ns1.ifs(), ['lo', 'veth1']) self.assertCountEqual(ns2.ifs(), ['lo', 'veth2'])