xref: /openbmc/qemu/tests/qemu-iotests/208 (revision b91a0fa7)
1#!/usr/bin/env python3
2# group: rw quick
3#
4# Copyright (C) 2018 Red Hat, Inc.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com>
20#
21# Check that the runtime NBD server does not crash when stopped after
22# blockdev-snapshot-sync.
23
24import iotests
25
26iotests.script_initialize(supported_fmts=['generic'])
27
28with iotests.FilePath('disk.img') as disk_img_path, \
29     iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \
30     iotests.FilePath('nbd.sock', base_dir=iotests.sock_dir) as nbd_sock_path, \
31     iotests.VM() as vm:
32
33    img_size = '10M'
34    iotests.qemu_img_create('-f', iotests.imgfmt, disk_img_path, img_size)
35
36    iotests.log('Launching VM...')
37    (vm.add_drive(disk_img_path, 'node-name=drive0-node', interface='none')
38       .launch())
39
40    iotests.log('Starting NBD server...')
41    iotests.log(vm.qmp('nbd-server-start', addr={
42            "type": "unix",
43            "data": {
44                "path": nbd_sock_path,
45            }
46        }))
47
48    iotests.log('Adding NBD export...')
49    iotests.log(vm.qmp('nbd-server-add', device='drive0-node', writable=True))
50
51    iotests.log('Creating external snapshot...')
52    iotests.log(vm.qmp('blockdev-snapshot-sync',
53        node_name='drive0-node',
54        snapshot_node_name='drive0-snapshot-node',
55        snapshot_file=disk_snapshot_img_path))
56
57    iotests.log('Stopping NBD server...')
58    iotests.log(vm.qmp('nbd-server-stop'))
59