1 |
Code by Zac Medico, with some small tweaks. |
2 |
--- |
3 |
lib/portage/tests/process/test_unshare_net.py | 32 +++++++++++++++++++ |
4 |
1 file changed, 32 insertions(+) |
5 |
create mode 100644 lib/portage/tests/process/test_unshare_net.py |
6 |
|
7 |
diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py |
8 |
new file mode 100644 |
9 |
index 000000000..b339cf532 |
10 |
--- /dev/null |
11 |
+++ b/lib/portage/tests/process/test_unshare_net.py |
12 |
@@ -0,0 +1,32 @@ |
13 |
+# Copyright 2019 Gentoo Authors |
14 |
+# Distributed under the terms of the GNU General Public License v2 |
15 |
+ |
16 |
+import os |
17 |
+import platform |
18 |
+ |
19 |
+import portage.process |
20 |
+from portage.const import BASH_BINARY |
21 |
+from portage.tests import TestCase |
22 |
+ |
23 |
+UNSHARE_NET_TEST_SCRIPT = """ |
24 |
+ping -c 1 -W 1 127.0.0.1 || exit 1 |
25 |
+ping -c 1 -W 1 10.0.0.1 || exit 1 |
26 |
+[[ -n ${IPV6} ]] || exit 0 |
27 |
+ping -c 1 -W 1 ::1 || exit 1 |
28 |
+ping -c 1 -W 1 fd::1 || exit 1 |
29 |
+""" |
30 |
+ |
31 |
+class UnshareNetTestCase(TestCase): |
32 |
+ |
33 |
+ def testUnshareNet(self): |
34 |
+ |
35 |
+ if os.geteuid() != 0: |
36 |
+ self.skipTest('not root') |
37 |
+ if platform.system() != 'Linux': |
38 |
+ self.skipTest('not Linux') |
39 |
+ if portage.process.find_binary('ping') is None: |
40 |
+ self.skipTest('ping not found') |
41 |
+ |
42 |
+ env = os.environ.copy() |
43 |
+ env['IPV6'] = '1' if portage.process._has_ipv6() else '' |
44 |
+ self.assertEqual(portage.process.spawn([BASH_BINARY, '-c', UNSHARE_NET_TEST_SCRIPT], unshare_net=True, env=env), 0) |
45 |
-- |
46 |
2.23.0 |