master
text 182 lines 5.09 KB
Raw
1 #!/usr/bin/env bash
2 # group: rw auto quick
3 #
4 # Tests oVirt-like storage migration:
5 # - Create snapshot
6 # - Create target image with (not yet existing) target backing chain
7 # (i.e. just write the name of a soon-to-be-copied-over backing file into it)
8 # - drive-mirror the snapshot to the target with mode=existing and sync=top
9 # - In the meantime, copy the original source files to the destination via
10 # conventional means (i.e. outside of qemu)
11 # - Complete the drive-mirror job
12 # - Delete all source images
13 #
14 # Copyright (C) 2016 Red Hat, Inc.
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #
29
30 # creator
31 owner=hreitz@redhat.com
32
33 seq="$(basename $0)"
34 echo "QA output created by $seq"
35
36 status=1 # failure is the default!
37
38 _cleanup()
39 {
40 _cleanup_qemu
41 for img in "$TEST_IMG"{,.target}{,.backing,.overlay}; do
42 _rm_test_img "$img"
43 done
44 }
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 # get standard environment, filters and checks
48 . ./common.rc
49 . ./common.filter
50 . ./common.qemu
51
52 _supported_fmt qcow2 qed
53 _supported_proto file
54 # Copying files around with cp does not work with external data files
55 _unsupported_imgopts data_file
56 _require_hmp
57
58 # Create source disk
59 TEST_IMG="$TEST_IMG.backing" _make_test_img 1M
60 _make_test_img -b "$TEST_IMG.backing" -F $IMGFMT 1M
61
62 $QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io
63 $QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io
64
65 _launch_qemu -drive if=none,id=source,file="$TEST_IMG"
66
67 _send_qemu_cmd $QEMU_HANDLE \
68 "{ 'execute': 'qmp_capabilities' }" \
69 'return'
70
71 # Create snapshot
72 TEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" -F $IMGFMT 1M
73 _send_qemu_cmd $QEMU_HANDLE \
74 "{ 'execute': 'blockdev-snapshot-sync',
75 'arguments': { 'device': 'source',
76 'snapshot-file': '$TEST_IMG.overlay',
77 'format': '$IMGFMT',
78 'mode': 'existing' } }" \
79 'return'
80
81 # Write something to the snapshot
82 _send_qemu_cmd $QEMU_HANDLE \
83 "{ 'execute': 'human-monitor-command',
84 'arguments': { 'command-line':
85 'qemu-io source \"write -P 3 128k 128k\"' } }" \
86 'return'
87
88 # Create target image
89 TEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" \
90 -F $IMGFMT 1M
91
92 # Mirror snapshot
93 _send_qemu_cmd $QEMU_HANDLE \
94 "{ 'execute': 'drive-mirror',
95 'arguments': { 'device': 'source',
96 'target': '$TEST_IMG.target.overlay',
97 'mode': 'existing',
98 'sync': 'top' } }" \
99 'return'
100
101 # Wait for convergence
102 _send_qemu_cmd $QEMU_HANDLE \
103 '' \
104 'BLOCK_JOB_READY'
105
106 # Write some more
107 _send_qemu_cmd $QEMU_HANDLE \
108 "{ 'execute': 'human-monitor-command',
109 'arguments': { 'command-line':
110 'qemu-io source \"write -P 4 192k 64k\"' } }" \
111 'return'
112
113 # Copy source backing chain to the target before completing the job
114 cp "$TEST_IMG.backing" "$TEST_IMG.target.backing"
115 cp "$TEST_IMG" "$TEST_IMG.target"
116 $QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" -F $IMGFMT "$TEST_IMG.target"
117
118 # Complete block job
119 _send_qemu_cmd $QEMU_HANDLE \
120 "{ 'execute': 'block-job-complete',
121 'arguments': { 'device': 'source' } }" \
122 ''
123
124 _send_qemu_cmd $QEMU_HANDLE \
125 '' \
126 '"status": "null"'
127
128 # Remove the source images
129 for img in "$TEST_IMG{,.backing,.overlay}"; do
130 _rm_test_img "$img"
131 done
132
133 echo
134
135 # Check online disk contents
136 _send_qemu_cmd $QEMU_HANDLE \
137 "{ 'execute': 'human-monitor-command',
138 'arguments': { 'command-line':
139 'qemu-io source \"read -P 1 0k 64k\"' } }" \
140 'return'
141
142 _send_qemu_cmd $QEMU_HANDLE \
143 "{ 'execute': 'human-monitor-command',
144 'arguments': { 'command-line':
145 'qemu-io source \"read -P 2 64k 64k\"' } }" \
146 'return'
147
148 _send_qemu_cmd $QEMU_HANDLE \
149 "{ 'execute': 'human-monitor-command',
150 'arguments': { 'command-line':
151 'qemu-io source \"read -P 3 128k 64k\"' } }" \
152 'return'
153
154 _send_qemu_cmd $QEMU_HANDLE \
155 "{ 'execute': 'human-monitor-command',
156 'arguments': { 'command-line':
157 'qemu-io source \"read -P 4 192k 64k\"' } }" \
158 'return'
159
160 echo
161
162 _send_qemu_cmd $QEMU_HANDLE \
163 "{ 'execute': 'quit' }" \
164 'return'
165
166 wait=1 _cleanup_qemu
167
168 echo
169
170 # Check offline disk contents
171 $QEMU_IO -c 'read -P 1 0k 64k' \
172 -c 'read -P 2 64k 64k' \
173 -c 'read -P 3 128k 64k' \
174 -c 'read -P 4 192k 64k' \
175 "$TEST_IMG.target.overlay" | _filter_qemu_io
176
177 echo
178
179 # success, all done
180 echo '*** done'
181 rm -f $seq.full
182 status=0