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