提交 3d8de8fb 编写于 作者: A Amador Pahim

avocado.utils.process add pid information to CmdResult

process.Popen returns the process ID, so let's use it in our
CmdResult class.

Fixes: #1514
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 aa40fccd
...@@ -222,24 +222,28 @@ class CmdResult(object): ...@@ -222,24 +222,28 @@ class CmdResult(object):
:param stdout: String containing stdout of the process :param stdout: String containing stdout of the process
:param stderr: String containing stderr of the process :param stderr: String containing stderr of the process
:param duration: Elapsed wall clock time running the process :param duration: Elapsed wall clock time running the process
:param pid: ID of the process
""" """
def __init__(self, command="", stdout="", stderr="", def __init__(self, command="", stdout="", stderr="",
exit_status=None, duration=0): exit_status=None, duration=0, pid=None):
self.command = command self.command = command
self.exit_status = exit_status self.exit_status = exit_status
self.stdout = stdout self.stdout = stdout
self.stderr = stderr self.stderr = stderr
self.duration = duration self.duration = duration
self.interrupted = False self.interrupted = False
self.pid = pid
def __repr__(self): def __repr__(self):
cmd_rep = ("Command: %s\n" cmd_rep = ("Command: %s\n"
"Exit status: %s\n" "Exit status: %s\n"
"Duration: %s\n" "Duration: %s\n"
"Stdout:\n%s\n" "Stdout:\n%s\n"
"Stderr:\n%s\n" % (self.command, self.exit_status, "Stderr:\n%s\n"
self.duration, self.stdout, self.stderr)) "PID:\n%s\n" % (self.command, self.exit_status,
self.duration, self.stdout, self.stderr,
self.pid))
if self.interrupted: if self.interrupted:
cmd_rep += "Command interrupted by %s\n" % self.interrupted cmd_rep += "Command interrupted by %s\n" % self.interrupted
return cmd_rep return cmd_rep
...@@ -433,6 +437,7 @@ class SubProcess(object): ...@@ -433,6 +437,7 @@ class SubProcess(object):
if self.verbose: if self.verbose:
log.info("Command '%s' finished with %s after %ss", self.cmd, rc, log.info("Command '%s' finished with %s after %ss", self.cmd, rc,
self.result.duration) self.result.duration)
self.result.pid = self._popen.pid
self._fill_streams() self._fill_streams()
def _fill_streams(self): def _fill_streams(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册