[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/10] iotests: ensure that QemuIoInteractive definitely closes
From: |
John Snow |
Subject: |
[PATCH 10/10] iotests: ensure that QemuIoInteractive definitely closes |
Date: |
Wed, 12 May 2021 17:46:42 -0400 |
More on the lines of quieting pylint 2.8.x, though to make it obvious
that we definitely handle the cleanup here, I elected to bolster the
close() method here.
1. Check for the process having terminated early more rigorously by
checking poll() directly.
2. Change the prompt read into an assertion.
3. Ensure that the final communicate() call *definitely* closes the
socket, adding a timeout and a final kill just in case.
Signed-off-by: John Snow <jsnow@redhat.com>
---
tests/qemu-iotests/iotests.py | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index e09c991b84e..12e876fa67d 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -238,20 +238,27 @@ def qemu_io_silent_check(*args):
class QemuIoInteractive:
def __init__(self, *args):
self.args = qemu_io_args_no_fmt + list(args)
+
+ # Resource cleaned up via close()
+ # pylint: disable=consider-using-with
self._p = subprocess.Popen(self.args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
+ if self._p.poll():
+ # Failed to start.
+ out = self._p.stdout.read()
+ raise subprocess.SubprocessError(out, self._p.poll())
+
+ # Eat the first prompt
out = self._p.stdout.read(9)
- if out != 'qemu-io> ':
- # Most probably qemu-io just failed to start.
- # Let's collect the whole output and exit.
- out += self._p.stdout.read()
- self._p.wait(timeout=1)
- raise ValueError(out)
+ assert out == 'qemu-io> ', "Did not understand qemu-io prompt"
def close(self):
- self._p.communicate('q\n')
+ try:
+ self._p.communicate('q\n', timeout=5)
+ except subprocess.TimeoutExpired:
+ self._p.kill()
def _read_output(self):
pattern = 'qemu-io> '
--
2.30.2
- Re: [PATCH 03/10] python/machine: use subprocess.run instead of subprocess.Popen, (continued)
- [PATCH 04/10] python/console_socket: Add a pylint ignore, John Snow, 2021/05/12
- [PATCH 08/10] iotests: use 'with open()' where applicable, John Snow, 2021/05/12
- [PATCH 06/10] python/machine: disable warning for Popen in _launch(), John Snow, 2021/05/12
- [PATCH 09/10] iotests: silence spurious consider-using-with warnings, John Snow, 2021/05/12
- [PATCH 07/10] iotests: use subprocess.run where possible, John Snow, 2021/05/12
- [PATCH 02/10] python/machine: use subprocess.DEVNULL instead of open(os.path.devnull), John Snow, 2021/05/12
- [PATCH 10/10] iotests: ensure that QemuIoInteractive definitely closes,
John Snow <=
- [PATCH 05/10] python/machine: Disable pylint warning for open() in _pre_launch, John Snow, 2021/05/12
- Re: [PATCH 00/10] Python: delint iotests, machine.py and console_socket.py, John Snow, 2021/05/17