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 42f0603329SDaniel P. Berrange 43f0603329SDaniel P. Berrange 44f0603329SDaniel P. Berrangesize=16M 45f0603329SDaniel P. BerrangeTEST_IMG_BASE=$TEST_IMG.base 46f0603329SDaniel P. BerrangeSECRET0="secret,id=sec0,data=astrochicken" 47f0603329SDaniel P. BerrangeSECRET1="secret,id=sec1,data=furby" 48f0603329SDaniel P. Berrange 49f0603329SDaniel P. BerrangeTEST_IMG_SAVE=$TEST_IMG 50f0603329SDaniel P. BerrangeTEST_IMG=$TEST_IMG_BASE 51f0603329SDaniel P. Berrangeecho "== create base ==" 52f0603329SDaniel P. Berrange_make_test_img --object $SECRET0 -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10" $size 53f0603329SDaniel P. BerrangeTEST_IMG=$TEST_IMG_SAVE 54f0603329SDaniel P. Berrange 55f0603329SDaniel P. BerrangeIMGSPECBASE="driver=$IMGFMT,file.filename=$TEST_IMG_BASE,encrypt.key-secret=sec0" 56f0603329SDaniel P. BerrangeIMGSPECLAYER="driver=$IMGFMT,file.filename=$TEST_IMG,encrypt.key-secret=sec1" 57f0603329SDaniel P. BerrangeIMGSPEC="$IMGSPECLAYER,backing.driver=$IMGFMT,backing.file.filename=$TEST_IMG_BASE,backing.encrypt.key-secret=sec0" 58f0603329SDaniel P. BerrangeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 59f0603329SDaniel P. Berrange 60f0603329SDaniel P. Berrangeecho 61f0603329SDaniel P. Berrangeecho "== writing whole image base ==" 62f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "write -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 63f0603329SDaniel P. Berrange 64f0603329SDaniel P. Berrangeecho "== create overlay ==" 65f0603329SDaniel P. Berrange_make_test_img --object $SECRET1 -o "encrypt.format=luks,encrypt.key-secret=sec1,encrypt.iter-time=10" -u -b "$TEST_IMG_BASE" $size 66f0603329SDaniel P. Berrange 67f0603329SDaniel P. Berrangeecho 68f0603329SDaniel P. Berrangeecho "== writing whole image layer ==" 69f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "write -P 0x9 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 70f0603329SDaniel P. Berrange 71f0603329SDaniel P. Berrangeecho 72f0603329SDaniel P. Berrangeecho "== verify pattern base ==" 73f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "read -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 74f0603329SDaniel P. Berrange 75f0603329SDaniel P. Berrangeecho 76f0603329SDaniel P. Berrangeecho "== verify pattern layer ==" 77f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 78f0603329SDaniel P. Berrange 79f0603329SDaniel P. Berrangeecho 80f0603329SDaniel P. Berrangeecho "== committing layer into base ==" 81f0603329SDaniel P. Berrange$QEMU_IMG commit --object $SECRET0 --object $SECRET1 --image-opts $IMGSPEC | _filter_testdir 82f0603329SDaniel P. Berrange 83f0603329SDaniel P. Berrangeecho 84f0603329SDaniel P. Berrangeecho "== verify pattern base ==" 85f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "read -P 0x9 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 86f0603329SDaniel P. Berrange 87f0603329SDaniel P. Berrangeecho 88f0603329SDaniel P. Berrangeecho "== verify pattern layer ==" 89f0603329SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 90f0603329SDaniel P. Berrange 91f0603329SDaniel P. Berrangeecho 92f0603329SDaniel P. Berrangeecho "== checking image base ==" 931cc6169bSMax Reitz$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info --format-specific \ 94b01a1944SMax Reitz | sed -e "/^disk size:/ D" -e '/refcount bits:/ D' -e '/compat:/ D' \ 95*39d2c7dcSMax Reitz -e '/lazy refcounts:/ D' -e '/corrupt:/ D' -e '/^\s*data file/ D' \ 96*39d2c7dcSMax Reitz | _filter_json_filename 97f0603329SDaniel P. Berrange 98f0603329SDaniel P. Berrangeecho 99f0603329SDaniel P. Berrangeecho "== checking image layer ==" 1001cc6169bSMax Reitz$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info --format-specific \ 101b01a1944SMax Reitz | sed -e "/^disk size:/ D" -e '/refcount bits:/ D' -e '/compat:/ D' \ 102*39d2c7dcSMax Reitz -e '/lazy refcounts:/ D' -e '/corrupt:/ D' -e '/^\s*data file/ D' \ 103*39d2c7dcSMax Reitz | _filter_json_filename 104f0603329SDaniel P. Berrange 105f0603329SDaniel P. Berrange 106f0603329SDaniel P. Berrange# success, all done 107f0603329SDaniel P. Berrangeecho "*** done" 108f0603329SDaniel P. Berrangerm -f $seq.full 109f0603329SDaniel P. Berrangestatus=0 110