1#!/usr/bin/env python 2# 3# Test resume mirror after auto pause on ENOSPC 4# 5# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. 6# 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. 11# 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. 16# 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/>. 19# 20 21import iotests 22from iotests import qemu_img_create, qemu_io, file_path, filter_qmp_testfiles 23 24iotests.verify_image_format(supported_fmts=['qcow2']) 25 26source, target = file_path('source', 'target') 27size = 5 * 1024 * 1024 28limit = 2 * 1024 * 1024 29 30qemu_img_create('-f', iotests.imgfmt, source, str(size)) 31qemu_img_create('-f', iotests.imgfmt, target, str(size)) 32qemu_io('-c', 'write 0 {}'.format(size), source) 33 34# raw format don't like empty files 35qemu_io('-c', 'write 0 {}'.format(size), target) 36 37vm = iotests.VM().add_drive(source) 38vm.launch() 39 40blockdev_opts = { 41 'driver': iotests.imgfmt, 42 'node-name': 'target', 43 'file': { 44 'driver': 'raw', 45 'size': limit, 46 'file': { 47 'driver': 'file', 48 'filename': target 49 } 50 } 51} 52vm.qmp_log('blockdev-add', filters=[filter_qmp_testfiles], **blockdev_opts) 53 54vm.qmp_log('blockdev-mirror', device='drive0', sync='full', target='target', 55 on_target_error='enospc') 56 57vm.event_wait('JOB_STATUS_CHANGE', timeout=3.0, 58 match={'data': {'status': 'paused'}}) 59 60# drop other cached events, to not interfere with further wait for 'running' 61vm.get_qmp_events() 62 63del blockdev_opts['file']['size'] 64vm.qmp_log('x-blockdev-reopen', filters=[filter_qmp_testfiles], 65 **blockdev_opts) 66 67vm.qmp_log('block-job-resume', device='drive0') 68vm.event_wait('JOB_STATUS_CHANGE', timeout=1.0, 69 match={'data': {'status': 'running'}}) 70 71vm.shutdown() 72