Files
libguestfs/tests/md/test-mdadm.sh
Jim Meyering 6edecdec59 maint: use $var notation rather than ${var} when possible
I noticed some uses of ${srcdir} in shell scripts.
That is almost always better written as $srcdir.
The patch below converts most such variable references.
Here are the few remaining candidates:

$ git grep -i -E '\$\{[a-zA-Z_0-9]+\}'|grep -v Makefile.in.in
configure.ac:        JAR_INSTALL_DIR=\${prefix}/share/java
configure.ac:        JNI_INSTALL_DIR=\${libdir}
debian/rules:   for TEST in ${DEBIAN_SKIP_TEST}; do \
debian/rules:#          mv $${mod} $$(dirname $${mod})/libguestfsmod.so; \
java/Makefile.am:libguestfs_jar_DATA = libguestfs-${VERSION}.jar
java/Makefile.am:libguestfs-${VERSION}.jar: $(libguestfs_jar_class_files)
perl/lib/Sys/Guestfs/Lib.pm:                      "-f", '${Package} ${Version} ${Architecture} ${Status}\n',
perl/typemap:            croak (\"${Package}::$func_name(): called on a closed handle\");
perl/typemap:        croak (\"${Package}::$func_name(): $var is not a blessed HV reference\");
tests/data/Makefile.am:   echo "$${i}abcdefghijklmnopqrstuvwxyz"; \

We could change all of those, too, except the ones in configure.ac
and Makefile.am, since they refer to Make variables.  Even those
should be changed, but to use the preferred Makefile notation:
$(prefix), $(libdir), $(VERSION).

>From a86770ecd45666232a94d76c8725c8f9b1c76e3a Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Mon, 23 Jan 2012 11:15:12 +0100
Subject: [PATCH libguestfs] maint: use $var notation rather than ${var} when
 possible

The only case to avoid in a shell script is when the byte after the
"}" is word-constituent, and concatenating it would thus change the
name of the variable.

These changes were induced by running this command:
  git grep -l -i -E '\$\{(srcdir|md)' \
    |xargs perl -pi -e 's/\$\{(srcdir|md)\}($|\w)/\$$1$2/gi'

The "g" was needed because there was one line with two instances.
The "i" is to handle ${SRCDIR}.  The ($|\w) ensures that concatenating
whatever follows the "}" won't change semantics.

* gobject/run-bindtests: Use "$srcdir", not "${srcdir}".
* haskell/run-bindtests: Likewise.
* java/run-bindtests: Likewise.
* ocaml/run-bindtests: Likewise.
* perl/run-bindtests: Likewise.
* python/run-bindtests: Likewise.
* ruby/run-bindtests: Likewise.
* tests/guests/guest-aux/make-debian-img.sh: Likewise, but $SRCDIR.
* tests/guests/guest-aux/make-ubuntu-img.sh: Likewise.
* tests/guests/guest-aux/make-windows-img.sh: Likewise.
* tests/md/test-mdadm.sh: Likewise, but $md.
2012-01-23 10:40:47 +00:00

167 lines
4.3 KiB
Bash
Executable File

#!/bin/bash -
# libguestfs
# Copyright (C) 2011 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.
# Test guestfish md-create and md-detail commands.
set -e
rm -f md-test1.img md-test2.img md-test3.img md-test4.img
../../fish/guestfish <<EOF
# Add four empty disks
sparse md-test1.img 100M
sparse md-test2.img 100M
sparse md-test3.img 100M
sparse md-test4.img 100M
run
# Create lots of test partitions.
part-init /dev/sda mbr
part-add /dev/sda p 4096 8191
part-add /dev/sda p 8192 12287
part-add /dev/sda p 12288 16383
part-add /dev/sda p 16384 20479
part-init /dev/sdb mbr
part-add /dev/sdb p 4096 8191
part-add /dev/sdb p 8192 12287
part-add /dev/sdb p 12288 16383
part-add /dev/sdb p 16384 20479
part-init /dev/sdc mbr
part-add /dev/sdc p 4096 8191
part-add /dev/sdc p 8192 12287
part-add /dev/sdc p 12288 16383
part-add /dev/sdc p 16384 20479
part-init /dev/sdd mbr
part-add /dev/sdd p 4096 8191
part-add /dev/sdd p 8192 12287
part-add /dev/sdd p 12288 16383
part-add /dev/sdd p 16384 20479
# RAID 1.
md-create r1t1 "/dev/sda1 /dev/sdb1"
md-create r1t2 "/dev/sdc1 /dev/sdd1" chunk:65536
# RAID 5.
md-create r5t1 "/dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2" \
missingbitmap:0x10 nrdevices:4 spare:1 level:5
md-create r5t2 "/dev/sda3 /dev/sdb3" missingbitmap:0x1 level:5
md-create r5t3 "/dev/sdc3 /dev/sdd3" \
missingbitmap:0x6 nrdevices:2 spare:2 level:5
# Make some filesystems and put some content on the
# new RAID devices to see if they work.
mkfs ext2 /dev/md/r1t1
mkfs ext2 /dev/md/r1t2
mkfs ext2 /dev/md/r5t1
mkfs ext2 /dev/md/r5t2
mkfs ext2 /dev/md/r5t3
mkmountpoint /r1t1
mount /dev/md/r1t1 /r1t1
mkmountpoint /r1t2
mount /dev/md/r1t2 /r1t2
mkmountpoint /r5t1
mount /dev/md/r5t1 /r5t1
mkmountpoint /r5t2
mount /dev/md/r5t2 /r5t2
mkmountpoint /r5t3
mount /dev/md/r5t3 /r5t3
touch /r1t1/foo
mkdir /r1t2/bar
write /r5t1/foo "hello"
write /r5t2/bar "goodbye"
write /r5t3/baz "testing"
EOF
eval `../../fish/guestfish --listen`
../../fish/guestfish --remote add-ro md-test1.img
../../fish/guestfish --remote add-ro md-test2.img
../../fish/guestfish --remote add-ro md-test3.img
../../fish/guestfish --remote add-ro md-test4.img
../../fish/guestfish --remote run
for md in `../../fish/guestfish --remote list-md-devices`; do
../../fish/guestfish --remote md-detail "$md" > md-detail.out
sed 's/:\s*/=/' md-detail.out > md-detail.out.sh
. md-detail.out.sh
rm -f md-detail.out.sh
error=0
case "$name" in
*:r1t1)
[ "$level" == "raid1" ] || error=1
[ "$devices" == "2" ] || error=1
;;
*:r1t2)
[ "$level" == "raid1" ] || error=1
[ "$devices" == "2" ] || error=1
;;
*:r5t1)
[ "$level" == "raid5" ] || error=1
[ "$devices" == "4" ] || error=1
;;
*:r5t2)
[ "$level" == "raid5" ] || error=1
[ "$devices" == "3" ] || error=1
;;
*:r5t3)
[ "$level" == "raid5" ] || error=1
[ "$devices" == "2" ] || error=1
;;
*)
error=1
esac
[[ "$uuid" =~ ([0-9a-f]{8}:){3}[0-9a-f]{8} ]] || error=1
[ ! -z "$metadata" ] || error=1
if [ "$error" == "1" ]; then
echo "$0: Unexpected output from md-detail for device $md"
cat md-detail.out
../../fish/guestfish --remote exit
exit 1
fi
done
../../fish/guestfish --remote exit
eval `../../fish/guestfish --listen`
../../fish/guestfish --remote add-ro md-test1.img
../../fish/guestfish --remote add-ro md-test2.img
../../fish/guestfish --remote add-ro md-test3.img
../../fish/guestfish --remote add-ro md-test4.img
../../fish/guestfish --remote run
for md in `../../fish/guestfish --remote list-md-devices`; do
../../fish/guestfish --remote md-stop "$md"
done
../../fish/guestfish --remote exit
rm -f md-detail.out md-test1.img md-test2.img md-test3.img md-test4.img