Code by Zac Medico, with some small tweaks.
---
 lib/portage/tests/process/test_unshare_net.py | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 lib/portage/tests/process/test_unshare_net.py

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..b339cf532
--- /dev/null
+++ b/lib/portage/tests/process/test_unshare_net.py
@@ -0,0 +1,32 @@
+# Copyright 2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import os
+import platform
+
+import portage.process
+from portage.const import BASH_BINARY
+from portage.tests import TestCase
+
+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 os.geteuid() != 0:
+                       self.skipTest('not root')
+               if platform.system() != 'Linux':
+                       self.skipTest('not Linux')
+               if portage.process.find_binary('ping') is None:
+                       self.skipTest('ping not found')
+
+               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)
-- 
2.23.0


Reply via email to