From f0ee6692792a7a2ad7dafa7f9914251b9ba4f338 Mon Sep 17 00:00:00 2001 From: Andrey Grebennikov Date: Fri, 5 Oct 2018 14:51:59 -0500 Subject: [PATCH] Improve Apache PID check on service restart In case there are containers with Apache running on the same host, the charm will only watch PIDs within the same namespace. Change-Id: I9cdd7d5b1f53fce748e7fafab538676e4e55dd54 Closes-Bug: #1795918 --- hooks/keystone_utils.py | 3 ++- unit_tests/test_keystone_utils.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hooks/keystone_utils.py b/hooks/keystone_utils.py index 70f443bb..97fe881d 100644 --- a/hooks/keystone_utils.py +++ b/hooks/keystone_utils.py @@ -512,7 +512,8 @@ def restart_pid_check(service_name, ptable_string=None): @retry_on_exception(5, base_delay=3, exc_type=AssertionError) def check_pids_gone(svc_string): log("Checking no pids for {} exist".format(svc_string), level=INFO) - assert(subprocess.call(["pgrep", svc_string]) == 1) + assert(subprocess.call(["pgrep", svc_string, "--nslist", "pid", + "--ns", str(os.getpid())]) == 1) if not ptable_string: ptable_string = service_name diff --git a/unit_tests/test_keystone_utils.py b/unit_tests/test_keystone_utils.py index b30db3d7..a9b20dbd 100644 --- a/unit_tests/test_keystone_utils.py +++ b/unit_tests/test_keystone_utils.py @@ -822,14 +822,18 @@ class TestKeystoneUtils(CharmTestCase): utils.restart_pid_check('apache2') self.service_stop.assert_called_once_with('apache2') self.service_start.assert_called_once_with('apache2') - self.subprocess.call.assert_called_once_with(['pgrep', 'apache2']) + self.subprocess.call.assert_called_once_with( + ['pgrep', 'apache2', '--nslist', 'pid', '--ns', str(os.getpid())] + ) def test_restart_pid_check_ptable_string(self): self.subprocess.call.return_value = 1 utils.restart_pid_check('apache2', ptable_string='httpd') self.service_stop.assert_called_once_with('apache2') self.service_start.assert_called_once_with('apache2') - self.subprocess.call.assert_called_once_with(['pgrep', 'httpd']) + self.subprocess.call.assert_called_once_with( + ['pgrep', 'httpd', '--nslist', 'pid', '--ns', str(os.getpid())] + ) # Do not sleep() to speed up manual runs. @patch('charmhelpers.core.decorators.time') @@ -841,9 +845,12 @@ class TestKeystoneUtils(CharmTestCase): self.service_start.assert_called_once_with('apache2') # self.subprocess.call.assert_called_once_with(['pgrep', 'httpd']) expected = [ - call(['pgrep', 'httpd']), - call(['pgrep', 'httpd']), - call(['pgrep', 'httpd']), + call(['pgrep', 'httpd', '--nslist', 'pid', '--ns', + str(os.getpid())]), + call(['pgrep', 'httpd', '--nslist', 'pid', '--ns', + str(os.getpid())]), + call(['pgrep', 'httpd', '--nslist', 'pid', '--ns', + str(os.getpid())]) ] self.assertEqual(self.subprocess.call.call_args_list, expected)