Statistics
| Branch: | Revision:

root / tests / qemu-iotests / 056 @ 5d12aa63

History | View | Annotate | Download (3.4 kB)

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