1 |
On Tue, Aug 27, 2019 at 7:11 PM Zac Medico <zmedico@g.o> wrote: |
2 |
> |
3 |
> On 8/27/19 9:24 AM, Alec Warner wrote: |
4 |
> > unit tests? |
5 |
> > |
6 |
> > -A |
7 |
> |
8 |
> Maybe something like this: |
9 |
> |
10 |
> diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py |
11 |
> new file mode 100644 |
12 |
> index 000000000..2d3eebad0 |
13 |
> --- /dev/null |
14 |
> +++ b/lib/portage/tests/process/test_unshare_net.py |
15 |
> @@ -0,0 +1,30 @@ |
16 |
> +# Copyright 2019 Gentoo Authors |
17 |
> +# Distributed under the terms of the GNU General Public License v2 |
18 |
> + |
19 |
> +import os |
20 |
> +import platform |
21 |
> + |
22 |
> +import portage.process |
23 |
> +from portage.const import BASH_BINARY |
24 |
> +from portage.tests import TestCase |
25 |
> + |
26 |
> +UNSHARE_NET_TEST_SCRIPT = """ |
27 |
> +ping -c 1 -W 1 127.0.0.1 || exit 1 |
28 |
> +[[ -n ${IPV6} ]] || exit 0 |
29 |
> +ping -c 1 -W 1 ::1 || exit 1 |
30 |
> +""" |
31 |
> + |
32 |
> +class UnshareNetTestCase(TestCase): |
33 |
> + |
34 |
> + def testUnshareNet(self): |
35 |
> + |
36 |
> + if os.geteuid() != 0: |
37 |
> + self.skipTest('not root') |
38 |
> + if platform.system() != 'Linux': |
39 |
> + self.skipTest('not Linux') |
40 |
> + if portage.process.find_binary('ping') is None: |
41 |
> + self.skipTest('ping not found') |
42 |
> + |
43 |
> + env = os.environ.copy() |
44 |
> + env['IPV6'] = '1' if portage.process._has_ipv6() else '' |
45 |
> + self.assertEqual(portage.process.spawn([BASH_BINARY, '-c', UNSHARE_NET_TEST_SCRIPT], unshare_net=True, env=env), 0) |
46 |
|
47 |
Thanks, that's helpful. |
48 |
|
49 |
I have made a couple tweaks to the original patch that I will send |
50 |
along shortly. |