diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index ff85785186a..2f082485772 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -314,20 +314,18 @@ def get_cmdline_from_pid(pid): if not process_is_running(pid): return [] with open('/proc/%s/cmdline' % pid, 'r') as f: - cmdline = f.readline() - cmdline_args = cmdline.split('\0')[:-1] + cmdline = f.readline().split('\0')[:-1] # NOTE(slaweq): sometimes it may happen that values in # /proc/{pid}/cmdline are separated by space instead of NUL char, # in such case we would have everything in one element of cmdline_args # list and it would not match to expected cmd so we need to try to # split it by spaces - if len(cmdline_args) == 1: - cmdline_args = cmdline_args[0].split(' ') + if len(cmdline) == 1: + cmdline = cmdline[0].split(' ') - LOG.debug("Found cmdline %s for rocess with PID %s.", - cmdline_args, pid) - return cmdline_args + LOG.debug("Found cmdline %s for process with PID %s.", cmdline, pid) + return cmdline def cmd_matches_expected(cmd, expected_cmd): diff --git a/neutron/tests/unit/agent/linux/test_utils.py b/neutron/tests/unit/agent/linux/test_utils.py index 1b7f64eb856..1c798217a9c 100644 --- a/neutron/tests/unit/agent/linux/test_utils.py +++ b/neutron/tests/unit/agent/linux/test_utils.py @@ -322,6 +322,11 @@ class TestGetCmdlineFromPid(base.BaseTestCase): expected_cmdline = ["python3", "test-binary", "test", "option"] self._test_cmdline(process_cmd, expected_cmdline) + def test_cmdline_with_single_argument(self): + process_cmd = "test-binary\0" + expected_cmdline = ["test-binary"] + self._test_cmdline(process_cmd, expected_cmdline) + def test_no_process_running(self): self.process_is_running_mock.return_value = False mock_open = self.useFixture(