17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 244a8174eSStefan Hajnoczi# 344a8174eSStefan Hajnoczi# Copyright (C) 2018 Red Hat, Inc. 444a8174eSStefan Hajnoczi# 544a8174eSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 644a8174eSStefan Hajnoczi# it under the terms of the GNU General Public License as published by 744a8174eSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 844a8174eSStefan Hajnoczi# (at your option) any later version. 944a8174eSStefan Hajnoczi# 1044a8174eSStefan Hajnoczi# This program is distributed in the hope that it will be useful, 1144a8174eSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 1244a8174eSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1344a8174eSStefan Hajnoczi# GNU General Public License for more details. 1444a8174eSStefan Hajnoczi# 1544a8174eSStefan Hajnoczi# You should have received a copy of the GNU General Public License 1644a8174eSStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 1744a8174eSStefan Hajnoczi# 1844a8174eSStefan Hajnoczi# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com> 1944a8174eSStefan Hajnoczi# 2044a8174eSStefan Hajnoczi# Check that the runtime NBD server does not crash when stopped after 2144a8174eSStefan Hajnoczi# blockdev-snapshot-sync. 2244a8174eSStefan Hajnoczi 2344a8174eSStefan Hajnocziimport iotests 2444a8174eSStefan Hajnoczi 257d814059SJohn Snowiotests.script_initialize(supported_fmts=['generic']) 26e819edd0SVladimir Sementsov-Ogievskiy 2744a8174eSStefan Hajnocziwith iotests.FilePath('disk.img') as disk_img_path, \ 2844a8174eSStefan Hajnoczi iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \ 29*3192fad7SNir Soffer iotests.FilePath('nbd.sock', base_dir=iotests.sock_dir) as nbd_sock_path, \ 3044a8174eSStefan Hajnoczi iotests.VM() as vm: 3144a8174eSStefan Hajnoczi 3244a8174eSStefan Hajnoczi img_size = '10M' 33eb42e719SVladimir Sementsov-Ogievskiy iotests.qemu_img_create('-f', iotests.imgfmt, disk_img_path, img_size) 3444a8174eSStefan Hajnoczi 3544a8174eSStefan Hajnoczi iotests.log('Launching VM...') 3644a8174eSStefan Hajnoczi (vm.add_drive(disk_img_path, 'node-name=drive0-node', interface='none') 3744a8174eSStefan Hajnoczi .launch()) 3844a8174eSStefan Hajnoczi 3944a8174eSStefan Hajnoczi iotests.log('Starting NBD server...') 4044a8174eSStefan Hajnoczi iotests.log(vm.qmp('nbd-server-start', addr={ 4144a8174eSStefan Hajnoczi "type": "unix", 4244a8174eSStefan Hajnoczi "data": { 4344a8174eSStefan Hajnoczi "path": nbd_sock_path, 4444a8174eSStefan Hajnoczi } 4544a8174eSStefan Hajnoczi })) 4644a8174eSStefan Hajnoczi 4744a8174eSStefan Hajnoczi iotests.log('Adding NBD export...') 4844a8174eSStefan Hajnoczi iotests.log(vm.qmp('nbd-server-add', device='drive0-node', writable=True)) 4944a8174eSStefan Hajnoczi 5044a8174eSStefan Hajnoczi iotests.log('Creating external snapshot...') 5144a8174eSStefan Hajnoczi iotests.log(vm.qmp('blockdev-snapshot-sync', 5244a8174eSStefan Hajnoczi node_name='drive0-node', 5344a8174eSStefan Hajnoczi snapshot_node_name='drive0-snapshot-node', 5444a8174eSStefan Hajnoczi snapshot_file=disk_snapshot_img_path)) 5544a8174eSStefan Hajnoczi 5644a8174eSStefan Hajnoczi iotests.log('Stopping NBD server...') 5744a8174eSStefan Hajnoczi iotests.log(vm.qmp('nbd-server-stop')) 58