master
text 109 lines 4.75 KB
Raw
1 #!/usr/bin/env python3
2 # group: rw migration quick
3 #
4 # Copyright (C) 2017 Red Hat, Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com>
20 #
21 # Non-shared storage migration test using NBD server and drive-mirror
22
23 import iotests
24
25 iotests.script_initialize(supported_fmts=['qcow2', 'qed', 'raw'],
26 supported_platforms=['linux'])
27
28 with iotests.FilePath('source.img') as source_img_path, \
29 iotests.FilePath('dest.img') as dest_img_path, \
30 iotests.FilePath('migration.sock', 'nbd.sock', base_dir=iotests.sock_dir) \
31 as (migration_sock_path, nbd_sock_path), \
32 iotests.VM('source') as source_vm, \
33 iotests.VM('dest') as dest_vm:
34
35 img_size = '1G'
36 iotests.qemu_img_create('-f', iotests.imgfmt, source_img_path, img_size)
37 iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write 512M 1M', source_img_path)
38 iotests.qemu_img_create('-f', iotests.imgfmt, dest_img_path, img_size)
39
40 iotests.log('Launching VMs...')
41 (source_vm.add_drive(source_img_path)
42 .launch())
43 (dest_vm.add_drive(dest_img_path)
44 .add_incoming('unix:{0}'.format(migration_sock_path))
45 .launch())
46
47 source_vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0')
48
49 iotests.log('Launching NBD server on destination...')
50 iotests.log(dest_vm.qmp('nbd-server-start', addr={'type': 'unix', 'data': {'path': nbd_sock_path}}))
51 iotests.log(dest_vm.qmp('nbd-server-add', device='drive0', writable=True))
52
53 iotests.log('Starting `drive-mirror` on source...')
54 iotests.log(source_vm.qmp(
55 'drive-mirror',
56 device='drive0',
57 target='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path),
58 sync='full',
59 format='raw', # always raw, the server handles the format
60 mode='existing',
61 job_id='mirror-job0'))
62
63 iotests.log('Waiting for `drive-mirror` to complete...')
64 iotests.log(source_vm.event_wait('BLOCK_JOB_READY'),
65 filters=[iotests.filter_qmp_event,
66 iotests.filter_block_job])
67
68 iotests.log('Starting migration...')
69 capabilities = [{'capability': 'events', 'state': True},
70 {'capability': 'dirty-bitmaps', 'state': True}]
71 source_vm.qmp('migrate-set-capabilities', capabilities=capabilities)
72 dest_vm.qmp('migrate-set-capabilities', capabilities=capabilities)
73 iotests.log(source_vm.qmp('migrate', uri='unix:{0}'.format(migration_sock_path)))
74
75 source_vm.qmp_log('migrate-start-postcopy')
76
77 while True:
78 event1 = source_vm.event_wait('MIGRATION')
79 if event1['data']['status'] in ('postcopy-device', 'postcopy-active'):
80 # This event is racy, it depends do we really do postcopy or bitmap
81 # was migrated during downtime (and no data to migrate in postcopy
82 # phase). So, don't log it.
83 continue
84 iotests.log(event1, filters=[iotests.filter_qmp_event])
85 if event1['data']['status'] in ('completed', 'failed'):
86 iotests.log('Gracefully ending the `drive-mirror` job on source...')
87 iotests.log(source_vm.qmp('block-job-cancel', device='mirror-job0'))
88 break
89
90 while True:
91 event2 = source_vm.event_wait('BLOCK_JOB_COMPLETED')
92 iotests.log(event2, filters=[iotests.filter_qmp_event,
93 iotests.filter_block_job])
94 if event2['event'] == 'BLOCK_JOB_COMPLETED':
95 iotests.log('Stopping the NBD server on destination...')
96 iotests.log(dest_vm.qmp('nbd-server-stop'))
97 break
98
99 iotests.log('Wait for migration completion on target...')
100 migr_events = (('MIGRATION', {'data': {'status': 'completed'}}),
101 ('MIGRATION', {'data': {'status': 'failed'}}))
102 event = dest_vm.events_wait(migr_events)
103 iotests.log(event, filters=[iotests.filter_qmp_event])
104
105 iotests.log('Check bitmaps on source:')
106 iotests.log(source_vm.qmp('query-block')['return'][0]['inserted']['dirty-bitmaps'])
107
108 iotests.log('Check bitmaps on target:')
109 iotests.log(dest_vm.qmp('query-block')['return'][0]['inserted']['dirty-bitmaps'])