xref: /openbmc/qemu/tests/qemu-iotests/194 (revision dcc28ab6)
17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw migration quick
312314f2dSStefan Hajnoczi#
412314f2dSStefan Hajnoczi# Copyright (C) 2017 Red Hat, Inc.
512314f2dSStefan Hajnoczi#
612314f2dSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
712314f2dSStefan Hajnoczi# it under the terms of the GNU General Public License as published by
812314f2dSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
912314f2dSStefan Hajnoczi# (at your option) any later version.
1012314f2dSStefan Hajnoczi#
1112314f2dSStefan Hajnoczi# This program is distributed in the hope that it will be useful,
1212314f2dSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
1312314f2dSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1412314f2dSStefan Hajnoczi# GNU General Public License for more details.
1512314f2dSStefan Hajnoczi#
1612314f2dSStefan Hajnoczi# You should have received a copy of the GNU General Public License
1712314f2dSStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1812314f2dSStefan Hajnoczi#
1912314f2dSStefan Hajnoczi# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com>
2012314f2dSStefan Hajnoczi#
2112314f2dSStefan Hajnoczi# Non-shared storage migration test using NBD server and drive-mirror
2212314f2dSStefan Hajnoczi
2312314f2dSStefan Hajnocziimport iotests
2412314f2dSStefan Hajnoczi
257d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2', 'qed', 'raw'],
267d814059SJohn Snow                          supported_platforms=['linux'])
2712314f2dSStefan Hajnoczi
28921a3217SStefan Hajnocziwith iotests.FilePath('source.img') as source_img_path, \
29921a3217SStefan Hajnoczi     iotests.FilePath('dest.img') as dest_img_path, \
303192fad7SNir Soffer     iotests.FilePath('migration.sock', 'nbd.sock', base_dir=iotests.sock_dir) \
31a242b19eSNir Soffer        as (migration_sock_path, nbd_sock_path), \
32921a3217SStefan Hajnoczi     iotests.VM('source') as source_vm, \
33921a3217SStefan Hajnoczi     iotests.VM('dest') as dest_vm:
34921a3217SStefan Hajnoczi
3512314f2dSStefan Hajnoczi    img_size = '1G'
363d53818fSJohn Snow    iotests.qemu_img_create('-f', iotests.imgfmt, source_img_path, img_size)
373d53818fSJohn Snow    iotests.qemu_img_create('-f', iotests.imgfmt, dest_img_path, img_size)
3812314f2dSStefan Hajnoczi
3912314f2dSStefan Hajnoczi    iotests.log('Launching VMs...')
40921a3217SStefan Hajnoczi    (source_vm.add_drive(source_img_path)
41921a3217SStefan Hajnoczi              .launch())
42921a3217SStefan Hajnoczi    (dest_vm.add_drive(dest_img_path)
43921a3217SStefan Hajnoczi            .add_incoming('unix:{0}'.format(migration_sock_path))
44921a3217SStefan Hajnoczi            .launch())
4512314f2dSStefan Hajnoczi
46ae00aa23SVladimir Sementsov-Ogievskiy    source_vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0')
47ae00aa23SVladimir Sementsov-Ogievskiy
4812314f2dSStefan Hajnoczi    iotests.log('Launching NBD server on destination...')
4912314f2dSStefan Hajnoczi    iotests.log(dest_vm.qmp('nbd-server-start', addr={'type': 'unix', 'data': {'path': nbd_sock_path}}))
5012314f2dSStefan Hajnoczi    iotests.log(dest_vm.qmp('nbd-server-add', device='drive0', writable=True))
5112314f2dSStefan Hajnoczi
522c94e271SKashyap Chamarthy    iotests.log('Starting `drive-mirror` on source...')
5312314f2dSStefan Hajnoczi    iotests.log(source_vm.qmp(
5412314f2dSStefan Hajnoczi                  'drive-mirror',
5512314f2dSStefan Hajnoczi                  device='drive0',
5612314f2dSStefan Hajnoczi                  target='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path),
5712314f2dSStefan Hajnoczi                  sync='full',
5812314f2dSStefan Hajnoczi                  format='raw', # always raw, the server handles the format
592c94e271SKashyap Chamarthy                  mode='existing',
602c94e271SKashyap Chamarthy                  job_id='mirror-job0'))
6112314f2dSStefan Hajnoczi
622c94e271SKashyap Chamarthy    iotests.log('Waiting for `drive-mirror` to complete...')
6312314f2dSStefan Hajnoczi    iotests.log(source_vm.event_wait('BLOCK_JOB_READY'),
6412314f2dSStefan Hajnoczi                filters=[iotests.filter_qmp_event])
6512314f2dSStefan Hajnoczi
6612314f2dSStefan Hajnoczi    iotests.log('Starting migration...')
67ae00aa23SVladimir Sementsov-Ogievskiy    capabilities = [{'capability': 'events', 'state': True},
68ae00aa23SVladimir Sementsov-Ogievskiy                    {'capability': 'dirty-bitmaps', 'state': True}]
69ae00aa23SVladimir Sementsov-Ogievskiy    source_vm.qmp('migrate-set-capabilities', capabilities=capabilities)
70ae00aa23SVladimir Sementsov-Ogievskiy    dest_vm.qmp('migrate-set-capabilities', capabilities=capabilities)
7112314f2dSStefan Hajnoczi    iotests.log(source_vm.qmp('migrate', uri='unix:{0}'.format(migration_sock_path)))
7212314f2dSStefan Hajnoczi
73ae00aa23SVladimir Sementsov-Ogievskiy    source_vm.qmp_log('migrate-start-postcopy')
74ae00aa23SVladimir Sementsov-Ogievskiy
7512314f2dSStefan Hajnoczi    while True:
762c94e271SKashyap Chamarthy        event1 = source_vm.event_wait('MIGRATION')
77*dcc28ab6SVladimir Sementsov-Ogievskiy        if event1['data']['status'] == 'postcopy-active':
78*dcc28ab6SVladimir Sementsov-Ogievskiy            # This event is racy, it depends do we really do postcopy or bitmap
79*dcc28ab6SVladimir Sementsov-Ogievskiy            # was migrated during downtime (and no data to migrate in postcopy
80*dcc28ab6SVladimir Sementsov-Ogievskiy            # phase). So, don't log it.
81*dcc28ab6SVladimir Sementsov-Ogievskiy            continue
822c94e271SKashyap Chamarthy        iotests.log(event1, filters=[iotests.filter_qmp_event])
832c94e271SKashyap Chamarthy        if event1['data']['status'] in ('completed', 'failed'):
842c94e271SKashyap Chamarthy            iotests.log('Gracefully ending the `drive-mirror` job on source...')
852c94e271SKashyap Chamarthy            iotests.log(source_vm.qmp('block-job-cancel', device='mirror-job0'))
862c94e271SKashyap Chamarthy            break
872c94e271SKashyap Chamarthy
882c94e271SKashyap Chamarthy    while True:
892c94e271SKashyap Chamarthy        event2 = source_vm.event_wait('BLOCK_JOB_COMPLETED')
902c94e271SKashyap Chamarthy        iotests.log(event2, filters=[iotests.filter_qmp_event])
912c94e271SKashyap Chamarthy        if event2['event'] == 'BLOCK_JOB_COMPLETED':
922c94e271SKashyap Chamarthy            iotests.log('Stopping the NBD server on destination...')
932c94e271SKashyap Chamarthy            iotests.log(dest_vm.qmp('nbd-server-stop'))
9412314f2dSStefan Hajnoczi            break
95ae00aa23SVladimir Sementsov-Ogievskiy
9693d48780SVladimir Sementsov-Ogievskiy    iotests.log('Wait for migration completion on target...')
9793d48780SVladimir Sementsov-Ogievskiy    migr_events = (('MIGRATION', {'data': {'status': 'completed'}}),
9893d48780SVladimir Sementsov-Ogievskiy                   ('MIGRATION', {'data': {'status': 'failed'}}))
9993d48780SVladimir Sementsov-Ogievskiy    event = dest_vm.events_wait(migr_events)
10093d48780SVladimir Sementsov-Ogievskiy    iotests.log(event, filters=[iotests.filter_qmp_event])
10193d48780SVladimir Sementsov-Ogievskiy
10293d48780SVladimir Sementsov-Ogievskiy    iotests.log('Check bitmaps on source:')
103e67d8e29SDaniel P. Berrangé    iotests.log(source_vm.qmp('query-block')['return'][0]['inserted']['dirty-bitmaps'])
10493d48780SVladimir Sementsov-Ogievskiy
10593d48780SVladimir Sementsov-Ogievskiy    iotests.log('Check bitmaps on target:')
106e67d8e29SDaniel P. Berrangé    iotests.log(dest_vm.qmp('query-block')['return'][0]['inserted']['dirty-bitmaps'])
107