es1370: check total frame count against current frame
[qemu/ar7.git] / tests / qemu-iotests / 264
blob304a7443d77f8e440e91b4f38d236720c5bf5bab
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.script_initialize(
28     supported_fmts=['qcow2'],
31 disk_a, disk_b, nbd_sock = file_path('disk_a', 'disk_b', 'nbd-sock')
32 nbd_uri = 'nbd+unix:///?socket=' + nbd_sock
33 size = 5 * 1024 * 1024
34 wait_limit = 3
35 wait_step = 0.2
37 qemu_img_create('-f', iotests.imgfmt, disk_a, str(size))
38 qemu_img_create('-f', iotests.imgfmt, disk_b, str(size))
39 srv = qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b)
41 # Wait for NBD server availability
42 t = 0
43 ok = False
44 while t < wait_limit:
45     ok = qemu_io_silent_check('-f', 'raw', '-c', 'read 0 512', nbd_uri)
46     if ok:
47         break
48     time.sleep(wait_step)
49     t += wait_step
51 assert ok
53 vm = iotests.VM().add_drive(disk_a)
54 vm.launch()
55 vm.hmp_qemu_io('drive0', 'write 0 {}'.format(size))
57 vm.qmp_log('blockdev-add', filters=[iotests.filter_qmp_testfiles],
58            **{'node_name': 'backup0',
59               'driver': 'raw',
60               'file': {'driver': 'nbd',
61                        'server': {'type': 'unix', 'path': nbd_sock},
62                        'reconnect-delay': 10}})
63 vm.qmp_log('blockdev-backup', device='drive0', sync='full', target='backup0',
64            speed=(1 * 1024 * 1024))
66 # Wait for some progress
67 t = 0
68 while t < wait_limit:
69     jobs = vm.qmp('query-block-jobs')['return']
70     if jobs and jobs[0]['offset'] > 0:
71         break
72     time.sleep(wait_step)
73     t += wait_step
75 if jobs and jobs[0]['offset'] > 0:
76     log('Backup job is started')
78 log('Kill NBD server')
79 srv.kill()
80 srv.wait()
82 jobs = vm.qmp('query-block-jobs')['return']
83 if jobs and jobs[0]['offset'] < jobs[0]['len']:
84     log('Backup job is still in progress')
86 vm.qmp_log('block-job-set-speed', device='drive0', speed=0)
88 # Emulate server down time for 1 second
89 time.sleep(1)
91 log('Start NBD server')
92 srv = qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b)
94 e = vm.event_wait('BLOCK_JOB_COMPLETED')
95 log('Backup completed: {}'.format(e['data']['offset']))
97 vm.qmp_log('blockdev-del', node_name='backup0')
98 srv.kill()
99 vm.shutdown()