[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v3 11/11] iotests: test nbd reconnect
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH v3 11/11] iotests: test nbd reconnect |
Date: |
Sat, 9 Jun 2018 18:32:17 +0300 |
Add test, which starts backup to nbd target and restarts nbd server
during backup.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
tests/qemu-iotests/220 | 68 +++++++++++++++++++++++++++++++++++++++++++
tests/qemu-iotests/220.out | 7 +++++
tests/qemu-iotests/group | 1 +
tests/qemu-iotests/iotests.py | 4 +++
4 files changed, 80 insertions(+)
create mode 100755 tests/qemu-iotests/220
create mode 100644 tests/qemu-iotests/220.out
diff --git a/tests/qemu-iotests/220 b/tests/qemu-iotests/220
new file mode 100755
index 0000000000..f1c26a2796
--- /dev/null
+++ b/tests/qemu-iotests/220
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+#
+# Test nbd reconnect
+#
+# Copyright (c) 2018 Virtuozzo International GmbH
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import time
+
+import iotests
+from iotests import qemu_img_create, file_path, qemu_nbd_popen
+
+disk_a, disk_b, nbd_sock = file_path('disk_a', 'disk_b', 'nbd-sock')
+nbd_uri = 'nbd+unix:///exp?socket=' + nbd_sock
+
+qemu_img_create('-f', iotests.imgfmt, disk_a, '5M')
+qemu_img_create('-f', iotests.imgfmt, disk_b, '5M')
+srv = qemu_nbd_popen('-k', nbd_sock, '-x', 'exp', '-f', iotests.imgfmt, disk_b)
+time.sleep(1)
+
+vm = iotests.VM().add_drive(disk_a)
+vm.launch()
+vm.hmp_qemu_io('drive0', 'write 0 5M')
+
+print 'blockdev-add:', vm.qmp('blockdev-add', node_name='backup0',
driver='raw',
+ file={'driver':'nbd',
+ 'reconnect-attempts':10,
+ 'export': 'exp',
+ 'server': {'type': 'unix',
+ 'path': nbd_sock}})
+print 'blockdev-backup:', vm.qmp('blockdev-backup', device='drive0',
+ sync='full', target='backup0')
+
+time.sleep(1)
+print 'Kill NBD server'
+srv.kill()
+
+jobs = vm.qmp('query-block-jobs')['return']
+if jobs and jobs[0]['offset'] < jobs[0]['len']:
+ print 'Backup job is still in progress'
+
+time.sleep(1)
+
+print 'Start NBD server'
+srv = qemu_nbd_popen('-k', nbd_sock, '-x', 'exp', '-f', iotests.imgfmt, disk_b)
+
+try:
+ e = vm.event_wait('BLOCK_JOB_COMPLETED')
+ print e['event'], ':', e['data']
+except:
+ pass
+
+print 'blockdev-del:', vm.qmp('blockdev-del', node_name='backup0')
+srv.kill()
+vm.shutdown()
diff --git a/tests/qemu-iotests/220.out b/tests/qemu-iotests/220.out
new file mode 100644
index 0000000000..dae1a49d9f
--- /dev/null
+++ b/tests/qemu-iotests/220.out
@@ -0,0 +1,7 @@
+blockdev-add: {u'return': {}}
+blockdev-backup: {u'return': {}}
+Kill NBD server
+Backup job is still in progress
+Start NBD server
+BLOCK_JOB_COMPLETED : {u'device': u'drive0', u'type': u'backup', u'speed': 0,
u'len': 5242880, u'offset': 5242880}
+blockdev-del: {u'return': {}}
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 93f93d71ba..cc5a1cf2a4 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -217,3 +217,4 @@
216 rw auto quick
218 rw auto quick
219 rw auto
+220 rw auto quick
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index fdbdd8b300..7071318c9e 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -175,6 +175,10 @@ 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))
+def qemu_nbd_popen(*args):
+ '''Run qemu-nbd in daemon mode and return the parent's exit code'''
+ return subprocess.Popen(qemu_nbd_args + ['--persistent'] + list(args))
+
def compare_images(img1, img2, fmt1=imgfmt, fmt2=imgfmt):
'''Return True if two image files are identical'''
return qemu_img('compare', '-f', fmt1,
--
2.11.1
- [Qemu-block] [PATCH v3 00/11] NBD reconnect, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 10/11] block/nbd-client: nbd reconnect, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 09/11] block/nbd: add cmdline and qapi parameters for nbd reconnect, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 11/11] iotests: test nbd reconnect,
Vladimir Sementsov-Ogievskiy <=
- [Qemu-block] [PATCH v3 08/11] block/nbd-client: move connecting to connection_co, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 02/11] block/nbd: move connection code from block/nbd to block/nbd-client, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 04/11] block/nbd-client: fix nbd_reply_chunk_iter_receive, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 05/11] block/nbd-client: don't check ioc, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 06/11] block/nbd-client: move from quit to state, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 01/11] block/nbd-client: split channel errors from export errors, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 07/11] block/nbd-client: rename read_reply_co to connection_co, Vladimir Sementsov-Ogievskiy, 2018/06/09
- [Qemu-block] [PATCH v3 03/11] block/nbd-client: split connection from initialization, Vladimir Sementsov-Ogievskiy, 2018/06/09