hw/scsi/spapr_vscsi: Simplify a bit
[qemu/ar7.git] / tests / qemu-iotests / 264
blob879123a343219c4aff0f5ee1ac0068fa206c96d0
1 #!/usr/bin/env python3
3 # Test nbd reconnect
5 # Copyright (c) 2019 Virtuozzo International GmbH.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 import time
23 import iotests
24 from iotests import qemu_img_create, qemu_io_silent_check, file_path, \
25         qemu_nbd_popen, log
27 iotests.verify_image_format(supported_fmts=['qcow2'])
29 disk_a, disk_b, nbd_sock = file_path('disk_a', 'disk_b', 'nbd-sock')
30 nbd_uri = 'nbd+unix:///?socket=' + nbd_sock
31 size = 5 * 1024 * 1024
32 wait_limit = 3
33 wait_step = 0.2
35 qemu_img_create('-f', iotests.imgfmt, disk_a, str(size))
36 qemu_img_create('-f', iotests.imgfmt, disk_b, str(size))
37 srv = qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b)
39 # Wait for NBD server availability
40 t = 0
41 ok = False
42 while t < wait_limit:
43     ok = qemu_io_silent_check('-f', 'raw', '-c', 'read 0 512', nbd_uri)
44     if ok:
45         break
46     time.sleep(wait_step)
47     t += wait_step
49 assert ok
51 vm = iotests.VM().add_drive(disk_a)
52 vm.launch()
53 vm.hmp_qemu_io('drive0', 'write 0 {}'.format(size))
55 vm.qmp_log('blockdev-add', filters=[iotests.filter_qmp_testfiles],
56            **{'node_name': 'backup0',
57               'driver': 'raw',
58               'file': {'driver': 'nbd',
59                        'server': {'type': 'unix', 'path': nbd_sock},
60                        'reconnect-delay': 10}})
61 vm.qmp_log('blockdev-backup', device='drive0', sync='full', target='backup0',
62            speed=(1 * 1024 * 1024))
64 # Wait for some progress
65 t = 0
66 while t < wait_limit:
67     jobs = vm.qmp('query-block-jobs')['return']
68     if jobs and jobs[0]['offset'] > 0:
69         break
70     time.sleep(wait_step)
71     t += wait_step
73 if jobs and jobs[0]['offset'] > 0:
74     log('Backup job is started')
76 log('Kill NBD server')
77 srv.kill()
78 srv.wait()
80 jobs = vm.qmp('query-block-jobs')['return']
81 if jobs and jobs[0]['offset'] < jobs[0]['len']:
82     log('Backup job is still in progress')
84 vm.qmp_log('block-job-set-speed', device='drive0', speed=0)
86 # Emulate server down time for 1 second
87 time.sleep(1)
89 log('Start NBD server')
90 srv = qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b)
92 e = vm.event_wait('BLOCK_JOB_COMPLETED')
93 log('Backup completed: {}'.format(e['data']['offset']))
95 vm.qmp_log('blockdev-del', node_name='backup0')
96 srv.kill()
97 vm.shutdown()