Nir Soffer has uploaded a new change for review.
Change subject: procwatch: Replace command with process
......................................................................
procwatch: Replace command with process
ProcessWatcher is watching child process, not commands, which can be
confused with abstract things. Rename the argument and instance variable
in the class, the tests, and the user code.
Change-Id: I3a0265d7847d0fffd7cf0c60d1feb87621ee5ac5
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M lib/vdsm/procwatch.py
M lib/vdsm/qemuimg.py
M tests/procwatch_test.py
3 files changed, 33 insertions(+), 33 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/65077/1
diff --git a/lib/vdsm/procwatch.py b/lib/vdsm/procwatch.py
index fd4b543..a75cbc7 100644
--- a/lib/vdsm/procwatch.py
+++ b/lib/vdsm/procwatch.py
@@ -29,16 +29,16 @@
class ProcessWatcher(object):
- def __init__(self, command, stdoutcb, stderrcb):
- self._command = command
+ def __init__(self, process, stdoutcb, stderrcb):
+ self._process = process
self._poll = select.epoll()
self._iocb = {}
# In case both stderr and stdout are using the same fd the
# output is squashed to the stdout (given the order of the
# entries in the dictionary)
- self._iocb[self._command.stderr.fileno()] = stderrcb
- self._iocb[self._command.stdout.fileno()] = stdoutcb
+ self._iocb[self._process.stderr.fileno()] = stderrcb
+ self._iocb[self._process.stdout.fileno()] = stdoutcb
for fd in self._iocb:
self._poll.register(fd, select.EPOLLIN)
@@ -68,7 +68,7 @@
def receive(self, timeout=None):
"""
- Receiving data from the command can raise OSError
+ Receiving data from the process can raise OSError
exceptions as described in read(2).
"""
if timeout is None:
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 0527a15..9133587 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -202,9 +202,9 @@
cmd = cmdutils.wrap_command(cmd, with_nice=utils.NICENESS.HIGH,
with_ioclass=utils.IOCLASS.IDLE)
_log.debug(cmdutils.command_log_line(cmd, cwd=cwd))
- self._command = CPopen(cmd, cwd=cwd, deathSignal=signal.SIGKILL)
+ self._process = CPopen(cmd, cwd=cwd, deathSignal=signal.SIGKILL)
self._watcher = procwatch.ProcessWatcher(
- self._command, self._recvstdout, self._recvstderr)
+ self._process, self._recvstdout, self._recvstderr)
def _recvstderr(self, buffer):
self._stderr += buffer
@@ -244,7 +244,7 @@
@property
def finished(self):
- return self._command.poll() is not None
+ return self._process.poll() is not None
def poll(self, timeout=None):
self._watcher.receive(timeout=timeout)
@@ -252,14 +252,14 @@
if not self._watcher.closed:
return
- self._command.wait()
+ self._process.wait()
if self._aborted:
raise exception.ActionStopped()
- cmdutils.retcode_log_line(self._command.returncode, self.error)
- if self._command.returncode != 0:
- raise QImgError(self._command.returncode, "", self.error)
+ cmdutils.retcode_log_line(self._process.returncode, self.error)
+ if self._process.returncode != 0:
+ raise QImgError(self._process.returncode, "", self.error)
def wait_for_completion(self):
timeout = config.getint("irs", "progress_interval")
@@ -268,9 +268,9 @@
_log.debug('qemu-img operation progress: %s%%', self.progress)
def abort(self):
- if self._command.poll() is None:
+ if self._process.poll() is None:
self._aborted = True
- self._command.terminate()
+ self._process.terminate()
def resize(image, newSize, format=None):
diff --git a/tests/procwatch_test.py b/tests/procwatch_test.py
index d66d3ff..0a5fe2d 100644
--- a/tests/procwatch_test.py
+++ b/tests/procwatch_test.py
@@ -47,16 +47,16 @@
cmd[-1] = cmd[-1] % text
- c = self.startCommand(cmd)
+ process = self.start_process(cmd)
watcher = procwatch.ProcessWatcher(
- c,
+ process,
recv_data if recv_out else self.unexpected_data,
recv_data if recv_err else self.unexpected_data)
while not watcher.closed:
watcher.receive()
- retcode = c.wait()
+ retcode = process.wait()
self.assertEqual(retcode, 0)
self.assertEqual(text, received)
@@ -74,59 +74,59 @@
# defined in the parent function.
operator.iadd(received, buffer)
- c = self.startCommand(cmd)
+ process = self.start_process(cmd)
watcher = procwatch.ProcessWatcher(
- c,
+ process,
recv_data if recv_out else self.unexpected_data,
recv_data if recv_err else self.unexpected_data)
- c.stdin.write(text)
- c.stdin.flush()
- c.stdin.close()
+ process.stdin.write(text)
+ process.stdin.flush()
+ process.stdin.close()
while not watcher.closed:
watcher.receive()
- retcode = c.wait()
+ retcode = process.wait()
self.assertEqual(retcode, 0)
self.assertEqual(text, str(received))
def test_timeout(self):
- c = self.startCommand(["sleep", "5"])
+ process = self.start_process(["sleep", "5"])
watcher = procwatch.ProcessWatcher(
- c, self.unexpected_data, self.unexpected_data)
+ process, self.unexpected_data, self.unexpected_data)
with self.assertElapsed(2):
watcher.receive(2)
self.assertEqual(watcher.closed, False)
- c.terminate()
+ process.terminate()
- self.assertEqual(c.wait(), -signal.SIGTERM)
+ self.assertEqual(process.wait(), -signal.SIGTERM)
@permutations((
('kill', -signal.SIGKILL),
('terminate', -signal.SIGTERM),
))
def test_signals(self, method, expected_retcode):
- c = self.startCommand(["sleep", "2"])
+ process = self.start_process(["sleep", "2"])
watcher = procwatch.ProcessWatcher(
- c, self.unexpected_data, self.unexpected_data)
+ process, self.unexpected_data, self.unexpected_data)
- getattr(c, method)()
+ getattr(process, method)()
try:
with self.assertElapsed(0):
watcher.receive(2)
finally:
- retcode = c.wait()
+ retcode = process.wait()
self.assertEqual(retcode, expected_retcode)
def unexpected_data(self, data):
raise AssertionError("Unexpected data: %r" % data)
- def startCommand(self, command):
- return compat.CPopen(command)
+ def start_process(self, cmd):
+ return compat.CPopen(cmd)
--
To view, visit
https://gerrit.ovirt.org/65077
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a0265d7847d0fffd7cf0c60d1feb87621ee5ac5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>