1*d047cfa7SVladimir Sementsov-Ogievskiy#!/usr/bin/env python3 2*d047cfa7SVladimir Sementsov-Ogievskiy# 3*d047cfa7SVladimir Sementsov-Ogievskiy# Test shutdown when bitmap is exported through NBD server 4*d047cfa7SVladimir Sementsov-Ogievskiy# 5*d047cfa7SVladimir Sementsov-Ogievskiy# Copyright (c) 2020 Virtuozzo International GmbH. 6*d047cfa7SVladimir Sementsov-Ogievskiy# 7*d047cfa7SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify 8*d047cfa7SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by 9*d047cfa7SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or 10*d047cfa7SVladimir Sementsov-Ogievskiy# (at your option) any later version. 11*d047cfa7SVladimir Sementsov-Ogievskiy# 12*d047cfa7SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful, 13*d047cfa7SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*d047cfa7SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*d047cfa7SVladimir Sementsov-Ogievskiy# GNU General Public License for more details. 16*d047cfa7SVladimir Sementsov-Ogievskiy# 17*d047cfa7SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License 18*d047cfa7SVladimir Sementsov-Ogievskiy# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*d047cfa7SVladimir Sementsov-Ogievskiy# 20*d047cfa7SVladimir Sementsov-Ogievskiy 21*d047cfa7SVladimir Sementsov-Ogievskiyimport iotests 22*d047cfa7SVladimir Sementsov-Ogievskiy 23*d047cfa7SVladimir Sementsov-Ogievskiy# The test is unrelated to formats, restrict it to qcow2 to avoid extra runs 24*d047cfa7SVladimir Sementsov-Ogievskiyiotests.script_initialize( 25*d047cfa7SVladimir Sementsov-Ogievskiy supported_fmts=['qcow2'], 26*d047cfa7SVladimir Sementsov-Ogievskiy) 27*d047cfa7SVladimir Sementsov-Ogievskiy 28*d047cfa7SVladimir Sementsov-Ogievskiynbd_sock = iotests.file_path('nbd.sock', base_dir=iotests.sock_dir) 29*d047cfa7SVladimir Sementsov-Ogievskiynbd_uri = 'nbd+unix:///disk?socket=' + nbd_sock 30*d047cfa7SVladimir Sementsov-Ogievskiysize = 1024 * 1024 31*d047cfa7SVladimir Sementsov-Ogievskiy 32*d047cfa7SVladimir Sementsov-Ogievskiyvm = iotests.VM() 33*d047cfa7SVladimir Sementsov-Ogievskiyvm.launch() 34*d047cfa7SVladimir Sementsov-Ogievskiy 35*d047cfa7SVladimir Sementsov-Ogievskiyvm.qmp_log('blockdev-add', **{ 36*d047cfa7SVladimir Sementsov-Ogievskiy 'node-name': 'disk', 37*d047cfa7SVladimir Sementsov-Ogievskiy 'driver': 'null-co', 38*d047cfa7SVladimir Sementsov-Ogievskiy 'size': 1024 * 1024, 39*d047cfa7SVladimir Sementsov-Ogievskiy}) 40*d047cfa7SVladimir Sementsov-Ogievskiy 41*d047cfa7SVladimir Sementsov-Ogievskiyvm.qmp_log('block-dirty-bitmap-add', **{ 42*d047cfa7SVladimir Sementsov-Ogievskiy 'node': 'disk', 43*d047cfa7SVladimir Sementsov-Ogievskiy 'name': 'bitmap0' 44*d047cfa7SVladimir Sementsov-Ogievskiy}) 45*d047cfa7SVladimir Sementsov-Ogievskiy 46*d047cfa7SVladimir Sementsov-Ogievskiyvm.qmp_log('nbd-server-start', **{ 47*d047cfa7SVladimir Sementsov-Ogievskiy 'addr': { 48*d047cfa7SVladimir Sementsov-Ogievskiy 'type': 'unix', 49*d047cfa7SVladimir Sementsov-Ogievskiy 'data': {'path': nbd_sock} 50*d047cfa7SVladimir Sementsov-Ogievskiy } 51*d047cfa7SVladimir Sementsov-Ogievskiy}, filters=[iotests.filter_qmp_testfiles]) 52*d047cfa7SVladimir Sementsov-Ogievskiy 53*d047cfa7SVladimir Sementsov-Ogievskiyvm.qmp_log('nbd-server-add', **{ 54*d047cfa7SVladimir Sementsov-Ogievskiy 'device': 'disk', 55*d047cfa7SVladimir Sementsov-Ogievskiy 'writable': True, 56*d047cfa7SVladimir Sementsov-Ogievskiy 'bitmap': 'bitmap0' 57*d047cfa7SVladimir Sementsov-Ogievskiy}) 58*d047cfa7SVladimir Sementsov-Ogievskiy 59*d047cfa7SVladimir Sementsov-Ogievskiyp = iotests.QemuIoInteractive('-f', 'raw', nbd_uri) 60*d047cfa7SVladimir Sementsov-Ogievskiy# wait for connection and check it: 61*d047cfa7SVladimir Sementsov-Ogievskiyiotests.log(p.cmd('read 0 512').rstrip(), filters=[iotests.filter_qemu_io]) 62*d047cfa7SVladimir Sementsov-Ogievskiy 63*d047cfa7SVladimir Sementsov-Ogievskiyvm.shutdown() 64*d047cfa7SVladimir Sementsov-Ogievskiy 65*d047cfa7SVladimir Sementsov-Ogievskiyp.close() 66