3
# Tests for drive-backup
5
# Copyright (C) 2013 Red Hat, Inc.
9
# This program is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
26
from iotests import qemu_img, qemu_io, create_image
28
backing_img = os.path.join(iotests.test_dir, 'backing.img')
29
test_img = os.path.join(iotests.test_dir, 'test.img')
30
target_img = os.path.join(iotests.test_dir, 'target.img')
32
class TestSyncModesNoneAndTop(iotests.QMPTestCase):
33
image_len = 64 * 1024 * 1024 # MB
36
create_image(backing_img, TestSyncModesNoneAndTop.image_len)
37
qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img)
38
qemu_io('-c', 'write -P0x41 0 512', test_img)
39
qemu_io('-c', 'write -P0xd5 1M 32k', test_img)
40
qemu_io('-c', 'write -P0xdc 32M 124k', test_img)
41
qemu_io('-c', 'write -P0xdc 67043328 64k', test_img)
42
self.vm = iotests.VM().add_drive(test_img)
48
os.remove(backing_img)
54
def test_complete_top(self):
55
self.assert_no_active_block_jobs()
56
result = self.vm.qmp('drive-backup', device='drive0', sync='top',
57
format=iotests.imgfmt, target=target_img)
58
self.assert_qmp(result, 'return', {})
60
# Custom completed check as we are not copying all data.
63
for event in self.vm.get_qmp_events(wait=True):
64
if event['event'] == 'BLOCK_JOB_COMPLETED':
65
self.assert_qmp(event, 'data/device', 'drive0')
66
self.assert_qmp_absent(event, 'data/error')
69
self.assert_no_active_block_jobs()
71
self.assertTrue(iotests.compare_images(test_img, target_img),
72
'target image does not match source after backup')
74
def test_cancel_sync_none(self):
75
self.assert_no_active_block_jobs()
77
result = self.vm.qmp('drive-backup', device='drive0',
78
sync='none', target=target_img)
79
self.assert_qmp(result, 'return', {})
81
self.vm.hmp_qemu_io('drive0', 'write -P0x5e 0 512')
82
self.vm.hmp_qemu_io('drive0', 'aio_flush')
83
# Verify that the original contents exist in the target image.
85
event = self.cancel_and_wait()
86
self.assert_qmp(event, 'data/type', 'backup')
90
self.assertEqual(-1, qemu_io('-c', 'read -P0x41 0 512', target_img).find("verification failed"))
93
if __name__ == '__main__':
94
iotests.main(supported_fmts=['qcow2', 'qed'])