From: Hanna Reitz <hreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
Eric Blake <eblake@redhat.com>,
qemu-devel@nongnu.org
Subject: [PATCH 4/7] iotests.py: Add QemuStorageDaemon class
Date: Thu, 3 Feb 2022 17:30:21 +0100 [thread overview]
Message-ID: <20220203163024.38913-5-hreitz@redhat.com> (raw)
In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com>
This is a rather simple class that allows creating a QSD instance
running in the background and stopping it when no longer needed.
The __del__ handler is a safety net for when something goes so wrong in
a test that e.g. the tearDown() method is not called (e.g. setUp()
launches the QSD, but then launching a VM fails). We do not want the
QSD to continue running after the test has failed, so __del__() will
take care to kill it.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
tests/qemu-iotests/iotests.py | 42 +++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 8cdb381f2a..c75e402b87 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -73,6 +73,8 @@
qemu_prog = os.environ.get('QEMU_PROG', 'qemu')
qemu_opts = os.environ.get('QEMU_OPTIONS', '').strip().split(' ')
+qsd_prog = os.environ.get('QSD_PROG', 'qemu-storage-daemon')
+
gdb_qemu_env = os.environ.get('GDB_OPTIONS')
qemu_gdb = []
if gdb_qemu_env:
@@ -345,6 +347,46 @@ def cmd(self, cmd):
return self._read_output()
+class QemuStorageDaemon:
+ def __init__(self, *args: str, instance_id: Optional[str] = None):
+ if not instance_id:
+ instance_id = 'a'
+
+ self.pidfile = os.path.join(test_dir, f'qsd-{instance_id}-pid')
+ all_args = [qsd_prog] + list(args) + ['--pidfile', self.pidfile]
+
+ # Cannot use with here, we want the subprocess to stay around
+ # pylint: disable=consider-using-with
+ self._p = subprocess.Popen(all_args)
+ while not os.path.exists(self.pidfile):
+ if self._p.poll() is not None:
+ cmd = ' '.join(all_args)
+ raise RuntimeError(
+ 'qemu-storage-daemon terminated with exit code ' +
+ f'{self._p.returncode}: {cmd}')
+
+ time.sleep(0.01)
+
+ with open(self.pidfile, encoding='utf-8') as f:
+ self._pid = int(f.read().strip())
+
+ assert self._pid == self._p.pid
+
+ def stop(self, kill_signal=15):
+ self._p.send_signal(kill_signal)
+ self._p.wait()
+ self._p = None
+
+ try:
+ os.remove(self.pidfile)
+ except OSError:
+ pass
+
+ def __del__(self):
+ if self._p is not None:
+ self.stop(kill_signal=9)
+
+
def qemu_nbd(*args):
'''Run qemu-nbd in daemon mode and return the parent's exit code'''
return subprocess.call(qemu_nbd_args + ['--fork'] + list(args))
--
2.34.1
next prev parent reply other threads:[~2022-02-03 16:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 16:30 [PATCH 0/7] block/nbd: Move s->ioc on AioContext change Hanna Reitz
2022-02-03 16:30 ` [PATCH 1/7] block/nbd: Delete reconnect delay timer when done Hanna Reitz
2022-02-04 8:50 ` Vladimir Sementsov-Ogievskiy
2022-02-03 16:30 ` [PATCH 2/7] block/nbd: Delete open " Hanna Reitz
2022-02-04 8:52 ` Vladimir Sementsov-Ogievskiy
2022-02-03 16:30 ` [PATCH 3/7] block/nbd: Assert there are no timers when closed Hanna Reitz
2022-02-04 8:54 ` Vladimir Sementsov-Ogievskiy
2022-02-03 16:30 ` Hanna Reitz [this message]
2022-02-04 9:04 ` [PATCH 4/7] iotests.py: Add QemuStorageDaemon class Vladimir Sementsov-Ogievskiy
2022-02-04 9:58 ` Hanna Reitz
2022-02-03 16:30 ` [PATCH 5/7] iotests/281: Test lingering timers Hanna Reitz
2022-02-04 9:17 ` Vladimir Sementsov-Ogievskiy
2022-02-03 16:30 ` [PATCH 6/7] block/nbd: Move s->ioc on AioContext change Hanna Reitz
2022-02-04 9:20 ` Vladimir Sementsov-Ogievskiy
2022-02-03 16:30 ` [PATCH 7/7] iotests/281: Let NBD connection yield in iothread Hanna Reitz
2022-02-04 9:31 ` Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220203163024.38913-5-hreitz@redhat.com \
--to=hreitz@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).