From c0afeba0b55318e4508d59a68bc7c15e23a9a996 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Wed, 27 May 2015 13:50:22 +0000 Subject: [PATCH] Run RootHelperProcess always as root The purpose of RootHelperProcess is to spawn processes running with root id. Instantiating RootHelperProcess as non-root doesn't make sense. This also implies NetcatTester always spawns 'netcat' process as root. The reason why parameter existed here was due to refactor from passing root_helper all over the place. Change-Id: If042efcd75e46b66abf4a9e303e633749a1611b1 --- .../tests/functional/agent/linux/helpers.py | 21 +++++++------------ .../functional/agent/linux/test_helpers.py | 4 ++-- .../functional/agent/linux/test_iptables.py | 2 +- .../tests/functional/agent/test_l3_agent.py | 3 +-- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/neutron/tests/functional/agent/linux/helpers.py b/neutron/tests/functional/agent/linux/helpers.py index ed4d1b0ea..593234346 100644 --- a/neutron/tests/functional/agent/linux/helpers.py +++ b/neutron/tests/functional/agent/linux/helpers.py @@ -96,21 +96,18 @@ class RootHelperProcess(subprocess.Popen): for arg in ('stdin', 'stdout', 'stderr'): kwargs.setdefault(arg, subprocess.PIPE) self.namespace = kwargs.pop('namespace', None) - self.run_as_root = kwargs.pop('run_as_root', False) self.cmd = cmd if self.namespace is not None: cmd = ['ip', 'netns', 'exec', self.namespace] + cmd - if self.run_as_root: - root_helper = config.get_root_helper(utils.cfg.CONF) - cmd = shlex.split(root_helper) + cmd + root_helper = config.get_root_helper(utils.cfg.CONF) + cmd = shlex.split(root_helper) + cmd self.child_pid = None super(RootHelperProcess, self).__init__(cmd, *args, **kwargs) - if self.run_as_root: - self._wait_for_child_process() + self._wait_for_child_process() def kill(self): pid = self.child_pid or str(self.pid) - utils.execute(['kill', '-9', pid], run_as_root=self.run_as_root) + utils.execute(['kill', '-9', pid], run_as_root=True) def read_stdout(self, timeout=None): return self._read_stream(self.stdout, timeout) @@ -134,7 +131,7 @@ class RootHelperProcess(subprocess.Popen): sleep=CHILD_PROCESS_SLEEP): def child_is_running(): child_pid = utils.get_root_helper_child_pid( - self.pid, run_as_root=self.run_as_root) + self.pid, run_as_root=True) if utils.pid_invoked_with_cmdline(child_pid, self.cmd): return True @@ -144,14 +141,14 @@ class RootHelperProcess(subprocess.Popen): exception=RuntimeError("Process %s hasn't been spawned " "in %d seconds" % (self.cmd, timeout))) self.child_pid = utils.get_root_helper_child_pid( - self.pid, run_as_root=self.run_as_root) + self.pid, run_as_root=True) class NetcatTester(object): TESTING_STRING = 'foo' def __init__(self, client_namespace, server_namespace, server_address, - port, client_address=None, run_as_root=False, udp=False): + port, client_address=None, udp=False): self.client_namespace = client_namespace self.server_namespace = server_namespace self._client_process = None @@ -162,7 +159,6 @@ class NetcatTester(object): self.client_address = client_address or server_address self.server_address = server_address self.port = str(port) - self.run_as_root = run_as_root self.udp = udp @property @@ -210,8 +206,7 @@ class NetcatTester(object): cmd.append('-k') else: cmd.extend(['-w', '20']) - proc = RootHelperProcess(cmd, namespace=namespace, - run_as_root=self.run_as_root) + proc = RootHelperProcess(cmd, namespace=namespace) return proc def stop_processes(self): diff --git a/neutron/tests/functional/agent/linux/test_helpers.py b/neutron/tests/functional/agent/linux/test_helpers.py index 44ba2e797..a027245d4 100644 --- a/neutron/tests/functional/agent/linux/test_helpers.py +++ b/neutron/tests/functional/agent/linux/test_helpers.py @@ -19,14 +19,14 @@ from neutron.tests.functional import base class TestRootHelperProcess(base.BaseSudoTestCase): def test_process_read_write(self): - proc = helpers.RootHelperProcess(['tee'], run_as_root=True) + proc = helpers.RootHelperProcess(['tee']) proc.writeline('foo') output = proc.read_stdout(helpers.READ_TIMEOUT) self.assertEqual('foo\n', output) def test_process_kill(self): with self.assert_max_execution_time(100): - proc = helpers.RootHelperProcess(['tee'], run_as_root=True) + proc = helpers.RootHelperProcess(['tee']) proc.kill() proc.wait() # sudo returns 137 and diff --git a/neutron/tests/functional/agent/linux/test_iptables.py b/neutron/tests/functional/agent/linux/test_iptables.py index 7b2b0a722..ebbf74ce3 100644 --- a/neutron/tests/functional/agent/linux/test_iptables.py +++ b/neutron/tests/functional/agent/linux/test_iptables.py @@ -80,7 +80,7 @@ class IptablesManagerTestCase(functional_base.BaseSudoTestCase): def _test_with_nc(self, fw_manager, direction, port, udp): netcat = helpers.NetcatTester( self.client.namespace, self.server.namespace, - self.server.ip, self.port, run_as_root=True, udp=udp) + self.server.ip, self.port, udp=udp) self.addCleanup(netcat.stop_processes) protocol = 'tcp' if udp: diff --git a/neutron/tests/functional/agent/test_l3_agent.py b/neutron/tests/functional/agent/test_l3_agent.py index bd461164f..7788654bf 100644 --- a/neutron/tests/functional/agent/test_l3_agent.py +++ b/neutron/tests/functional/agent/test_l3_agent.py @@ -414,7 +414,6 @@ class L3AgentTestCase(L3AgentTestFramework): netcat = helpers.NetcatTester(router.ns_name, router.ns_name, server_address, port, client_address=client_address, - run_as_root=True, udp=False) self.addCleanup(netcat.stop_processes) @@ -710,7 +709,7 @@ class L3AgentTestCase(L3AgentTestFramework): netcat = helpers.NetcatTester( src_machine.namespace, dst_machine.namespace, dst_machine.ip, protocol_port, client_address=dst_fip, - run_as_root=True, udp=False) + udp=False) self.addCleanup(netcat.stop_processes) self.assertTrue(netcat.test_connectivity()) -- 2.45.2