scripts: kernel-doc: allow passing desired Sphinx C domain dialect
[qemu/ar7.git] / tests / qemu-iotests / 222
blob14d67c875bd881b628b7c2bbbecc7ab55fbf6023
1 #!/usr/bin/env python3
3 # This test covers the basic fleecing workflow, which provides a
4 # point-in-time snapshot of a node that can be queried over NBD.
6 # Copyright (C) 2018 Red Hat, Inc.
7 # John helped, too.
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/>.
22 # Creator/Owner: John Snow <jsnow@redhat.com>
24 import iotests
25 from iotests import log, qemu_img, qemu_io, qemu_io_silent
27 iotests.script_initialize(
28     supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk', 'vhdx', 'raw'],
29     supported_platforms=['linux'],
32 patterns = [("0x5d", "0",         "64k"),
33             ("0xd5", "1M",        "64k"),
34             ("0xdc", "32M",       "64k"),
35             ("0xcd", "0x3ff0000", "64k")]  # 64M - 64K
37 overwrite = [("0xab", "0",         "64k"), # Full overwrite
38              ("0xad", "0x00f8000", "64k"), # Partial-left (1M-32K)
39              ("0x1d", "0x2008000", "64k"), # Partial-right (32M+32K)
40              ("0xea", "0x3fe0000", "64k")] # Adjacent-left (64M - 128K)
42 zeroes = [("0", "0x00f8000", "32k"), # Left-end of partial-left (1M-32K)
43           ("0", "0x2010000", "32k"), # Right-end of partial-right (32M+64K)
44           ("0", "0x3fe0000", "64k")] # overwrite[3]
46 remainder = [("0xd5", "0x108000",  "32k"), # Right-end of partial-left [1]
47              ("0xdc", "32M",       "32k"), # Left-end of partial-right [2]
48              ("0xcd", "0x3ff0000", "64k")] # patterns[3]
50 with iotests.FilePath('base.img') as base_img_path, \
51      iotests.FilePath('fleece.img') as fleece_img_path, \
52      iotests.FilePath('nbd.sock', base_dir=iotests.sock_dir) as nbd_sock_path, \
53      iotests.VM() as vm:
55     log('--- Setting up images ---')
56     log('')
58     assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
59     assert qemu_img('create', '-f', "qcow2", fleece_img_path, '64M') == 0
61     for p in patterns:
62         qemu_io('-f', iotests.imgfmt,
63                 '-c', 'write -P%s %s %s' % p, base_img_path)
65     log('Done')
67     log('')
68     log('--- Launching VM ---')
69     log('')
71     vm.add_drive(base_img_path)
72     vm.launch()
73     log('Done')
75     log('')
76     log('--- Setting up Fleecing Graph ---')
77     log('')
79     src_node = "drive0"
80     tgt_node = "fleeceNode"
82     # create tgt_node backed by src_node
83     log(vm.qmp("blockdev-add", **{
84         "driver": "qcow2",
85         "node-name": tgt_node,
86         "file": {
87             "driver": "file",
88             "filename": fleece_img_path,
89         },
90         "backing": src_node,
91     }))
93     # Establish COW from source to fleecing node
94     log(vm.qmp("blockdev-backup",
95                device=src_node,
96                target=tgt_node,
97                sync="none"))
99     log('')
100     log('--- Setting up NBD Export ---')
101     log('')
103     nbd_uri = 'nbd+unix:///%s?socket=%s' % (tgt_node, nbd_sock_path)
104     log(vm.qmp("nbd-server-start",
105                **{"addr": { "type": "unix",
106                             "data": { "path": nbd_sock_path } } }))
108     log(vm.qmp("nbd-server-add", device=tgt_node))
110     log('')
111     log('--- Sanity Check ---')
112     log('')
114     for p in (patterns + zeroes):
115         cmd = "read -P%s %s %s" % p
116         log(cmd)
117         assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0
119     log('')
120     log('--- Testing COW ---')
121     log('')
123     for p in overwrite:
124         cmd = "write -P%s %s %s" % p
125         log(cmd)
126         log(vm.hmp_qemu_io(src_node, cmd))
128     log('')
129     log('--- Verifying Data ---')
130     log('')
132     for p in (patterns + zeroes):
133         cmd = "read -P%s %s %s" % p
134         log(cmd)
135         assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0
137     log('')
138     log('--- Cleanup ---')
139     log('')
141     log(vm.qmp('block-job-cancel', device=src_node))
142     log(vm.event_wait('BLOCK_JOB_CANCELLED'),
143         filters=[iotests.filter_qmp_event])
144     log(vm.qmp('nbd-server-stop'))
145     log(vm.qmp('blockdev-del', node_name=tgt_node))
146     vm.shutdown()
148     log('')
149     log('--- Confirming writes ---')
150     log('')
152     for p in (overwrite + remainder):
153         cmd = "read -P%s %s %s" % p
154         log(cmd)
155         assert qemu_io_silent(base_img_path, '-c', cmd) == 0
157     log('')
158     log('Done')