From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: armbru@redhat.com, dgilbert@redhat.com, mreitz@redhat.com,
kwolf@redhat.com, pbonzini@redhat.com, eblake@redhat.com,
vsementsov@virtuozzo.com, den@openvz.org
Subject: [Qemu-devel] [PATCH v3 4/5] iotests: implement QemuIoInteractive class
Date: Fri, 19 Jan 2018 16:57:18 +0300 [thread overview]
Message-ID: <20180119135719.24745-5-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20180119135719.24745-1-vsementsov@virtuozzo.com>
Implement QemuIoInteractive to test nbd-server-remove command when
there are active connections.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
tests/qemu-iotests/iotests.py | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 44477e9295..5a10b2d534 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -93,6 +93,44 @@ def qemu_io(*args):
sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, ' '.join(args)))
return subp.communicate()[0]
+
+class QemuIoInteractive:
+ def __init__(self, *args):
+ self.args = qemu_io_args + list(args)
+ self._p = subprocess.Popen(self.args, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ assert self._p.stdout.read(9) == 'qemu-io> '
+
+ def close(self):
+ self._p.communicate('q\n')
+
+ def _read_output(self):
+ pattern = 'qemu-io> '
+ n = len(pattern)
+ pos = 0
+ s = []
+ while pos != n:
+ c = self._p.stdout.read(1)
+ # check unexpected EOF
+ assert c != ''
+ s.append(c)
+ if c == pattern[pos]:
+ pos += 1
+ else:
+ pos = 0
+
+ return ''.join(s[:-n])
+
+ def cmd(self, cmd):
+ # quit command is in close(), '\n' is added automatically
+ assert '\n' not in cmd
+ cmd = cmd.strip()
+ assert cmd != 'q' and cmd != 'quit'
+ self._p.stdin.write(cmd + '\n')
+ return self._read_output()
+
+
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.11.1
next prev parent reply other threads:[~2018-01-19 13:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-19 13:57 [Qemu-devel] [PATCH v3 0/5] nbd export qmp interface Vladimir Sementsov-Ogievskiy
2018-01-19 13:57 ` [Qemu-devel] [PATCH v3 1/5] qapi: add name parameter to nbd-server-add Vladimir Sementsov-Ogievskiy
2018-01-19 13:57 ` [Qemu-devel] [PATCH v3 2/5] qapi: add nbd-server-remove Vladimir Sementsov-Ogievskiy
2018-01-22 22:33 ` Eric Blake
2018-01-19 13:57 ` [Qemu-devel] [PATCH v3 3/5] iotest 147: add cases to test new @name parameter of nbd-server-add Vladimir Sementsov-Ogievskiy
2018-01-19 13:57 ` Vladimir Sementsov-Ogievskiy [this message]
2018-01-19 13:57 ` [Qemu-devel] [PATCH v3 5/5] iotest 201: new test for qmp nbd-server-remove Vladimir Sementsov-Ogievskiy
2018-01-23 15:12 ` Eric Blake
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=20180119135719.24745-5-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).