From c7ad52998327defe8075c9512be1986e7f5af755 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Tue, 19 Sep 2017 14:12:28 -0400 Subject: [PATCH] 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 --- neutron/tests/common/net_helpers.py | 4 ++-- .../functional/tests/common/exclusive_resources/test_port.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/neutron/tests/common/net_helpers.py b/neutron/tests/common/net_helpers.py index 9b5e8b00928..18d56afcc6f 100644 --- a/neutron/tests/common/net_helpers.py +++ b/neutron/tests/common/net_helpers.py @@ -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) diff --git a/neutron/tests/functional/tests/common/exclusive_resources/test_port.py b/neutron/tests/functional/tests/common/exclusive_resources/test_port.py index 190dcbf1b9d..f22659ebe4c 100644 --- a/neutron/tests/functional/tests/common/exclusive_resources/test_port.py +++ b/neutron/tests/functional/tests/common/exclusive_resources/test_port.py @@ -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