111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2f0603329SDaniel P. Berrange# 3f0603329SDaniel P. Berrange# Test commit of encrypted qcow2 files 4f0603329SDaniel P. Berrange# 5f0603329SDaniel P. Berrange# Copyright (C) 2017 Red Hat, Inc. 6f0603329SDaniel P. Berrange# 7f0603329SDaniel P. Berrange# This program is free software; you can redistribute it and/or modify 8f0603329SDaniel P. Berrange# it under the terms of the GNU General Public License as published by 9f0603329SDaniel P. Berrange# the Free Software Foundation; either version 2 of the License, or 10f0603329SDaniel P. Berrange# (at your option) any later version. 11f0603329SDaniel P. Berrange# 12f0603329SDaniel P. Berrange# This program is distributed in the hope that it will be useful, 13f0603329SDaniel P. Berrange# but WITHOUT ANY WARRANTY; without even the implied warranty of 14f0603329SDaniel P. Berrange# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15f0603329SDaniel P. Berrange# GNU General Public License for more details. 16f0603329SDaniel P. Berrange# 17f0603329SDaniel P. Berrange# You should have received a copy of the GNU General Public License 18f0603329SDaniel P. Berrange# along with this program. If not, see <http://www.gnu.org/licenses/>. 19f0603329SDaniel P. Berrange# 20f0603329SDaniel P. Berrange 21f0603329SDaniel P. Berrange# creator 22f0603329SDaniel P. Berrangeowner=berrange@redhat.com 23f0603329SDaniel P. Berrange 24f0603329SDaniel P. Berrangeseq=`basename $0` 25f0603329SDaniel P. Berrangeecho "QA output created by $seq" 26f0603329SDaniel P. Berrange 27f0603329SDaniel P. Berrangestatus=1 # failure is the default! 28f0603329SDaniel P. Berrange 29f0603329SDaniel P. Berrange_cleanup() 30f0603329SDaniel P. Berrange{ 31f0603329SDaniel P. Berrange _cleanup_test_img 32f0603329SDaniel P. Berrange} 33f0603329SDaniel P. Berrangetrap "_cleanup; exit \$status" 0 1 2 3 15 34f0603329SDaniel P. Berrange 35f0603329SDaniel P. Berrange# get standard environment, filters and checks 36f0603329SDaniel P. Berrange. ./common.rc 37f0603329SDaniel P. Berrange. ./common.filter 38f0603329SDaniel P. Berrange 39f0603329SDaniel P. Berrange_supported_fmt qcow2 40f0603329SDaniel P. Berrange_supported_proto generic 41f0603329SDaniel P. Berrange_supported_os Linux 42d2a839edSMax Reitz_require_working_luks 43f0603329SDaniel P. Berrange 44f0603329SDaniel P. Berrange 45f0603329SDaniel P. Berrangesize=16M 46f0603329SDaniel P. BerrangeTEST_IMG_BASE=$TEST_IMG.base 47f0603329SDaniel P. BerrangeSECRET0="secret,id=sec0,data=astrochicken" 48f0603329SDaniel P. BerrangeSECRET1="secret,id=sec1,data=furby" 49f0603329SDaniel P. Berrange 50f0603329SDaniel P. BerrangeTEST_IMG_SAVE=$TEST_IMG 51f0603329SDaniel P. BerrangeTEST_IMG=$TEST_IMG_BASE 52f0603329SDaniel P. Berrangeecho "== create base ==" 53f0603329SDaniel P. Berrange_make_test_img --object $SECRET0 -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10" $size 54f0603329SDaniel P. BerrangeTEST_IMG=$TEST_IMG_SAVE 55f0603329SDaniel P. Berrange 56f0603329SDaniel P. BerrangeIMGSPECBASE="driver=$IMGFMT,file.filename=$TEST_IMG_BASE,encrypt.key-secret=sec0" 57f0603329SDaniel P. BerrangeIMGSPECLAYER="driver=$IMGFMT,file.filename=$TEST_IMG,encrypt.key-secret=sec1" 58f0603329SDaniel P. BerrangeIMGSPEC="$IMGSPECLAYER,backing.driver=$IMGFMT,backing.file.filename=$TEST_IMG_BASE,backing.encrypt.key-secret=sec0" 59f0603329SDaniel P. BerrangeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 60f0603329SDaniel P. Berrange 61f0603329SDaniel P. Berrangeecho 62f0603329SDaniel P. Berrangeecho "== writing whole image base ==" 63f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "write -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 64f0603329SDaniel P. Berrange 65f0603329SDaniel P. Berrangeecho "== create overlay ==" 66b66ff2c2SEric Blake_make_test_img --object $SECRET1 -o "encrypt.format=luks,encrypt.key-secret=sec1,encrypt.iter-time=10" -u -b "$TEST_IMG_BASE" -F $IMGFMT $size 67f0603329SDaniel P. Berrange 68f0603329SDaniel P. Berrangeecho 69f0603329SDaniel P. Berrangeecho "== writing whole image layer ==" 70f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "write -P 0x9 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 71f0603329SDaniel P. Berrange 72f0603329SDaniel P. Berrangeecho 73f0603329SDaniel P. Berrangeecho "== verify pattern base ==" 74f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "read -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 75f0603329SDaniel P. Berrange 76f0603329SDaniel P. Berrangeecho 77f0603329SDaniel P. Berrangeecho "== verify pattern layer ==" 78f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 79f0603329SDaniel P. Berrange 80f0603329SDaniel P. Berrangeecho 81f0603329SDaniel P. Berrangeecho "== committing layer into base ==" 82f0603329SDaniel P. Berrange$QEMU_IMG commit --object $SECRET0 --object $SECRET1 --image-opts $IMGSPEC | _filter_testdir 83f0603329SDaniel P. Berrange 84f0603329SDaniel P. Berrangeecho 85f0603329SDaniel P. Berrangeecho "== verify pattern base ==" 86f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "read -P 0x9 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 87f0603329SDaniel P. Berrange 88f0603329SDaniel P. Berrangeecho 89f0603329SDaniel P. Berrangeecho "== verify pattern layer ==" 90f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 91f0603329SDaniel P. Berrange 92f0603329SDaniel P. Berrangeecho 93f0603329SDaniel P. Berrangeecho "== checking image base ==" 941cc6169bSMax Reitz$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info --format-specific \ 95b01a1944SMax Reitz | sed -e "/^disk size:/ D" -e '/refcount bits:/ D' -e '/compat:/ D' \ 9639d2c7dcSMax Reitz -e '/lazy refcounts:/ D' -e '/corrupt:/ D' -e '/^\s*data file/ D' \ 97*7be20252SAlberto Garcia -e '/extended l2:/ D' \ 9839d2c7dcSMax Reitz | _filter_json_filename 99f0603329SDaniel P. Berrange 100f0603329SDaniel P. Berrangeecho 101f0603329SDaniel P. Berrangeecho "== checking image layer ==" 1021cc6169bSMax Reitz$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info --format-specific \ 103b01a1944SMax Reitz | sed -e "/^disk size:/ D" -e '/refcount bits:/ D' -e '/compat:/ D' \ 10439d2c7dcSMax Reitz -e '/lazy refcounts:/ D' -e '/corrupt:/ D' -e '/^\s*data file/ D' \ 105*7be20252SAlberto Garcia -e '/extended l2:/ D' \ 10639d2c7dcSMax Reitz | _filter_json_filename 107f0603329SDaniel P. Berrange 108f0603329SDaniel P. Berrange 109f0603329SDaniel P. Berrange# success, all done 110f0603329SDaniel P. Berrangeecho "*** done" 111f0603329SDaniel P. Berrangerm -f $seq.full 112f0603329SDaniel P. Berrangestatus=0 113