commit 01c23d75ef0f94cffc1871a29350d2b8a6f10062
Author: Iustin Pop <iustin@google.com>
Date:   Thu Mar 8 01:10:30 2012 +0200

    Add a helper for htools CLI tests
    
    … and update live-test.sh to use it, instead of hard-coding the
    program paths.
    
    A few additional style fixes are also done (indentation).
    
    Signed-off-by: Iustin Pop <iustin@google.com>
    Reviewed-by: René Nussbaumer <rn@google.com>

diff --git a/htools/cli-tests-defs.sh b/htools/cli-tests-defs.sh
new file mode 100644
index 0000000..da24b0c
--- /dev/null
+++ b/htools/cli-tests-defs.sh
@@ -0,0 +1,44 @@
+#
+
+# Copyright (C) 2012 Google 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.
+
+# This is an shell testing configuration fragment.
+
+HBINARY=${HBINARY:-./htools/htools}
+
+hbal() {
+  HTOOLS=hbal $HBINARY "$@"
+}
+
+hscan() {
+  HTOOLS=hscan $HBINARY "$@"
+}
+
+hail() {
+  HTOOLS=hail $HBINARY "$@"
+}
+
+hspace() {
+  HTOOLS=hspace $HBINARY "$@"
+}
+
+hinfo() {
+  HTOOLS=hinfo $HBINARY "$@"
+}
+
+ALL_ROLES="hbal hscan hail hspace hinfo"
diff --git a/htools/live-test.sh b/htools/live-test.sh
index c47766f..78b680f 100755
--- a/htools/live-test.sh
+++ b/htools/live-test.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# Copyright (C) 2009, 2010, 2011 Google Inc.
+# Copyright (C) 2009, 2010, 2011, 2012 Google 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
@@ -35,21 +35,23 @@ set -e
 : ${RAPI:=localhost}
 GROUP=${GROUP:+-G $GROUP}
 
+. $(dirname $0)/cli-tests-defs.sh
+
 T=`mktemp -d`
 trap 'rm -rf $T' EXIT
 echo Using $T as temporary dir
 
 echo Checking command line
-for prog in hscan hbal hail hspace; do
-    ./$prog --version
-    ./$prog --help
-    ! ./$prog --no-such-option
+for prog in $ALL_ROLES; do
+  $prog --version
+  $prog --help >/dev/null
+  ! $prog --no-such-option 2>/dev/null
 done
 
 echo Testing hscan/rapi
-./hscan -d$T $RAPI -p
+hscan -d$T $RAPI -p
 echo Testing hscan/luxi
-./hscan -d$T -L$LUXI -p
+hscan -d$T -L$LUXI -p
 echo Comparing hscan results...
 diff -u $T/$RAPI.data $T/LOCAL.data
 
@@ -58,13 +60,13 @@ FI=$($CLUSTER head -n1 /var/lib/ganeti/ssconf_instance_list)
 
 
 echo Testing hbal/luxi
-./hbal -L$LUXI $GROUP -p --print-instances -C$T/hbal-luxi-cmds.sh
+hbal -L$LUXI $GROUP -p --print-instances -C$T/hbal-luxi-cmds.sh
 bash -n $T/hbal-luxi-cmds.sh
 echo Testing hbal/rapi
-./hbal -m$RAPI $GROUP -p --print-instances -C$T/hbal-rapi-cmds.sh
+hbal -m$RAPI $GROUP -p --print-instances -C$T/hbal-rapi-cmds.sh
 bash -n $T/hbal-rapi-cmds.sh
 echo Testing hbal/text
-./hbal -t$T/$RAPI.data $GROUP -p --print-instances -C$T/hbal-text-cmds.sh
+hbal -t$T/$RAPI.data $GROUP -p --print-instances -C$T/hbal-text-cmds.sh
 bash -n $T/hbal-text-cmds.sh
 echo Comparing hbal results
 diff -u $T/hbal-luxi-cmds.sh $T/hbal-rapi-cmds.sh
@@ -72,30 +74,30 @@ diff -u $T/hbal-luxi-cmds.sh $T/hbal-text-cmds.sh
 
 
 echo Testing hbal/text with evacuation mode
-./hbal -t$T/$RAPI.data $GROUP -E
+hbal -t$T/$RAPI.data $GROUP -E
 echo Testing hbal/text with no disk moves
-./hbal -t$T/$RAPI.data $GROUP --no-disk-moves
+hbal -t$T/$RAPI.data $GROUP --no-disk-moves
 echo Testing hbal/text with no instance moves
-./hbal -t$T/$RAPI.data $GROUP --no-instance-moves
+hbal -t$T/$RAPI.data $GROUP --no-instance-moves
 echo Testing hbal/text with offline node mode
-./hbal -t$T/$RAPI.data $GROUP -O$FN
+hbal -t$T/$RAPI.data $GROUP -O$FN
 echo Testing hbal/text with utilization data
 echo "$FI 2 2 2 2" > $T/util.data
-./hbal -t$T/$RAPI.data $GROUP -U $T/util.data
+hbal -t$T/$RAPI.data $GROUP -U $T/util.data
 echo Testing hbal/text with bad utilization data
 echo "$FI 2 a 3b" > $T/util.data
-! ./hbal -t$T/$RAPI.data $GROUP -U $T/util.data
+! hbal -t$T/$RAPI.data $GROUP -U $T/util.data
 echo Testing hbal/text with instance exclusion/selection
-./hbal -t$T/$RAPI.data $GROUP --exclude-instances=$FI
-./hbal -t$T/$RAPI.data $GROUP --select-instances=$FI
-! ./hbal -t$T/$RAPI.data --exclude-instances=no_such_instance
-! ./hbal -t$T/$RAPI.data --select-instances=no_such_instance
+hbal -t$T/$RAPI.data $GROUP --exclude-instances=$FI
+hbal -t$T/$RAPI.data $GROUP --select-instances=$FI
+! hbal -t$T/$RAPI.data --exclude-instances=no_such_instance
+! hbal -t$T/$RAPI.data --select-instances=no_such_instance
 echo Testing hbal/text with tag exclusion
-./hbal -t $T/$RAPI.data $GROUP --exclusion-tags=no_such_tag
+hbal -t $T/$RAPI.data $GROUP --exclusion-tags=no_such_tag
 echo Testing hbal multiple backend failure
-! ./hbal -t $T/$RAPI.data -L$LUXI
+! hbal -t $T/$RAPI.data -L$LUXI
 echo Testing hbal no backend failure
-! ./hbal
+! hbal
 
 echo Getting data files for hail
 for dtemplate in plain drbd; do
@@ -109,44 +111,44 @@ $CLUSTER gnt-debug allocator --dir in --mode multi-evacuate \
     $FN > $T/h-evacuate.json
 for dtemplate in plain drbd; do
   echo Testing hail/allocate-$dtemplate
-  ./hail $T/h-alloc-$dtemplate.json
+  hail $T/h-alloc-$dtemplate.json
 done
 echo Testing hail/relocate for instance $FI
-./hail $T/h-reloc.json
+hail $T/h-reloc.json
 echo Testing hail/evacuate for node $FN
-./hail $T/h-evacuate.json
+hail $T/h-evacuate.json
 
 HOUT="$T/hspace.out"
 
 check_hspace_out() {
-    set -u
-    set -e
-    source "$HOUT"
-    echo ALLOC_INSTANCES=$HTS_ALLOC_INSTANCES
-    echo TSPEC=$HTS_TSPEC
-    echo OK=$HTS_OK
+  set -u
+  set -e
+  source "$HOUT"
+  echo ALLOC_INSTANCES=$HTS_ALLOC_INSTANCES
+  echo TSPEC=$HTS_TSPEC
+  echo OK=$HTS_OK
 }
 
 TIER="--tiered 102400,8192,2"
 SIMU="--simu=preferred,10,6835937,32768,4"
 echo Testing hspace/luxi
-./hspace -L$LUXI $TIER -v > $HOUT
+hspace -L$LUXI $TIER -v > $HOUT
 ( check_hspace_out ) || exit 1
 echo Testing hspace/rapi
-./hspace -m$RAPI $TIER -v > $HOUT
+hspace -m$RAPI $TIER -v > $HOUT
 ( check_hspace_out ) || exit 1
 echo Testing hspace/text
-./hspace -t$T/$RAPI.data $TIER -v > $HOUT
+hspace -t$T/$RAPI.data $TIER -v > $HOUT
 ( check_hspace_out ) || exit 1
 echo Testing hspace/simu
 # ~6T disk space, 32G ram, 4 VCPUs
-./hspace $SIMU $TIER -v > $HOUT
+hspace $SIMU $TIER -v > $HOUT
 ( check_hspace_out ) || exit 1
 # Wrong tiered spec input
-! ./hspace $SIMU --tiered 1,2,3x
-! ./hspace $SIMU --tiered 1,2,x
-! ./hspace $SIMU --tiered 1,2
+! hspace $SIMU --tiered 1,2,3x
+! hspace $SIMU --tiered 1,2,x
+! hspace $SIMU --tiered 1,2
 # Wrong simu spec
-! ./hspace --simu=1,2,x
+! hspace --simu=1,2,x
 
 echo All OK
