commit: a6b9b218bc8599a5c07470aabc41a7af6a1f05d7
Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 30 18:24:48 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Aug 31 03:10:14 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a6b9b218
Add test case for unshare_net code in portage.process
Code by Zac Medico, with some small tweaks.
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/process/test_unshare_net.py | 38 +++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
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)