diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index 249b3d26fca..d90cf41ccd3 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -324,20 +324,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 c09de840a56..1a2e796e8d5 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(