3 # Copyright (C) 2017 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 # Non-shared storage migration test using NBD server and drive-mirror
26 iotests
.verify_platform(['linux'])
29 source_img_path
= os
.path
.join(iotests
.test_dir
, 'source.img')
30 dest_img_path
= os
.path
.join(iotests
.test_dir
, 'dest.img')
31 iotests
.qemu_img_pipe('create', '-f', iotests
.imgfmt
, source_img_path
, img_size
)
32 iotests
.qemu_img_pipe('create', '-f', iotests
.imgfmt
, dest_img_path
, img_size
)
34 iotests
.log('Launching VMs...')
35 migration_sock_path
= os
.path
.join(iotests
.test_dir
, 'migration.sock')
36 nbd_sock_path
= os
.path
.join(iotests
.test_dir
, 'nbd.sock')
37 source_vm
= iotests
.VM('source').add_drive(source_img_path
)
38 dest_vm
= (iotests
.VM('dest').add_drive(dest_img_path
)
39 .add_incoming('unix:{0}'.format(migration_sock_path
)))
41 atexit
.register(source_vm
.shutdown
)
43 atexit
.register(dest_vm
.shutdown
)
45 iotests
.log('Launching NBD server on destination...')
46 iotests
.log(dest_vm
.qmp('nbd-server-start', addr
={'type': 'unix', 'data': {'path': nbd_sock_path
}}))
47 iotests
.log(dest_vm
.qmp('nbd-server-add', device
='drive0', writable
=True))
49 iotests
.log('Starting drive-mirror on source...')
50 iotests
.log(source_vm
.qmp(
53 target
='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path
),
55 format
='raw', # always raw, the server handles the format
58 iotests
.log('Waiting for drive-mirror to complete...')
59 iotests
.log(source_vm
.event_wait('BLOCK_JOB_READY'),
60 filters
=[iotests
.filter_qmp_event
])
62 iotests
.log('Starting migration...')
63 source_vm
.qmp('migrate-set-capabilities',
64 capabilities
=[{'capability': 'events', 'state': True}])
65 dest_vm
.qmp('migrate-set-capabilities',
66 capabilities
=[{'capability': 'events', 'state': True}])
67 iotests
.log(source_vm
.qmp('migrate', uri
='unix:{0}'.format(migration_sock_path
)))
70 event
= source_vm
.event_wait('MIGRATION')
71 iotests
.log(event
, filters
=[iotests
.filter_qmp_event
])
72 if event
['data']['status'] in ('completed', 'failed'):