On Tue, Aug 27, 2019 at 7:11 PM Zac Medico <zmed...@gentoo.org> wrote: > > On 8/27/19 9:24 AM, Alec Warner wrote: > > unit tests? > > > > -A > > Maybe something like this: > > 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..2d3eebad0 > --- /dev/null > +++ b/lib/portage/tests/process/test_unshare_net.py > @@ -0,0 +1,30 @@ > +# 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 > +[[ -n ${IPV6} ]] || exit 0 > +ping -c 1 -W 1 ::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)
Thanks, that's helpful. I have made a couple tweaks to the original patch that I will send along shortly.