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:
parent
e40ba77269
commit
c7ad529983
|
@ -189,7 +189,7 @@ def _get_source_ports_from_ss_output(output):
|
||||||
def get_unused_port(used, start=1024, end=None):
|
def get_unused_port(used, start=1024, end=None):
|
||||||
if end is None:
|
if end is None:
|
||||||
port_range = utils.execute(
|
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
|
end = int(port_range.split()[0]) - 1
|
||||||
|
|
||||||
candidates = set(range(start, end + 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)
|
raise ValueError("Unsupported protocol %s" % protocol)
|
||||||
|
|
||||||
ip_wrapper = ip_lib.IPWrapper(namespace=namespace)
|
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)
|
used_ports = _get_source_ports_from_ss_output(output)
|
||||||
|
|
||||||
return get_unused_port(used_ports, start, end)
|
return get_unused_port(used_ports, start, end)
|
||||||
|
|
|
@ -18,7 +18,7 @@ from neutron.tests.common.exclusive_resources import port
|
||||||
from neutron.tests.functional import base
|
from neutron.tests.functional import base
|
||||||
|
|
||||||
|
|
||||||
class TestExclusivePort(base.BaseLoggingTestCase):
|
class TestExclusivePort(base.BaseSudoTestCase):
|
||||||
def test_port(self):
|
def test_port(self):
|
||||||
port_1 = self.useFixture(port.ExclusivePort(
|
port_1 = self.useFixture(port.ExclusivePort(
|
||||||
constants.PROTO_NAME_TCP)).port
|
constants.PROTO_NAME_TCP)).port
|
||||||
|
|
Loading…
Reference in New Issue