Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, Alec Warner <antarus@g.o>, Mike Gilbert <floppym@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH] Use RTNETLINK to configure the loopback interface
Date: Tue, 27 Aug 2019 23:11:35
Message-Id: 6c4d5bb1-a83e-3663-4059-4374327bad5e@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH] Use RTNETLINK to configure the loopback interface by Alec Warner
1 On 8/27/19 9:24 AM, Alec Warner wrote:
2 > unit tests?
3 >
4 > -A
5
6 Maybe something like this:
7
8 diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py
9 new file mode 100644
10 index 000000000..2d3eebad0
11 --- /dev/null
12 +++ b/lib/portage/tests/process/test_unshare_net.py
13 @@ -0,0 +1,30 @@
14 +# Copyright 2019 Gentoo Authors
15 +# Distributed under the terms of the GNU General Public License v2
16 +
17 +import os
18 +import platform
19 +
20 +import portage.process
21 +from portage.const import BASH_BINARY
22 +from portage.tests import TestCase
23 +
24 +UNSHARE_NET_TEST_SCRIPT = """
25 +ping -c 1 -W 1 127.0.0.1 || exit 1
26 +[[ -n ${IPV6} ]] || exit 0
27 +ping -c 1 -W 1 ::1 || exit 1
28 +"""
29 +
30 +class UnshareNetTestCase(TestCase):
31 +
32 + def testUnshareNet(self):
33 +
34 + if os.geteuid() != 0:
35 + self.skipTest('not root')
36 + if platform.system() != 'Linux':
37 + self.skipTest('not Linux')
38 + if portage.process.find_binary('ping') is None:
39 + self.skipTest('ping not found')
40 +
41 + env = os.environ.copy()
42 + env['IPV6'] = '1' if portage.process._has_ipv6() else ''
43 + self.assertEqual(portage.process.spawn([BASH_BINARY, '-c', UNSHARE_NET_TEST_SCRIPT], unshare_net=True, env=env), 0)
44
45 --
46 Thanks,
47 Zac

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies