make net_helpers functions work on OpenSUSE

/sbin may not be in the regular user's PATH or tools like sysctl/ss
may require root privileges to execute correctly on OpenSUSE, and this
makes net_helpers functions fail with OSError. There is no harm in
running ss or sysctl as root user for these functions and that allows
fullstack/functional tests to operate correctly on OpenSUSE.

The change requires a testcase to inherit from BaseSudoTestCase due
to the new run_as_root=True flag.

Change-Id: Ia4f2af1d44faacf5f7ab5471b4f18ecb27f06549
This commit is contained in:
Armando Migliaccio 2017-09-19 14:12:28 -04:00
parent e40ba77269
commit c7ad529983
2 changed files with 3 additions and 3 deletions

View File

@ -189,7 +189,7 @@ def _get_source_ports_from_ss_output(output):
def get_unused_port(used, start=1024, end=None):
if end is None:
port_range = utils.execute(
['sysctl', '-n', 'net.ipv4.ip_local_port_range'])
['sysctl', '-n', 'net.ipv4.ip_local_port_range'], run_as_root=True)
end = int(port_range.split()[0]) - 1
candidates = set(range(start, end + 1))
@ -219,7 +219,7 @@ def get_free_namespace_port(protocol, namespace=None, start=1024, end=None):
raise ValueError("Unsupported protocol %s" % protocol)
ip_wrapper = ip_lib.IPWrapper(namespace=namespace)
output = ip_wrapper.netns.execute(['ss', param])
output = ip_wrapper.netns.execute(['ss', param], run_as_root=True)
used_ports = _get_source_ports_from_ss_output(output)
return get_unused_port(used_ports, start, end)

View File

@ -18,7 +18,7 @@ from neutron.tests.common.exclusive_resources import port
from neutron.tests.functional import base
class TestExclusivePort(base.BaseLoggingTestCase):
class TestExclusivePort(base.BaseSudoTestCase):
def test_port(self):
port_1 = self.useFixture(port.ExclusivePort(
constants.PROTO_NAME_TCP)).port