xref: /openbmc/qemu/tests/qemu-iotests/208 (revision 0dacec87)
1#!/usr/bin/env python
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
25with iotests.FilePath('disk.img') as disk_img_path, \
26     iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \
27     iotests.FilePath('nbd.sock') as nbd_sock_path, \
28     iotests.VM() as vm:
29
30    img_size = '10M'
31    iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk_img_path, img_size)
32
33    iotests.log('Launching VM...')
34    (vm.add_drive(disk_img_path, 'node-name=drive0-node', interface='none')
35       .launch())
36
37    iotests.log('Starting NBD server...')
38    iotests.log(vm.qmp('nbd-server-start', addr={
39            "type": "unix",
40            "data": {
41                "path": nbd_sock_path,
42            }
43        }))
44
45    iotests.log('Adding NBD export...')
46    iotests.log(vm.qmp('nbd-server-add', device='drive0-node', writable=True))
47
48    iotests.log('Creating external snapshot...')
49    iotests.log(vm.qmp('blockdev-snapshot-sync',
50        node_name='drive0-node',
51        snapshot_node_name='drive0-snapshot-node',
52        snapshot_file=disk_snapshot_img_path))
53
54    iotests.log('Stopping NBD server...')
55    iotests.log(vm.qmp('nbd-server-stop'))
56