Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
Date: Sat, 31 Aug 2019 03:10:59
Message-Id: 1567221014.a6b9b218bc8599a5c07470aabc41a7af6a1f05d7.zmedico@gentoo
1 commit: a6b9b218bc8599a5c07470aabc41a7af6a1f05d7
2 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
3 AuthorDate: Fri Aug 30 18:24:48 2019 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sat Aug 31 03:10:14 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a6b9b218
7
8 Add test case for unshare_net code in portage.process
9
10 Code by Zac Medico, with some small tweaks.
11
12 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
13
14 lib/portage/tests/process/test_unshare_net.py | 38 +++++++++++++++++++++++++++
15 1 file changed, 38 insertions(+)
16
17 diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py
18 new file mode 100644
19 index 000000000..745b79a47
20 --- /dev/null
21 +++ b/lib/portage/tests/process/test_unshare_net.py
22 @@ -0,0 +1,38 @@
23 +# Copyright 2019 Gentoo Authors
24 +# Distributed under the terms of the GNU General Public License v2
25 +
26 +import errno
27 +import os
28 +import platform
29 +
30 +import portage.process
31 +from portage.const import BASH_BINARY
32 +from portage.tests import TestCase
33 +
34 +CLONE_NEWNET = 0x40000000
35 +
36 +UNSHARE_NET_TEST_SCRIPT = """
37 +ping -c 1 -W 1 127.0.0.1 || exit 1
38 +ping -c 1 -W 1 10.0.0.1 || exit 1
39 +[[ -n ${IPV6} ]] || exit 0
40 +ping -c 1 -W 1 ::1 || exit 1
41 +ping -c 1 -W 1 fd::1 || exit 1
42 +"""
43 +
44 +class UnshareNetTestCase(TestCase):
45 +
46 + def testUnshareNet(self):
47 +
48 + if platform.system() != 'Linux':
49 + self.skipTest('not Linux')
50 + if portage.process.find_binary('ping') is None:
51 + self.skipTest('ping not found')
52 +
53 + errno_value = portage.process._unshare_validate(CLONE_NEWNET)
54 + if errno_value != 0:
55 + self.skipTest("Unable to unshare: %s" % (
56 + errno.errorcode.get(errno_value, '?')))
57 +
58 + env = os.environ.copy()
59 + env['IPV6'] = '1' if portage.process._has_ipv6() else ''
60 + self.assertEqual(portage.process.spawn([BASH_BINARY, '-c', UNSHARE_NET_TEST_SCRIPT], unshare_net=True, env=env), 0)