Merge "Add extra unit test for get_cmdline_from_pid function" into stable/rocky
This commit is contained in:
commit
6ebfdc52f9
|
@ -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):
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue