xref: /qemu/tests/qemu-iotests/196 (revision 103cbc771e5660d1f5bb458be80aa9e363547ae0)
13590cd0fSVladimir Sementsov-Ogievskiy#!/usr/bin/env python
23590cd0fSVladimir Sementsov-Ogievskiy#
33590cd0fSVladimir Sementsov-Ogievskiy# Test clearing unknown autoclear_features flag by qcow2 after
43590cd0fSVladimir Sementsov-Ogievskiy# migration. This test mimics migration to older qemu.
53590cd0fSVladimir Sementsov-Ogievskiy#
63590cd0fSVladimir Sementsov-Ogievskiy# Copyright (c) 2017 Parallels International GmbH
73590cd0fSVladimir Sementsov-Ogievskiy#
83590cd0fSVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify
93590cd0fSVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by
103590cd0fSVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or
113590cd0fSVladimir Sementsov-Ogievskiy# (at your option) any later version.
123590cd0fSVladimir Sementsov-Ogievskiy#
133590cd0fSVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful,
143590cd0fSVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of
153590cd0fSVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
163590cd0fSVladimir Sementsov-Ogievskiy# GNU General Public License for more details.
173590cd0fSVladimir Sementsov-Ogievskiy#
183590cd0fSVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License
193590cd0fSVladimir Sementsov-Ogievskiy# along with this program.  If not, see <http://www.gnu.org/licenses/>.
203590cd0fSVladimir Sementsov-Ogievskiy#
213590cd0fSVladimir Sementsov-Ogievskiy
223590cd0fSVladimir Sementsov-Ogievskiyimport os
233590cd0fSVladimir Sementsov-Ogievskiyimport iotests
243590cd0fSVladimir Sementsov-Ogievskiyfrom iotests import qemu_img
253590cd0fSVladimir Sementsov-Ogievskiy
263590cd0fSVladimir Sementsov-Ogievskiydisk = os.path.join(iotests.test_dir, 'disk')
273590cd0fSVladimir Sementsov-Ogievskiymigfile = os.path.join(iotests.test_dir, 'migfile')
283590cd0fSVladimir Sementsov-Ogievskiy
293590cd0fSVladimir Sementsov-Ogievskiyclass TestInvalidateAutoclear(iotests.QMPTestCase):
303590cd0fSVladimir Sementsov-Ogievskiy
313590cd0fSVladimir Sementsov-Ogievskiy    def tearDown(self):
323590cd0fSVladimir Sementsov-Ogievskiy        self.vm_a.shutdown()
333590cd0fSVladimir Sementsov-Ogievskiy        self.vm_b.shutdown()
343590cd0fSVladimir Sementsov-Ogievskiy        os.remove(disk)
353590cd0fSVladimir Sementsov-Ogievskiy        os.remove(migfile)
363590cd0fSVladimir Sementsov-Ogievskiy
373590cd0fSVladimir Sementsov-Ogievskiy    def setUp(self):
383590cd0fSVladimir Sementsov-Ogievskiy        qemu_img('create', '-f', iotests.imgfmt, disk, '1M')
393590cd0fSVladimir Sementsov-Ogievskiy
403590cd0fSVladimir Sementsov-Ogievskiy        self.vm_a = iotests.VM(path_suffix='a').add_drive(disk)
413590cd0fSVladimir Sementsov-Ogievskiy        self.vm_a.launch()
423590cd0fSVladimir Sementsov-Ogievskiy
433590cd0fSVladimir Sementsov-Ogievskiy        self.vm_b = iotests.VM(path_suffix='b').add_drive(disk)
443590cd0fSVladimir Sementsov-Ogievskiy        self.vm_b.add_incoming("exec: cat '" + migfile + "'")
453590cd0fSVladimir Sementsov-Ogievskiy
463590cd0fSVladimir Sementsov-Ogievskiy    def test_migration(self):
473590cd0fSVladimir Sementsov-Ogievskiy        result = self.vm_a.qmp('migrate', uri='exec:cat>' + migfile)
483590cd0fSVladimir Sementsov-Ogievskiy        self.assert_qmp(result, 'return', {});
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__':
66*103cbc77SMax Reitz    iotests.main(supported_fmts=['qcow2'],
67*103cbc77SMax Reitz                 supported_protocols=['file'])
68