xref: /openbmc/qemu/tests/qemu-iotests/194 (revision 6402cbbb)
1#!/usr/bin/env python
2#
3# Copyright (C) 2017 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# Non-shared storage migration test using NBD server and drive-mirror
21
22import os
23import atexit
24import iotests
25
26iotests.verify_platform(['linux'])
27
28img_size = '1G'
29source_img_path = os.path.join(iotests.test_dir, 'source.img')
30dest_img_path = os.path.join(iotests.test_dir, 'dest.img')
31iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, source_img_path, img_size)
32iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, dest_img_path, img_size)
33
34iotests.log('Launching VMs...')
35migration_sock_path = os.path.join(iotests.test_dir, 'migration.sock')
36nbd_sock_path = os.path.join(iotests.test_dir, 'nbd.sock')
37source_vm = iotests.VM('source').add_drive(source_img_path)
38dest_vm = (iotests.VM('dest').add_drive(dest_img_path)
39                             .add_incoming('unix:{0}'.format(migration_sock_path)))
40source_vm.launch()
41atexit.register(source_vm.shutdown)
42dest_vm.launch()
43atexit.register(dest_vm.shutdown)
44
45iotests.log('Launching NBD server on destination...')
46iotests.log(dest_vm.qmp('nbd-server-start', addr={'type': 'unix', 'data': {'path': nbd_sock_path}}))
47iotests.log(dest_vm.qmp('nbd-server-add', device='drive0', writable=True))
48
49iotests.log('Starting drive-mirror on source...')
50iotests.log(source_vm.qmp(
51              'drive-mirror',
52              device='drive0',
53              target='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path),
54              sync='full',
55              format='raw', # always raw, the server handles the format
56              mode='existing'))
57
58iotests.log('Waiting for drive-mirror to complete...')
59iotests.log(source_vm.event_wait('BLOCK_JOB_READY'),
60            filters=[iotests.filter_qmp_event])
61
62iotests.log('Starting migration...')
63source_vm.qmp('migrate-set-capabilities',
64              capabilities=[{'capability': 'events', 'state': True}])
65dest_vm.qmp('migrate-set-capabilities',
66            capabilities=[{'capability': 'events', 'state': True}])
67iotests.log(source_vm.qmp('migrate', uri='unix:{0}'.format(migration_sock_path)))
68
69while True:
70    event = source_vm.event_wait('MIGRATION')
71    iotests.log(event, filters=[iotests.filter_qmp_event])
72    if event['data']['status'] in ('completed', 'failed'):
73        break
74