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