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