hmp: Fail gracefully if chardev is already in use
[qemu/ar7.git] / tests / qemu-iotests / 208
blob1c3fc8c7fdd78412b7a628cb08a1dfcdf8a02ad5
1 #!/usr/bin/env python3
3 # Copyright (C) 2018 Red Hat, Inc.
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.
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.
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/>.
18 # Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com>
20 # Check that the runtime NBD server does not crash when stopped after
21 # blockdev-snapshot-sync.
23 import iotests
25 iotests.verify_image_format(supported_fmts=['generic'])
27 with iotests.FilePath('disk.img') as disk_img_path, \
28      iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \
29      iotests.FilePath('nbd.sock', iotests.sock_dir) as nbd_sock_path, \
30      iotests.VM() as vm:
32     img_size = '10M'
33     iotests.qemu_img_create('-f', iotests.imgfmt, disk_img_path, img_size)
35     iotests.log('Launching VM...')
36     (vm.add_drive(disk_img_path, 'node-name=drive0-node', interface='none')
37        .launch())
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         }))
47     iotests.log('Adding NBD export...')
48     iotests.log(vm.qmp('nbd-server-add', device='drive0-node', writable=True))
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))
56     iotests.log('Stopping NBD server...')
57     iotests.log(vm.qmp('nbd-server-stop'))