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