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/>.
24 from iotests import qemu_img_create, qemu_io_silent_check, file_path, \
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
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
43 ok = qemu_io_silent_check('-f', 'raw', '-c', 'read 0 512', nbd_uri)
51 vm = iotests.VM().add_drive(disk_a)
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',
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
67 jobs = vm.qmp('query-block-jobs')['return']
68 if jobs and jobs[0]['offset'] > 0:
73 if jobs and jobs[0]['offset'] > 0:
74 log('Backup job is started')
76 log('Kill NBD server')
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
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')