[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 5/6] iotests: implement QemuIoInteractive class
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH v2 5/6] iotests: implement QemuIoInteractive class |
Date: |
Thu, 18 Jan 2018 21:11:22 +0300 |
Implement QemuIoInteractive to test nbd-server-remove command when
there are active connections.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
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
- [Qemu-block] [PATCH v2 0/6] nbd export qmp interface, Vladimir Sementsov-Ogievskiy, 2018/01/18
- [Qemu-block] [PATCH v2 2/6] hmp: add name parameter to nbd_server_add, Vladimir Sementsov-Ogievskiy, 2018/01/18
- [Qemu-block] [PATCH v2 5/6] iotests: implement QemuIoInteractive class,
Vladimir Sementsov-Ogievskiy <=
- [Qemu-block] [PATCH v2 1/6] qapi: add name parameter to nbd-server-add, Vladimir Sementsov-Ogievskiy, 2018/01/18
- [Qemu-block] [PATCH v2 3/6] qapi: add nbd-server-remove, Vladimir Sementsov-Ogievskiy, 2018/01/18
- [Qemu-block] [PATCH v2 4/6] iotest 147: add cases to test new @name parameter of nbd-server-add, Vladimir Sementsov-Ogievskiy, 2018/01/18
- [Qemu-block] [PATCH v2 6/6] iotest 201: new test for qmp nbd-server-remove, Vladimir Sementsov-Ogievskiy, 2018/01/18
- Re: [Qemu-block] [PATCH v2 0/6] nbd export qmp interface, Eric Blake, 2018/01/18