diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-05-03 13:44:49 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-05-03 14:32:24 +0100 |
commit | c53ea071c690b1760b89a56f2a634bec00d2b554 (patch) | |
tree | 048ad6f5a7809235618b5e49bfc93b632688c41a /tools | |
parent | 0cc35251421bc5c4d5a682566e2d71b942bbcc4a (diff) | |
download | libguestfs-c53ea071c690b1760b89a56f2a634bec00d2b554.tar.gz libguestfs-c53ea071c690b1760b89a56f2a634bec00d2b554.tar.xz libguestfs-c53ea071c690b1760b89a56f2a634bec00d2b554.zip |
virt-make-fs: Simplify test code.
This is just code motion.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/test-virt-make-fs.sh | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/tools/test-virt-make-fs.sh b/tools/test-virt-make-fs.sh index 5a318069..8f6ff2e8 100755 --- a/tools/test-virt-make-fs.sh +++ b/tools/test-virt-make-fs.sh @@ -16,53 +16,47 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# Engage in some montecarlo testing of virt-make-fs. + export LANG=C set -e -# Is NTFS supported? -if ../fish/guestfish -a /dev/null run : available "ntfs3g ntfsprogs"; then - ntfs_supported=yes -else - ntfs_supported=no -fi +# Check which filesystems are supported by the appliance. +eval $( +perl -MSys::Guestfs '-MSys::Guestfs::Lib qw(feature_available)' -e ' + $g = Sys::Guestfs->new(); + $g->add_drive ("/dev/null"); + $g->launch (); + feature_available ($g, "ntfs3g") and print "ntfs3g_available=yes\n"; + feature_available ($g, "ntfsprogs") and print "ntfsprogs_available=yes\n"; +') -# Engage in some montecarlo testing of virt-make-fs. +declare -a choices + +# Return a random element from the array 'choices'. +function random_choice +{ + echo "${choices[$((RANDOM % ${#choices[*]}))]}" +} -if [ "$ntfs_supported" = "yes" ]; then - case $((RANDOM % 4)) in - 0) type="--type=ext2" ;; - 1) type="--type=ext3" ;; - 2) type="--type=ext4" ;; - 3) type="--type=ntfs" ;; - # Can't test vfat because we cannot create a tar archive - # where files are owned by UID:GID 0:0. As a result, tar - # in the appliance fails when trying to change the UID of - # the files to some non-zero value (not supported by FAT). - # 4) type="--type=vfat" ;; - esac -else - case $((RANDOM % 3)) in - 0) type="--type=ext2" ;; - 1) type="--type=ext3" ;; - 2) type="--type=ext4" ;; - esac +# Can't test vfat because we cannot create a tar archive +# where files are owned by UID:GID 0:0. As a result, tar +# in the appliance fails when trying to change the UID of +# the files to some non-zero value (not supported by FAT). +choices=(--type=ext2 --type=ext3 --type=ext4) +if [ "$ntfs3g_available" = "yes" -a "$ntfsprogs_available" = "yes" ]; then + choices[${#choices[*]}]="--type=ntfs" fi +type=`random_choice` -case $((RANDOM % 2)) in - 0) format="--format=raw" ;; - 1) format="--format=qcow2" ;; -esac +choices=(--format=raw --format=qcow2) +format=`random_choice` -case $((RANDOM % 3)) in - 0) partition="--partition" ;; - 1) partition="--partition=gpt" ;; - 2) ;; -esac +choices=(--partition --partition=gpt) +partition=`random_choice` -case $((RANDOM % 2)) in - 0) ;; - 1) size="--size=+1M" ;; -esac +choices=("" --size=+1M) +size=`random_choice` if [ -n "$LIBGUESTFS_DEBUG" ]; then debug=--debug; fi |