xref: /openbmc/qemu/tests/qemu-iotests/196 (revision b6aed193)
1903cb1bfSPhilippe Mathieu-Daudé#!/usr/bin/env python3
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick migration
33590cd0fSVladimir Sementsov-Ogievskiy#
43590cd0fSVladimir Sementsov-Ogievskiy# Test clearing unknown autoclear_features flag by qcow2 after
53590cd0fSVladimir Sementsov-Ogievskiy# migration. This test mimics migration to older qemu.
63590cd0fSVladimir Sementsov-Ogievskiy#
73590cd0fSVladimir Sementsov-Ogievskiy# Copyright (c) 2017 Parallels International GmbH
83590cd0fSVladimir Sementsov-Ogievskiy#
93590cd0fSVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify
103590cd0fSVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by
113590cd0fSVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or
123590cd0fSVladimir Sementsov-Ogievskiy# (at your option) any later version.
133590cd0fSVladimir Sementsov-Ogievskiy#
143590cd0fSVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful,
153590cd0fSVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of
163590cd0fSVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
173590cd0fSVladimir Sementsov-Ogievskiy# GNU General Public License for more details.
183590cd0fSVladimir Sementsov-Ogievskiy#
193590cd0fSVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License
203590cd0fSVladimir Sementsov-Ogievskiy# along with this program.  If not, see <http://www.gnu.org/licenses/>.
213590cd0fSVladimir Sementsov-Ogievskiy#
223590cd0fSVladimir Sementsov-Ogievskiy
233590cd0fSVladimir Sementsov-Ogievskiyimport os
243590cd0fSVladimir Sementsov-Ogievskiyimport iotests
253590cd0fSVladimir Sementsov-Ogievskiyfrom iotests import qemu_img
263590cd0fSVladimir Sementsov-Ogievskiy
273590cd0fSVladimir Sementsov-Ogievskiydisk = os.path.join(iotests.test_dir, 'disk')
283590cd0fSVladimir Sementsov-Ogievskiymigfile = os.path.join(iotests.test_dir, 'migfile')
293590cd0fSVladimir Sementsov-Ogievskiy
303590cd0fSVladimir Sementsov-Ogievskiyclass TestInvalidateAutoclear(iotests.QMPTestCase):
313590cd0fSVladimir Sementsov-Ogievskiy
323590cd0fSVladimir Sementsov-Ogievskiy    def tearDown(self):
333590cd0fSVladimir Sementsov-Ogievskiy        self.vm_a.shutdown()
343590cd0fSVladimir Sementsov-Ogievskiy        self.vm_b.shutdown()
353590cd0fSVladimir Sementsov-Ogievskiy        os.remove(disk)
363590cd0fSVladimir Sementsov-Ogievskiy        os.remove(migfile)
373590cd0fSVladimir Sementsov-Ogievskiy
383590cd0fSVladimir Sementsov-Ogievskiy    def setUp(self):
393590cd0fSVladimir Sementsov-Ogievskiy        qemu_img('create', '-f', iotests.imgfmt, disk, '1M')
403590cd0fSVladimir Sementsov-Ogievskiy
413590cd0fSVladimir Sementsov-Ogievskiy        self.vm_a = iotests.VM(path_suffix='a').add_drive(disk)
423590cd0fSVladimir Sementsov-Ogievskiy        self.vm_a.launch()
433590cd0fSVladimir Sementsov-Ogievskiy
443590cd0fSVladimir Sementsov-Ogievskiy        self.vm_b = iotests.VM(path_suffix='b').add_drive(disk)
453590cd0fSVladimir Sementsov-Ogievskiy        self.vm_b.add_incoming("exec: cat '" + migfile + "'")
463590cd0fSVladimir Sementsov-Ogievskiy
473590cd0fSVladimir Sementsov-Ogievskiy    def test_migration(self):
48*b6aed193SVladimir Sementsov-Ogievskiy        self.vm_a.cmd('migrate', uri='exec:cat>' + migfile)
493590cd0fSVladimir Sementsov-Ogievskiy        self.assertNotEqual(self.vm_a.event_wait("STOP"), None)
503590cd0fSVladimir Sementsov-Ogievskiy
513590cd0fSVladimir Sementsov-Ogievskiy        with open(disk, 'r+b') as f:
523590cd0fSVladimir Sementsov-Ogievskiy            f.seek(88) # first byte of autoclear_features field
533590cd0fSVladimir Sementsov-Ogievskiy            f.write(b'\xff')
543590cd0fSVladimir Sementsov-Ogievskiy
553590cd0fSVladimir Sementsov-Ogievskiy        self.vm_b.launch()
563590cd0fSVladimir Sementsov-Ogievskiy        while True:
573590cd0fSVladimir Sementsov-Ogievskiy            result = self.vm_b.qmp('query-status')
583590cd0fSVladimir Sementsov-Ogievskiy            if result['return']['status'] == 'running':
593590cd0fSVladimir Sementsov-Ogievskiy                break
603590cd0fSVladimir Sementsov-Ogievskiy
613590cd0fSVladimir Sementsov-Ogievskiy        with open(disk, 'rb') as f:
623590cd0fSVladimir Sementsov-Ogievskiy            f.seek(88)
633590cd0fSVladimir Sementsov-Ogievskiy            self.assertEqual(f.read(1), b'\x00')
643590cd0fSVladimir Sementsov-Ogievskiy
653590cd0fSVladimir Sementsov-Ogievskiyif __name__ == '__main__':
66103cbc77SMax Reitz    iotests.main(supported_fmts=['qcow2'],
67b30b8077SVladimir Sementsov-Ogievskiy                 supported_protocols=['file'],
68b30b8077SVladimir Sementsov-Ogievskiy                 unsupported_imgopts=['compat'])
69