1747051cdSJeff Cody#!/usr/bin/env python 2747051cdSJeff Cody# 3747051cdSJeff Cody# Tests for image block commit. 4747051cdSJeff Cody# 5747051cdSJeff Cody# Copyright (C) 2012 IBM, Corp. 6747051cdSJeff Cody# Copyright (C) 2012 Red Hat, Inc. 7747051cdSJeff Cody# 8747051cdSJeff Cody# This program is free software; you can redistribute it and/or modify 9747051cdSJeff Cody# it under the terms of the GNU General Public License as published by 10747051cdSJeff Cody# the Free Software Foundation; either version 2 of the License, or 11747051cdSJeff Cody# (at your option) any later version. 12747051cdSJeff Cody# 13747051cdSJeff Cody# This program is distributed in the hope that it will be useful, 14747051cdSJeff Cody# but WITHOUT ANY WARRANTY; without even the implied warranty of 15747051cdSJeff Cody# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16747051cdSJeff Cody# GNU General Public License for more details. 17747051cdSJeff Cody# 18747051cdSJeff Cody# You should have received a copy of the GNU General Public License 19747051cdSJeff Cody# along with this program. If not, see <http://www.gnu.org/licenses/>. 20747051cdSJeff Cody# 21747051cdSJeff Cody# Test for live block commit 22747051cdSJeff Cody# Derived from Image Streaming Test 030 23747051cdSJeff Cody 24747051cdSJeff Codyimport time 25747051cdSJeff Codyimport os 26747051cdSJeff Codyimport iotests 27747051cdSJeff Codyfrom iotests import qemu_img, qemu_io 28747051cdSJeff Codyimport struct 296bf0d1f4SJeff Codyimport errno 30747051cdSJeff Cody 31747051cdSJeff Codybacking_img = os.path.join(iotests.test_dir, 'backing.img') 32747051cdSJeff Codymid_img = os.path.join(iotests.test_dir, 'mid.img') 33747051cdSJeff Codytest_img = os.path.join(iotests.test_dir, 'test.img') 34747051cdSJeff Cody 35747051cdSJeff Codyclass ImageCommitTestCase(iotests.QMPTestCase): 36747051cdSJeff Cody '''Abstract base class for image commit test cases''' 37747051cdSJeff Cody 387676e2c5SJeff Cody def wait_for_complete(self, need_ready=False): 394de43470SFam Zheng completed = False 408b9a30caSFam Zheng ready = False 414de43470SFam Zheng while not completed: 424de43470SFam Zheng for event in self.vm.get_qmp_events(wait=True): 434de43470SFam Zheng if event['event'] == 'BLOCK_JOB_COMPLETED': 44bcdce5a7SAlberto Garcia self.assert_qmp_absent(event, 'data/error') 454de43470SFam Zheng self.assert_qmp(event, 'data/type', 'commit') 464de43470SFam Zheng self.assert_qmp(event, 'data/device', 'drive0') 471d3ba15aSMax Reitz self.assert_qmp(event, 'data/offset', event['data']['len']) 488b9a30caSFam Zheng if need_ready: 498b9a30caSFam Zheng self.assertTrue(ready, "Expecting BLOCK_JOB_COMPLETED event") 504de43470SFam Zheng completed = True 514de43470SFam Zheng elif event['event'] == 'BLOCK_JOB_READY': 528b9a30caSFam Zheng ready = True 534de43470SFam Zheng self.assert_qmp(event, 'data/type', 'commit') 544de43470SFam Zheng self.assert_qmp(event, 'data/device', 'drive0') 554de43470SFam Zheng self.vm.qmp('block-job-complete', device='drive0') 564de43470SFam Zheng 57fb0a078fSFam Zheng self.assert_no_active_block_jobs() 584de43470SFam Zheng self.vm.shutdown() 594de43470SFam Zheng 607676e2c5SJeff Cody def run_commit_test(self, top, base, need_ready=False): 617676e2c5SJeff Cody self.assert_no_active_block_jobs() 627676e2c5SJeff Cody result = self.vm.qmp('block-commit', device='drive0', top=top, base=base) 637676e2c5SJeff Cody self.assert_qmp(result, 'return', {}) 647676e2c5SJeff Cody self.wait_for_complete(need_ready) 657676e2c5SJeff Cody 667676e2c5SJeff Cody def run_default_commit_test(self): 677676e2c5SJeff Cody self.assert_no_active_block_jobs() 687676e2c5SJeff Cody result = self.vm.qmp('block-commit', device='drive0') 697676e2c5SJeff Cody self.assert_qmp(result, 'return', {}) 707676e2c5SJeff Cody self.wait_for_complete() 717676e2c5SJeff Cody 72747051cdSJeff Codyclass TestSingleDrive(ImageCommitTestCase): 73c3971b88SKevin Wolf # Need some space after the copied data so that throttling is effective in 74c3971b88SKevin Wolf # tests that use it rather than just completing the job immediately 75c3971b88SKevin Wolf image_len = 2 * 1024 * 1024 76747051cdSJeff Cody test_len = 1 * 1024 * 256 77747051cdSJeff Cody 78747051cdSJeff Cody def setUp(self): 798b9a30caSFam Zheng iotests.create_image(backing_img, self.image_len) 80747051cdSJeff Cody qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) 81747051cdSJeff Cody qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) 8290c9b167SKevin Wolf qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) 8390c9b167SKevin Wolf qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) 84d3c8c674SKevin Wolf self.vm = iotests.VM().add_drive(test_img, "node-name=top,backing.node-name=mid,backing.backing.node-name=base", interface="none") 85f1d5516aSCornelia Huck if iotests.qemu_default_machine == 's390-ccw-virtio': 86f1d5516aSCornelia Huck self.vm.add_device("virtio-scsi-ccw") 87f1d5516aSCornelia Huck else: 88c3971b88SKevin Wolf self.vm.add_device("virtio-scsi-pci") 89f1d5516aSCornelia Huck 90c3971b88SKevin Wolf self.vm.add_device("scsi-hd,id=scsi0,drive=drive0") 91747051cdSJeff Cody self.vm.launch() 92747051cdSJeff Cody 93747051cdSJeff Cody def tearDown(self): 94747051cdSJeff Cody self.vm.shutdown() 95747051cdSJeff Cody os.remove(test_img) 96747051cdSJeff Cody os.remove(mid_img) 97747051cdSJeff Cody os.remove(backing_img) 98747051cdSJeff Cody 99747051cdSJeff Cody def test_commit(self): 1004de43470SFam Zheng self.run_commit_test(mid_img, backing_img) 10190c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) 10290c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) 103747051cdSJeff Cody 104747051cdSJeff Cody def test_device_not_found(self): 105747051cdSJeff Cody result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % mid_img) 106747051cdSJeff Cody self.assert_qmp(result, 'error/class', 'DeviceNotFound') 107747051cdSJeff Cody 108747051cdSJeff Cody def test_top_same_base(self): 109fb0a078fSFam Zheng self.assert_no_active_block_jobs() 110747051cdSJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % backing_img) 111747051cdSJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 112d5208c45SJeff Cody self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % backing_img) 113747051cdSJeff Cody 114747051cdSJeff Cody def test_top_invalid(self): 115fb0a078fSFam Zheng self.assert_no_active_block_jobs() 116747051cdSJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='badfile', base='%s' % backing_img) 117747051cdSJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 118747051cdSJeff Cody self.assert_qmp(result, 'error/desc', 'Top image file badfile not found') 119747051cdSJeff Cody 120747051cdSJeff Cody def test_base_invalid(self): 121fb0a078fSFam Zheng self.assert_no_active_block_jobs() 122747051cdSJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='%s' % mid_img, base='badfile') 123747051cdSJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 124747051cdSJeff Cody self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found') 125747051cdSJeff Cody 126747051cdSJeff Cody def test_top_is_active(self): 1278b9a30caSFam Zheng self.run_commit_test(test_img, backing_img, need_ready=True) 12890c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) 12990c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) 130747051cdSJeff Cody 1317676e2c5SJeff Cody def test_top_is_default_active(self): 1327676e2c5SJeff Cody self.run_default_commit_test() 13390c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) 13490c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) 1357676e2c5SJeff Cody 136747051cdSJeff Cody def test_top_and_base_reversed(self): 137fb0a078fSFam Zheng self.assert_no_active_block_jobs() 138747051cdSJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % mid_img) 139747051cdSJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 140d5208c45SJeff Cody self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img) 141747051cdSJeff Cody 142c3971b88SKevin Wolf # When the job is running on a BB that is automatically deleted on hot 143c3971b88SKevin Wolf # unplug, the job is cancelled when the device disappears 144c3971b88SKevin Wolf def test_hot_unplug(self): 145c3971b88SKevin Wolf if self.image_len == 0: 146c3971b88SKevin Wolf return 147c3971b88SKevin Wolf 148c3971b88SKevin Wolf self.assert_no_active_block_jobs() 149c3971b88SKevin Wolf result = self.vm.qmp('block-commit', device='drive0', top=mid_img, 150c3971b88SKevin Wolf base=backing_img, speed=(self.image_len / 4)) 151c3971b88SKevin Wolf self.assert_qmp(result, 'return', {}) 152c3971b88SKevin Wolf result = self.vm.qmp('device_del', id='scsi0') 153c3971b88SKevin Wolf self.assert_qmp(result, 'return', {}) 154c3971b88SKevin Wolf 155c3971b88SKevin Wolf cancelled = False 156c3971b88SKevin Wolf deleted = False 157c3971b88SKevin Wolf while not cancelled or not deleted: 158c3971b88SKevin Wolf for event in self.vm.get_qmp_events(wait=True): 159c3971b88SKevin Wolf if event['event'] == 'DEVICE_DELETED': 160c3971b88SKevin Wolf self.assert_qmp(event, 'data/device', 'scsi0') 161c3971b88SKevin Wolf deleted = True 162c3971b88SKevin Wolf elif event['event'] == 'BLOCK_JOB_CANCELLED': 163c3971b88SKevin Wolf self.assert_qmp(event, 'data/device', 'drive0') 164c3971b88SKevin Wolf cancelled = True 165*1dac83f1SKevin Wolf elif event['event'] == 'JOB_STATUS_CHANGE': 166*1dac83f1SKevin Wolf self.assert_qmp(event, 'data/id', 'drive0') 167c3971b88SKevin Wolf else: 168c3971b88SKevin Wolf self.fail("Unexpected event %s" % (event['event'])) 169c3971b88SKevin Wolf 170c3971b88SKevin Wolf self.assert_no_active_block_jobs() 171747051cdSJeff Cody 172d3c8c674SKevin Wolf # Tests that the insertion of the commit_top filter node doesn't make a 173d3c8c674SKevin Wolf # difference to query-blockstat 174d3c8c674SKevin Wolf def test_implicit_node(self): 175d3c8c674SKevin Wolf if self.image_len == 0: 176d3c8c674SKevin Wolf return 177d3c8c674SKevin Wolf 178d3c8c674SKevin Wolf self.assert_no_active_block_jobs() 179d3c8c674SKevin Wolf result = self.vm.qmp('block-commit', device='drive0', top=mid_img, 180d3c8c674SKevin Wolf base=backing_img, speed=(self.image_len / 4)) 181d3c8c674SKevin Wolf self.assert_qmp(result, 'return', {}) 182d3c8c674SKevin Wolf 183d3c8c674SKevin Wolf result = self.vm.qmp('query-block') 184d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/inserted/file', test_img) 185d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/inserted/drv', iotests.imgfmt) 186d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/inserted/backing_file', mid_img) 187d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/inserted/backing_file_depth', 2) 188d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/inserted/image/filename', test_img) 189d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/inserted/image/backing-image/filename', mid_img) 190d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/inserted/image/backing-image/backing-image/filename', backing_img) 191d3c8c674SKevin Wolf 192d3c8c674SKevin Wolf result = self.vm.qmp('query-blockstats') 193d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/node-name', 'top') 194d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/backing/node-name', 'mid') 195d3c8c674SKevin Wolf self.assert_qmp(result, 'return[0]/backing/backing/node-name', 'base') 196d3c8c674SKevin Wolf 197d3c8c674SKevin Wolf self.cancel_and_wait() 198d3c8c674SKevin Wolf self.assert_no_active_block_jobs() 199d3c8c674SKevin Wolf 2006bf0d1f4SJeff Codyclass TestRelativePaths(ImageCommitTestCase): 2016bf0d1f4SJeff Cody image_len = 1 * 1024 * 1024 2026bf0d1f4SJeff Cody test_len = 1 * 1024 * 256 2036bf0d1f4SJeff Cody 2046bf0d1f4SJeff Cody dir1 = "dir1" 2056bf0d1f4SJeff Cody dir2 = "dir2/" 2066bf0d1f4SJeff Cody dir3 = "dir2/dir3/" 2076bf0d1f4SJeff Cody 2086bf0d1f4SJeff Cody test_img = os.path.join(iotests.test_dir, dir3, 'test.img') 2096bf0d1f4SJeff Cody mid_img = "../mid.img" 2106bf0d1f4SJeff Cody backing_img = "../dir1/backing.img" 2116bf0d1f4SJeff Cody 2126bf0d1f4SJeff Cody backing_img_abs = os.path.join(iotests.test_dir, dir1, 'backing.img') 2136bf0d1f4SJeff Cody mid_img_abs = os.path.join(iotests.test_dir, dir2, 'mid.img') 2146bf0d1f4SJeff Cody 2156bf0d1f4SJeff Cody def setUp(self): 2166bf0d1f4SJeff Cody try: 2176bf0d1f4SJeff Cody os.mkdir(os.path.join(iotests.test_dir, self.dir1)) 2186bf0d1f4SJeff Cody os.mkdir(os.path.join(iotests.test_dir, self.dir2)) 2196bf0d1f4SJeff Cody os.mkdir(os.path.join(iotests.test_dir, self.dir3)) 2206bf0d1f4SJeff Cody except OSError as exception: 2216bf0d1f4SJeff Cody if exception.errno != errno.EEXIST: 2226bf0d1f4SJeff Cody raise 223915365a9SFam Zheng iotests.create_image(self.backing_img_abs, TestRelativePaths.image_len) 2246bf0d1f4SJeff Cody qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % self.backing_img_abs, self.mid_img_abs) 2256bf0d1f4SJeff Cody qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % self.mid_img_abs, self.test_img) 2266bf0d1f4SJeff Cody qemu_img('rebase', '-u', '-b', self.backing_img, self.mid_img_abs) 2276bf0d1f4SJeff Cody qemu_img('rebase', '-u', '-b', self.mid_img, self.test_img) 22890c9b167SKevin Wolf qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', self.backing_img_abs) 22990c9b167SKevin Wolf qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', self.mid_img_abs) 2306bf0d1f4SJeff Cody self.vm = iotests.VM().add_drive(self.test_img) 2316bf0d1f4SJeff Cody self.vm.launch() 2326bf0d1f4SJeff Cody 2336bf0d1f4SJeff Cody def tearDown(self): 2346bf0d1f4SJeff Cody self.vm.shutdown() 2356bf0d1f4SJeff Cody os.remove(self.test_img) 2366bf0d1f4SJeff Cody os.remove(self.mid_img_abs) 2376bf0d1f4SJeff Cody os.remove(self.backing_img_abs) 2386bf0d1f4SJeff Cody try: 2396bf0d1f4SJeff Cody os.rmdir(os.path.join(iotests.test_dir, self.dir1)) 2406bf0d1f4SJeff Cody os.rmdir(os.path.join(iotests.test_dir, self.dir3)) 2416bf0d1f4SJeff Cody os.rmdir(os.path.join(iotests.test_dir, self.dir2)) 2426bf0d1f4SJeff Cody except OSError as exception: 2436bf0d1f4SJeff Cody if exception.errno != errno.EEXIST and exception.errno != errno.ENOTEMPTY: 2446bf0d1f4SJeff Cody raise 2456bf0d1f4SJeff Cody 2466bf0d1f4SJeff Cody def test_commit(self): 2474de43470SFam Zheng self.run_commit_test(self.mid_img, self.backing_img) 24890c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', self.backing_img_abs).find("verification failed")) 24990c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', self.backing_img_abs).find("verification failed")) 2506bf0d1f4SJeff Cody 2516bf0d1f4SJeff Cody def test_device_not_found(self): 2526bf0d1f4SJeff Cody result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % self.mid_img) 2536bf0d1f4SJeff Cody self.assert_qmp(result, 'error/class', 'DeviceNotFound') 2546bf0d1f4SJeff Cody 2556bf0d1f4SJeff Cody def test_top_same_base(self): 256fb0a078fSFam Zheng self.assert_no_active_block_jobs() 2576bf0d1f4SJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.mid_img, base='%s' % self.mid_img) 2586bf0d1f4SJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 2596bf0d1f4SJeff Cody self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % self.mid_img) 2606bf0d1f4SJeff Cody 2616bf0d1f4SJeff Cody def test_top_invalid(self): 262fb0a078fSFam Zheng self.assert_no_active_block_jobs() 2636bf0d1f4SJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='badfile', base='%s' % self.backing_img) 2646bf0d1f4SJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 2656bf0d1f4SJeff Cody self.assert_qmp(result, 'error/desc', 'Top image file badfile not found') 2666bf0d1f4SJeff Cody 2676bf0d1f4SJeff Cody def test_base_invalid(self): 268fb0a078fSFam Zheng self.assert_no_active_block_jobs() 2696bf0d1f4SJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.mid_img, base='badfile') 2706bf0d1f4SJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 2716bf0d1f4SJeff Cody self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found') 2726bf0d1f4SJeff Cody 2736bf0d1f4SJeff Cody def test_top_is_active(self): 2744de43470SFam Zheng self.run_commit_test(self.test_img, self.backing_img) 27590c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', self.backing_img_abs).find("verification failed")) 27690c9b167SKevin Wolf self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', self.backing_img_abs).find("verification failed")) 2776bf0d1f4SJeff Cody 2786bf0d1f4SJeff Cody def test_top_and_base_reversed(self): 279fb0a078fSFam Zheng self.assert_no_active_block_jobs() 2806bf0d1f4SJeff Cody result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.backing_img, base='%s' % self.mid_img) 2816bf0d1f4SJeff Cody self.assert_qmp(result, 'error/class', 'GenericError') 2826bf0d1f4SJeff Cody self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % self.mid_img) 2836bf0d1f4SJeff Cody 284747051cdSJeff Cody 285747051cdSJeff Codyclass TestSetSpeed(ImageCommitTestCase): 286747051cdSJeff Cody image_len = 80 * 1024 * 1024 # MB 287747051cdSJeff Cody 288747051cdSJeff Cody def setUp(self): 289747051cdSJeff Cody qemu_img('create', backing_img, str(TestSetSpeed.image_len)) 290747051cdSJeff Cody qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) 291747051cdSJeff Cody qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) 29290c9b167SKevin Wolf qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0x1 0 512', test_img) 29390c9b167SKevin Wolf qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) 29451c493c5SMax Reitz self.vm = iotests.VM().add_drive('blkdebug::' + test_img) 295747051cdSJeff Cody self.vm.launch() 296747051cdSJeff Cody 297747051cdSJeff Cody def tearDown(self): 298747051cdSJeff Cody self.vm.shutdown() 299747051cdSJeff Cody os.remove(test_img) 300747051cdSJeff Cody os.remove(mid_img) 301747051cdSJeff Cody os.remove(backing_img) 302747051cdSJeff Cody 303747051cdSJeff Cody def test_set_speed(self): 304fb0a078fSFam Zheng self.assert_no_active_block_jobs() 305747051cdSJeff Cody 306b59b3d57SFam Zheng self.vm.pause_drive('drive0') 307747051cdSJeff Cody result = self.vm.qmp('block-commit', device='drive0', top=mid_img, speed=1024 * 1024) 308747051cdSJeff Cody self.assert_qmp(result, 'return', {}) 309747051cdSJeff Cody 310747051cdSJeff Cody # Ensure the speed we set was accepted 311747051cdSJeff Cody result = self.vm.qmp('query-block-jobs') 312747051cdSJeff Cody self.assert_qmp(result, 'return[0]/device', 'drive0') 313747051cdSJeff Cody self.assert_qmp(result, 'return[0]/speed', 1024 * 1024) 314747051cdSJeff Cody 315b59b3d57SFam Zheng self.cancel_and_wait(resume=True) 316747051cdSJeff Cody 3178b9a30caSFam Zhengclass TestActiveZeroLengthImage(TestSingleDrive): 3188b9a30caSFam Zheng image_len = 0 319747051cdSJeff Cody 320bcdce5a7SAlberto Garciaclass TestReopenOverlay(ImageCommitTestCase): 321bcdce5a7SAlberto Garcia image_len = 1024 * 1024 322bcdce5a7SAlberto Garcia img0 = os.path.join(iotests.test_dir, '0.img') 323bcdce5a7SAlberto Garcia img1 = os.path.join(iotests.test_dir, '1.img') 324bcdce5a7SAlberto Garcia img2 = os.path.join(iotests.test_dir, '2.img') 325bcdce5a7SAlberto Garcia img3 = os.path.join(iotests.test_dir, '3.img') 326bcdce5a7SAlberto Garcia 327bcdce5a7SAlberto Garcia def setUp(self): 328bcdce5a7SAlberto Garcia iotests.create_image(self.img0, self.image_len) 329bcdce5a7SAlberto Garcia qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % self.img0, self.img1) 330bcdce5a7SAlberto Garcia qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % self.img1, self.img2) 331bcdce5a7SAlberto Garcia qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % self.img2, self.img3) 332bcdce5a7SAlberto Garcia qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xab 0 128K', self.img1) 333bcdce5a7SAlberto Garcia self.vm = iotests.VM().add_drive(self.img3) 334bcdce5a7SAlberto Garcia self.vm.launch() 335bcdce5a7SAlberto Garcia 336bcdce5a7SAlberto Garcia def tearDown(self): 337bcdce5a7SAlberto Garcia self.vm.shutdown() 338bcdce5a7SAlberto Garcia os.remove(self.img0) 339bcdce5a7SAlberto Garcia os.remove(self.img1) 340bcdce5a7SAlberto Garcia os.remove(self.img2) 341bcdce5a7SAlberto Garcia os.remove(self.img3) 342bcdce5a7SAlberto Garcia 343bcdce5a7SAlberto Garcia # This tests what happens when the overlay image of the 'top' node 344bcdce5a7SAlberto Garcia # needs to be reopened in read-write mode in order to update the 345bcdce5a7SAlberto Garcia # backing image string. 346bcdce5a7SAlberto Garcia def test_reopen_overlay(self): 347bcdce5a7SAlberto Garcia self.run_commit_test(self.img1, self.img0) 348bcdce5a7SAlberto Garcia 349747051cdSJeff Codyif __name__ == '__main__': 350747051cdSJeff Cody iotests.main(supported_fmts=['qcow2', 'qed']) 351