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