Add qemu 2.4.0
[kvmfornfv.git] / qemu / tests / qemu-iotests / 085
1 #!/bin/bash
2 #
3 # Live snapshot tests
4 #
5 # This tests live snapshots of images on a running QEMU instance, using
6 # QMP commands.  Both single disk snapshots, and transactional group
7 # snapshots are performed.
8 #
9 # Copyright (C) 2014 Red Hat, Inc.
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 #
24
25 # creator
26 owner=jcody@redhat.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 status=1        # failure is the default!
33
34 snapshot_virt0="snapshot-v0.qcow2"
35 snapshot_virt1="snapshot-v1.qcow2"
36
37 MAX_SNAPSHOTS=10
38
39 _cleanup()
40 {
41     _cleanup_qemu
42     for i in $(seq 1 ${MAX_SNAPSHOTS})
43     do
44         rm -f "${TEST_DIR}/${i}-${snapshot_virt0}"
45         rm -f "${TEST_DIR}/${i}-${snapshot_virt1}"
46     done
47         _cleanup_test_img
48
49 }
50 trap "_cleanup; exit \$status" 0 1 2 3 15
51
52 # get standard environment, filters and checks
53 . ./common.rc
54 . ./common.filter
55 . ./common.qemu
56
57 _supported_fmt qcow2
58 _supported_proto file
59 _supported_os Linux
60
61
62 # ${1}: unique identifier for the snapshot filename
63 function create_single_snapshot()
64 {
65     cmd="{ 'execute': 'blockdev-snapshot-sync',
66                       'arguments': { 'device': 'virtio0',
67                                      'snapshot-file':'"${TEST_DIR}/${1}-${snapshot_virt0}"',
68                                      'format': 'qcow2' } }"
69     _send_qemu_cmd $h "${cmd}" "return"
70 }
71
72 # ${1}: unique identifier for the snapshot filename
73 function create_group_snapshot()
74 {
75     cmd="{ 'execute': 'transaction', 'arguments':
76            {'actions': [
77                { 'type': 'blockdev-snapshot-sync', 'data' :
78                    { 'device': 'virtio0',
79                       'snapshot-file': '"${TEST_DIR}/${1}-${snapshot_virt0}"' } },
80                { 'type': 'blockdev-snapshot-sync', 'data' :
81                    { 'device': 'virtio1',
82                        'snapshot-file': '"${TEST_DIR}/${1}-${snapshot_virt1}"' } } ]
83              } }"
84
85     _send_qemu_cmd $h "${cmd}" "return"
86 }
87
88 size=128M
89
90 _make_test_img $size
91 mv "${TEST_IMG}" "${TEST_IMG}.orig"
92 _make_test_img $size
93
94 echo
95 echo === Running QEMU ===
96 echo
97
98 qemu_comm_method="qmp"
99 _launch_qemu -drive file="${TEST_IMG}.orig",if=virtio -drive file="${TEST_IMG}",if=virtio
100 h=$QEMU_HANDLE
101
102 echo
103 echo === Sending capabilities ===
104 echo
105
106 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" "return"
107
108 echo
109 echo === Create a single snapshot on virtio0 ===
110 echo
111
112 create_single_snapshot 1
113
114
115 echo
116 echo === Invalid command - missing device and nodename ===
117 echo
118
119 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync',
120                          'arguments': { 'snapshot-file':'"${TEST_DIR}/1-${snapshot_virt0}"',
121                                      'format': 'qcow2' } }" "error"
122
123 echo
124 echo === Invalid command - missing snapshot-file ===
125 echo
126
127 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync',
128                          'arguments': { 'device': 'virtio0',
129                                      'format': 'qcow2' } }" "error"
130 echo
131 echo
132 echo === Create several transactional group snapshots ===
133 echo
134
135 for i in $(seq 2 ${MAX_SNAPSHOTS})
136 do
137     create_group_snapshot ${i}
138 done
139
140 # success, all done
141 echo "*** done"
142 rm -f $seq.full
143 status=0