1*3590cd0fSVladimir Sementsov-Ogievskiy#!/usr/bin/env python 2*3590cd0fSVladimir Sementsov-Ogievskiy# 3*3590cd0fSVladimir Sementsov-Ogievskiy# Test clearing unknown autoclear_features flag by qcow2 after 4*3590cd0fSVladimir Sementsov-Ogievskiy# migration. This test mimics migration to older qemu. 5*3590cd0fSVladimir Sementsov-Ogievskiy# 6*3590cd0fSVladimir Sementsov-Ogievskiy# Copyright (c) 2017 Parallels International GmbH 7*3590cd0fSVladimir Sementsov-Ogievskiy# 8*3590cd0fSVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify 9*3590cd0fSVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by 10*3590cd0fSVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or 11*3590cd0fSVladimir Sementsov-Ogievskiy# (at your option) any later version. 12*3590cd0fSVladimir Sementsov-Ogievskiy# 13*3590cd0fSVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful, 14*3590cd0fSVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*3590cd0fSVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*3590cd0fSVladimir Sementsov-Ogievskiy# GNU General Public License for more details. 17*3590cd0fSVladimir Sementsov-Ogievskiy# 18*3590cd0fSVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License 19*3590cd0fSVladimir Sementsov-Ogievskiy# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*3590cd0fSVladimir Sementsov-Ogievskiy# 21*3590cd0fSVladimir Sementsov-Ogievskiy 22*3590cd0fSVladimir Sementsov-Ogievskiyimport os 23*3590cd0fSVladimir Sementsov-Ogievskiyimport iotests 24*3590cd0fSVladimir Sementsov-Ogievskiyfrom iotests import qemu_img 25*3590cd0fSVladimir Sementsov-Ogievskiy 26*3590cd0fSVladimir Sementsov-Ogievskiydisk = os.path.join(iotests.test_dir, 'disk') 27*3590cd0fSVladimir Sementsov-Ogievskiymigfile = os.path.join(iotests.test_dir, 'migfile') 28*3590cd0fSVladimir Sementsov-Ogievskiy 29*3590cd0fSVladimir Sementsov-Ogievskiyclass TestInvalidateAutoclear(iotests.QMPTestCase): 30*3590cd0fSVladimir Sementsov-Ogievskiy 31*3590cd0fSVladimir Sementsov-Ogievskiy def tearDown(self): 32*3590cd0fSVladimir Sementsov-Ogievskiy self.vm_a.shutdown() 33*3590cd0fSVladimir Sementsov-Ogievskiy self.vm_b.shutdown() 34*3590cd0fSVladimir Sementsov-Ogievskiy os.remove(disk) 35*3590cd0fSVladimir Sementsov-Ogievskiy os.remove(migfile) 36*3590cd0fSVladimir Sementsov-Ogievskiy 37*3590cd0fSVladimir Sementsov-Ogievskiy def setUp(self): 38*3590cd0fSVladimir Sementsov-Ogievskiy qemu_img('create', '-f', iotests.imgfmt, disk, '1M') 39*3590cd0fSVladimir Sementsov-Ogievskiy 40*3590cd0fSVladimir Sementsov-Ogievskiy self.vm_a = iotests.VM(path_suffix='a').add_drive(disk) 41*3590cd0fSVladimir Sementsov-Ogievskiy self.vm_a.launch() 42*3590cd0fSVladimir Sementsov-Ogievskiy 43*3590cd0fSVladimir Sementsov-Ogievskiy self.vm_b = iotests.VM(path_suffix='b').add_drive(disk) 44*3590cd0fSVladimir Sementsov-Ogievskiy self.vm_b.add_incoming("exec: cat '" + migfile + "'") 45*3590cd0fSVladimir Sementsov-Ogievskiy 46*3590cd0fSVladimir Sementsov-Ogievskiy def test_migration(self): 47*3590cd0fSVladimir Sementsov-Ogievskiy result = self.vm_a.qmp('migrate', uri='exec:cat>' + migfile) 48*3590cd0fSVladimir Sementsov-Ogievskiy self.assert_qmp(result, 'return', {}); 49*3590cd0fSVladimir Sementsov-Ogievskiy self.assertNotEqual(self.vm_a.event_wait("STOP"), None) 50*3590cd0fSVladimir Sementsov-Ogievskiy 51*3590cd0fSVladimir Sementsov-Ogievskiy with open(disk, 'r+b') as f: 52*3590cd0fSVladimir Sementsov-Ogievskiy f.seek(88) # first byte of autoclear_features field 53*3590cd0fSVladimir Sementsov-Ogievskiy f.write(b'\xff') 54*3590cd0fSVladimir Sementsov-Ogievskiy 55*3590cd0fSVladimir Sementsov-Ogievskiy self.vm_b.launch() 56*3590cd0fSVladimir Sementsov-Ogievskiy while True: 57*3590cd0fSVladimir Sementsov-Ogievskiy result = self.vm_b.qmp('query-status') 58*3590cd0fSVladimir Sementsov-Ogievskiy if result['return']['status'] == 'running': 59*3590cd0fSVladimir Sementsov-Ogievskiy break 60*3590cd0fSVladimir Sementsov-Ogievskiy 61*3590cd0fSVladimir Sementsov-Ogievskiy with open(disk, 'rb') as f: 62*3590cd0fSVladimir Sementsov-Ogievskiy f.seek(88) 63*3590cd0fSVladimir Sementsov-Ogievskiy self.assertEqual(f.read(1), b'\x00') 64*3590cd0fSVladimir Sementsov-Ogievskiy 65*3590cd0fSVladimir Sementsov-Ogievskiyif __name__ == '__main__': 66*3590cd0fSVladimir Sementsov-Ogievskiy iotests.main(supported_fmts=['qcow2']) 67