Philippe Mathieu-Daudé | 7c47752 | 2020-01-30 17:32:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw migration quick |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 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 | |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 23 | import iotests |
| 24 | |
John Snow | 7d81405 | 2020-03-30 20:00:11 -0400 | [diff] [blame] | 25 | iotests.script_initialize(supported_fmts=['qcow2', 'qed', 'raw'], |
| 26 | supported_platforms=['linux']) |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 27 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 28 | with iotests.FilePath('source.img') as source_img_path, \ |
| 29 | iotests.FilePath('dest.img') as dest_img_path, \ |
Nir Soffer | 3192fad | 2020-08-29 02:21:51 +0300 | [diff] [blame] | 30 | iotests.FilePath('migration.sock', 'nbd.sock', base_dir=iotests.sock_dir) \ |
Nir Soffer | a242b19 | 2020-08-29 02:21:50 +0300 | [diff] [blame] | 31 | as (migration_sock_path, nbd_sock_path), \ |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 32 | iotests.VM('source') as source_vm, \ |
| 33 | iotests.VM('dest') as dest_vm: |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 34 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 35 | img_size = '1G' |
John Snow | 3d53818 | 2022-03-21 16:16:12 -0400 | [diff] [blame] | 36 | iotests.qemu_img_create('-f', iotests.imgfmt, source_img_path, img_size) |
| 37 | iotests.qemu_img_create('-f', iotests.imgfmt, dest_img_path, img_size) |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 38 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 39 | iotests.log('Launching VMs...') |
| 40 | (source_vm.add_drive(source_img_path) |
| 41 | .launch()) |
| 42 | (dest_vm.add_drive(dest_img_path) |
| 43 | .add_incoming('unix:{0}'.format(migration_sock_path)) |
| 44 | .launch()) |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 45 | |
Vladimir Sementsov-Ogievskiy | ae00aa2 | 2020-05-22 01:06:46 +0300 | [diff] [blame] | 46 | source_vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0') |
| 47 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 48 | iotests.log('Launching NBD server on destination...') |
| 49 | iotests.log(dest_vm.qmp('nbd-server-start', addr={'type': 'unix', 'data': {'path': nbd_sock_path}})) |
| 50 | iotests.log(dest_vm.qmp('nbd-server-add', device='drive0', writable=True)) |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 51 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 52 | iotests.log('Starting `drive-mirror` on source...') |
| 53 | iotests.log(source_vm.qmp( |
| 54 | 'drive-mirror', |
| 55 | device='drive0', |
| 56 | target='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path), |
| 57 | sync='full', |
| 58 | format='raw', # always raw, the server handles the format |
| 59 | mode='existing', |
| 60 | job_id='mirror-job0')) |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 61 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 62 | iotests.log('Waiting for `drive-mirror` to complete...') |
| 63 | iotests.log(source_vm.event_wait('BLOCK_JOB_READY'), |
| 64 | filters=[iotests.filter_qmp_event]) |
Stefan Hajnoczi | 12314f2 | 2017-08-23 15:05:06 +0100 | [diff] [blame] | 65 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 66 | iotests.log('Starting migration...') |
Vladimir Sementsov-Ogievskiy | ae00aa2 | 2020-05-22 01:06:46 +0300 | [diff] [blame] | 67 | capabilities = [{'capability': 'events', 'state': True}, |
| 68 | {'capability': 'dirty-bitmaps', 'state': True}] |
| 69 | source_vm.qmp('migrate-set-capabilities', capabilities=capabilities) |
| 70 | dest_vm.qmp('migrate-set-capabilities', capabilities=capabilities) |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 71 | iotests.log(source_vm.qmp('migrate', uri='unix:{0}'.format(migration_sock_path))) |
Kashyap Chamarthy | 2c94e27 | 2017-08-29 18:50:58 +0200 | [diff] [blame] | 72 | |
Vladimir Sementsov-Ogievskiy | ae00aa2 | 2020-05-22 01:06:46 +0300 | [diff] [blame] | 73 | source_vm.qmp_log('migrate-start-postcopy') |
| 74 | |
Stefan Hajnoczi | 921a321 | 2017-08-24 08:22:02 +0100 | [diff] [blame] | 75 | while True: |
| 76 | event1 = source_vm.event_wait('MIGRATION') |
| 77 | iotests.log(event1, filters=[iotests.filter_qmp_event]) |
| 78 | if event1['data']['status'] in ('completed', 'failed'): |
| 79 | iotests.log('Gracefully ending the `drive-mirror` job on source...') |
| 80 | iotests.log(source_vm.qmp('block-job-cancel', device='mirror-job0')) |
| 81 | break |
| 82 | |
| 83 | while True: |
| 84 | event2 = source_vm.event_wait('BLOCK_JOB_COMPLETED') |
| 85 | iotests.log(event2, filters=[iotests.filter_qmp_event]) |
| 86 | if event2['event'] == 'BLOCK_JOB_COMPLETED': |
| 87 | iotests.log('Stopping the NBD server on destination...') |
| 88 | iotests.log(dest_vm.qmp('nbd-server-stop')) |
| 89 | break |
Vladimir Sementsov-Ogievskiy | ae00aa2 | 2020-05-22 01:06:46 +0300 | [diff] [blame] | 90 | |
Vladimir Sementsov-Ogievskiy | 93d4878 | 2020-06-04 11:33:41 +0300 | [diff] [blame] | 91 | iotests.log('Wait for migration completion on target...') |
| 92 | migr_events = (('MIGRATION', {'data': {'status': 'completed'}}), |
| 93 | ('MIGRATION', {'data': {'status': 'failed'}})) |
| 94 | event = dest_vm.events_wait(migr_events) |
| 95 | iotests.log(event, filters=[iotests.filter_qmp_event]) |
| 96 | |
| 97 | iotests.log('Check bitmaps on source:') |
Daniel P. Berrangé | e67d8e2 | 2021-02-19 19:22:36 +0000 | [diff] [blame] | 98 | iotests.log(source_vm.qmp('query-block')['return'][0]['inserted']['dirty-bitmaps']) |
Vladimir Sementsov-Ogievskiy | 93d4878 | 2020-06-04 11:33:41 +0300 | [diff] [blame] | 99 | |
| 100 | iotests.log('Check bitmaps on target:') |
Daniel P. Berrangé | e67d8e2 | 2021-02-19 19:22:36 +0000 | [diff] [blame] | 101 | iotests.log(dest_vm.qmp('query-block')['return'][0]['inserted']['dirty-bitmaps']) |