From a9c1ac21efe78332067e1673a63ab1755a81b726 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Thu, 19 Sep 2019 12:30:12 +0000 Subject: [PATCH] Avoid calling util.kill_process to kill "sleep" In "ListNamespacePids", to check that a process is running inside a namespace, a new thread is spawned. Inside it a shell command is executed ("sleep "). To avoid calling the method "utils.kill_process" with the correspondent overhead when running as root, this patch reduces the "sleep" time to a short period (3 seconds) and lets the process to finish gracefully. Trivial-Fix Change-Id: Ib33e725b563b863810f61f457a0ddfee8edc5c2e --- .../privileged/agent/linux/test_ip_lib.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/neutron/tests/functional/privileged/agent/linux/test_ip_lib.py b/neutron/tests/functional/privileged/agent/linux/test_ip_lib.py index 452ec60d4e9..2aed1591c3a 100644 --- a/neutron/tests/functional/privileged/agent/linux/test_ip_lib.py +++ b/neutron/tests/functional/privileged/agent/linux/test_ip_lib.py @@ -14,8 +14,8 @@ import functools import random +import threading -import eventlet import netaddr from neutron_lib import constants as n_cons from oslo_utils import uuidutils @@ -632,11 +632,12 @@ class ListNamespacePids(functional_base.BaseSudoTestCase): def setUp(self): super(ListNamespacePids, self).setUp() self.namespace = self.useFixture(net_helpers.NamespaceFixture()).name + self.timeout = 3 @staticmethod - def _run_sleep(namespace): + def _run_sleep(namespace, timeout): ip_wrapper = ip_lib.IPWrapper(namespace=namespace) - ip_wrapper.netns.execute(['sleep', '100'], check_exit_code=False) + ip_wrapper.netns.execute(['sleep', timeout], check_exit_code=False) def _check_pids(self, num_pids, namespace=None): namespace = self.namespace if not namespace else namespace @@ -644,13 +645,15 @@ class ListNamespacePids(functional_base.BaseSudoTestCase): return len(self.pids) == num_pids def test_list_namespace_pids(self): - eventlet.spawn_n(self._run_sleep, self.namespace) - + thread = threading.Thread(target=self._run_sleep, + args=(self.namespace, self.timeout)) + thread.start() try: check_pids = functools.partial(self._check_pids, 1) - common_utils.wait_until_true(check_pids, timeout=5) + common_utils.wait_until_true(check_pids, timeout=self.timeout) except common_utils.WaitTimeout: self.fail('Process no found in namespace %s' % self.namespace) + thread.join(timeout=self.timeout) def test_list_namespace_pids_nothing_running_inside(self): self.assertTrue(self._check_pids(0))