diff options
author | Mike Gilbert <floppym@gentoo.org> | 2019-08-30 14:24:48 -0400 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2019-08-30 20:10:14 -0700 |
commit | a6b9b218bc8599a5c07470aabc41a7af6a1f05d7 (patch) | |
tree | f86bd5f80f392a44884198849f4edde51d6b732d | |
parent | Use RTNETLINK to configure the loopback interface (diff) | |
download | portage-a6b9b218.tar.gz portage-a6b9b218.tar.bz2 portage-a6b9b218.zip |
Add test case for unshare_net code in portage.process
Code by Zac Medico, with some small tweaks.
Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r-- | lib/portage/tests/process/test_unshare_net.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py new file mode 100644 index 000000000..745b79a47 --- /dev/null +++ b/lib/portage/tests/process/test_unshare_net.py @@ -0,0 +1,38 @@ +# Copyright 2019 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +import errno +import os +import platform + +import portage.process +from portage.const import BASH_BINARY +from portage.tests import TestCase + +CLONE_NEWNET = 0x40000000 + +UNSHARE_NET_TEST_SCRIPT = """ +ping -c 1 -W 1 127.0.0.1 || exit 1 +ping -c 1 -W 1 10.0.0.1 || exit 1 +[[ -n ${IPV6} ]] || exit 0 +ping -c 1 -W 1 ::1 || exit 1 +ping -c 1 -W 1 fd::1 || exit 1 +""" + +class UnshareNetTestCase(TestCase): + + def testUnshareNet(self): + + if platform.system() != 'Linux': + self.skipTest('not Linux') + if portage.process.find_binary('ping') is None: + self.skipTest('ping not found') + + errno_value = portage.process._unshare_validate(CLONE_NEWNET) + if errno_value != 0: + self.skipTest("Unable to unshare: %s" % ( + errno.errorcode.get(errno_value, '?'))) + + env = os.environ.copy() + env['IPV6'] = '1' if portage.process._has_ipv6() else '' + self.assertEqual(portage.process.spawn([BASH_BINARY, '-c', UNSHARE_NET_TEST_SCRIPT], unshare_net=True, env=env), 0) |