mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
tests/qemu: isolate MD5 calculation in an own shared function
md5sum(1) does not exist everywhere, so wrap it in an own function so the right implementation can be chosen on each OS. Also, wrapping it avoid using awk everytime.
This commit is contained in:
@@ -30,6 +30,7 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(TESTS) \
|
||||
guestfs-md5.sh \
|
||||
qemu-boot.c \
|
||||
qemu-speed-test.c
|
||||
|
||||
|
||||
30
tests/qemu/guestfs-md5.sh
Executable file
30
tests/qemu/guestfs-md5.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash -
|
||||
# libguestfs
|
||||
# Copyright (C) 2014 Red Hat Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
do_md5 ()
|
||||
{
|
||||
case "$(uname)" in
|
||||
Linux)
|
||||
md5sum "$1" | awk '{print $1}'
|
||||
;;
|
||||
*)
|
||||
echo "$0: unknown method to calculate MD5 of file on $(uname)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -22,10 +22,12 @@
|
||||
|
||||
set -e
|
||||
|
||||
. $srcdir/guestfs-md5.sh
|
||||
|
||||
rm -f liveness1.img
|
||||
|
||||
guestfish sparse liveness1.img 100M
|
||||
liveness1_md5sum="$(md5sum liveness1.img | awk '{print $1}')"
|
||||
liveness1_md5sum="$(do_md5 liveness1.img)"
|
||||
|
||||
guestfish <<'EOF'
|
||||
add liveness1.img format:raw
|
||||
@@ -41,7 +43,7 @@ write /test "This is a test"
|
||||
EOF
|
||||
|
||||
# Verify that the disk has changed.
|
||||
if [ "$(md5sum liveness1.img | awk '{print $1}')" = "$liveness1_md5sum" ]; then
|
||||
if [ "$(do_md5 liveness1.img)" = "$liveness1_md5sum" ]; then
|
||||
echo "***** ERROR *****"
|
||||
echo "Write operations are not modifying an attached disk."
|
||||
echo
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
set -e
|
||||
|
||||
. $srcdir/guestfs-md5.sh
|
||||
|
||||
# UML backend doesn't support qcow2 format.
|
||||
supports_qcow2=yes
|
||||
if [ "$(guestfish get-backend)" = "uml" ]; then
|
||||
@@ -31,14 +33,14 @@ fi
|
||||
rm -f isolation1.img isolation2.img isolation3.img
|
||||
|
||||
guestfish sparse isolation1.img 100M
|
||||
isolation1_md5sum="$(md5sum isolation1.img | awk '{print $1}')"
|
||||
isolation1_md5sum="$(do_md5 isolation1.img)"
|
||||
guestfish sparse isolation2.img 100M
|
||||
isolation2_md5sum="$(md5sum isolation2.img | awk '{print $1}')"
|
||||
isolation2_md5sum="$(do_md5 isolation2.img)"
|
||||
|
||||
if [ "$supports_qcow2" = "yes" ]; then
|
||||
guestfish \
|
||||
disk-create isolation3.img qcow2 100M preallocation:metadata
|
||||
isolation3_md5sum="$(md5sum isolation3.img | awk '{print $1}')"
|
||||
isolation3_md5sum="$(do_md5 isolation3.img)"
|
||||
add3="add-drive-opts isolation3.img format:qcow2 readonly:true"
|
||||
cmds3="
|
||||
part-disk /dev/sdc mbr
|
||||
@@ -92,14 +94,14 @@ function serious_error
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ "$(md5sum isolation1.img | awk '{print $1}')" != "$isolation1_md5sum" ]; then
|
||||
if [ "$(do_md5 isolation1.img)" != "$isolation1_md5sum" ]; then
|
||||
serious_error
|
||||
fi
|
||||
if [ "$(md5sum isolation2.img | awk '{print $1}')" != "$isolation2_md5sum" ]; then
|
||||
if [ "$(do_md5 isolation2.img)" != "$isolation2_md5sum" ]; then
|
||||
serious_error
|
||||
fi
|
||||
if [ "$supports_qcow2" = "yes" -a \
|
||||
"$(md5sum isolation3.img | awk '{print $1}')" != "$isolation3_md5sum" ]; then
|
||||
"$(do_md5 isolation3.img)" != "$isolation3_md5sum" ]; then
|
||||
serious_error
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user