2020-01-30 17:32:30 +01:00
|
|
|
#!/usr/bin/env python3
|
2021-01-16 14:44:19 +01:00
|
|
|
# group: rw
|
2019-10-09 10:41:58 +02:00
|
|
|
#
|
|
|
|
# Test nbd reconnect
|
|
|
|
#
|
|
|
|
# Copyright (c) 2019 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
|
2020-11-18 19:04:28 +01:00
|
|
|
from iotests import qemu_img_create, file_path, qemu_nbd_popen, log
|
2019-10-09 10:41:58 +02:00
|
|
|
|
2020-03-31 02:00:11 +02:00
|
|
|
iotests.script_initialize(
|
|
|
|
supported_fmts=['qcow2'],
|
|
|
|
)
|
2019-10-25 16:50:22 +02:00
|
|
|
|
2019-10-09 10:41:58 +02:00
|
|
|
disk_a, disk_b, nbd_sock = file_path('disk_a', 'disk_b', 'nbd-sock')
|
|
|
|
nbd_uri = 'nbd+unix:///?socket=' + nbd_sock
|
|
|
|
size = 5 * 1024 * 1024
|
2020-11-18 19:04:28 +01:00
|
|
|
wait_limit = 3.0
|
2019-10-09 10:41:58 +02:00
|
|
|
wait_step = 0.2
|
|
|
|
|
|
|
|
qemu_img_create('-f', iotests.imgfmt, disk_a, str(size))
|
|
|
|
qemu_img_create('-f', iotests.imgfmt, disk_b, str(size))
|
|
|
|
|
2020-07-27 23:58:44 +02:00
|
|
|
with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b):
|
|
|
|
vm = iotests.VM().add_drive(disk_a)
|
|
|
|
vm.launch()
|
|
|
|
vm.hmp_qemu_io('drive0', 'write 0 {}'.format(size))
|
|
|
|
|
|
|
|
vm.qmp_log('blockdev-add', filters=[iotests.filter_qmp_testfiles],
|
|
|
|
**{'node_name': 'backup0',
|
|
|
|
'driver': 'raw',
|
|
|
|
'file': {'driver': 'nbd',
|
|
|
|
'server': {'type': 'unix', 'path': nbd_sock},
|
|
|
|
'reconnect-delay': 10}})
|
2020-11-18 19:04:28 +01:00
|
|
|
vm.qmp_log('blockdev-backup', device='drive0', sync='full',
|
|
|
|
target='backup0', speed=(1 * 1024 * 1024))
|
2020-07-27 23:58:44 +02:00
|
|
|
|
|
|
|
# Wait for some progress
|
2020-11-18 19:04:28 +01:00
|
|
|
t = 0.0
|
2020-07-27 23:58:44 +02:00
|
|
|
while t < wait_limit:
|
|
|
|
jobs = vm.qmp('query-block-jobs')['return']
|
|
|
|
if jobs and jobs[0]['offset'] > 0:
|
|
|
|
break
|
|
|
|
time.sleep(wait_step)
|
|
|
|
t += wait_step
|
2019-10-09 10:41:58 +02:00
|
|
|
|
|
|
|
if jobs and jobs[0]['offset'] > 0:
|
2020-07-27 23:58:44 +02:00
|
|
|
log('Backup job is started')
|
2019-10-09 10:41:58 +02:00
|
|
|
|
|
|
|
jobs = vm.qmp('query-block-jobs')['return']
|
|
|
|
if jobs and jobs[0]['offset'] < jobs[0]['len']:
|
|
|
|
log('Backup job is still in progress')
|
|
|
|
|
|
|
|
vm.qmp_log('block-job-set-speed', device='drive0', speed=0)
|
|
|
|
|
|
|
|
# Emulate server down time for 1 second
|
|
|
|
time.sleep(1)
|
|
|
|
|
2020-07-27 23:58:44 +02:00
|
|
|
with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b):
|
|
|
|
e = vm.event_wait('BLOCK_JOB_COMPLETED')
|
|
|
|
log('Backup completed: {}'.format(e['data']['offset']))
|
|
|
|
vm.qmp_log('blockdev-del', node_name='backup0')
|
|
|
|
vm.shutdown()
|