master
text 133 lines 3.47 KB
Raw
1 #!/usr/bin/env bash
2 # group: rw quick
3 #
4 # Test vmdk backing file correlation
5 #
6 # Copyright (C) 2018 Red Hat, Inc.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #
21
22 # creator
23 owner=hreitz@redhat.com
24
25 seq=$(basename $0)
26 echo "QA output created by $seq"
27
28 status=1 # failure is the default!
29
30 _cleanup()
31 {
32 _cleanup_test_img
33 _rm_test_img "$TEST_IMG.not_base"
34 }
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40 . ./common.qemu
41
42 # This tests vmdk-specific low-level functionality
43 _supported_fmt vmdk
44 _supported_proto file
45 _supported_os Linux
46 _unsupported_imgopts "subformat=monolithicFlat" \
47 "subformat=twoGbMaxExtentFlat" \
48 "subformat=twoGbMaxExtentSparse"
49 _require_hmp
50
51 TEST_IMG="$TEST_IMG.base" _make_test_img 1M
52 TEST_IMG="$TEST_IMG.not_base" _make_test_img 1M
53 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
54
55 make_opts()
56 {
57 node_name=$1
58 filename=$2
59 backing=$3
60
61 if [ -z "$backing" ]; then
62 backing="null"
63 else
64 backing="'$backing'"
65 fi
66
67 echo "{ 'node-name': '$node_name',
68 'driver': 'vmdk',
69 'file': {
70 'driver': 'file',
71 'filename': '$filename'
72 },
73 'backing': $backing }"
74 }
75
76 overlay_opts=$(make_opts overlay "$TEST_IMG" backing)
77 base_opts=$(make_opts backing "$TEST_IMG.base")
78 not_base_opts=$(make_opts backing "$TEST_IMG.not_base")
79
80 not_vmdk_opts="{ 'node-name': 'backing', 'driver': 'null-co' }"
81
82 echo
83 echo '=== Testing fitting VMDK backing image ==='
84 echo
85
86 qemu_comm_method=monitor \
87 _launch_qemu -blockdev "$base_opts" -blockdev "$overlay_opts"
88
89 # Should not return an error
90 _send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'ops'
91
92 _cleanup_qemu
93
94
95 echo
96 echo '=== Testing unrelated VMDK backing image ==='
97 echo
98
99 qemu_comm_method=monitor \
100 _launch_qemu -blockdev "$not_base_opts" -blockdev "$overlay_opts"
101
102 # Should fail (gracefully)
103 _send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
104
105 _cleanup_qemu
106
107
108 echo
109 echo '=== Testing non-VMDK backing image ==='
110 echo
111
112 # FIXME: This is the reason why we have to use two -blockdev
113 # invocations. You can only fully override the backing file options
114 # if you either specify a node reference (as done here) or the new
115 # options contain file.filename (which in this case they do not).
116 # In other cases, file.filename will be set to whatever the image
117 # header of the overlay contains (which we do not want). I consider
118 # this a FIXME because with -blockdev, you cannot specify "partial"
119 # options, so setting file.filename but leaving the rest as specified
120 # by the user does not make sense.
121 qemu_comm_method=monitor \
122 _launch_qemu -blockdev "$not_vmdk_opts" -blockdev "$overlay_opts"
123
124 # Should fail (gracefully)
125 _send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
126
127 _cleanup_qemu
128
129
130 # success, all done
131 echo "*** done"
132 rm -f $seq.full
133 status=0