[Zetaback-devel] [zetaback commit] r138 - in trunk/test: . lib
svn-commit at lists.omniti.com
svn-commit at lists.omniti.com
Wed Nov 4 16:39:04 EST 2009
Author: mark
Date: 2009-11-04 16:39:03 -0500 (Wed, 04 Nov 2009)
New Revision: 138
Added:
trunk/test/lib/
trunk/test/lib/config.sh
trunk/test/lib/functions.sh
Modified:
trunk/test/test.sh
Log:
Some more testing code, and split into separate files
Added: trunk/test/lib/config.sh
===================================================================
--- trunk/test/lib/config.sh (rev 0)
+++ trunk/test/lib/config.sh 2009-11-04 21:39:03 UTC (rev 138)
@@ -0,0 +1,25 @@
+# Pool configuration
+SRCPOOL=zbsrctest
+DSTPOOL=zbdsttest
+POOLSIZE=64M
+
+LOGFILE=zbtest.log
+
+# Command locations
+ZPOOL=/usr/sbin/zpool
+ZFS=/usr/sbin/zfs
+DATE=/bin/date
+ZETABACK=$PWD/../zetaback
+
+# Colors
+export RESET="$( tput sgr0)" # Reset all attributes
+export BRIGHT="$( tput bold)" # Set “bright” attribute
+export BLACK="$( tput setaf 0)" # foreground to color #0 - black
+export RED="$( tput setaf 1)" # foreground to color #1 - red
+export GREEN="$( tput setaf 2)" # foreground to color #2 - green
+export YELLOW="$( tput setaf 3)" # foreground to color #3 - yellow
+export BLUE="$( tput setaf 4)" # foreground to color #4 - blue
+export MAGENTA="$( tput setaf 5)" # foreground to color #5 - magenta
+export CYAN="$( tput setaf 6)" # foreground to color #6 - cyan
+export WHITE="$( tput setaf 7)" # foreground to color #7 - white
+export FGDEFAULT="$( tput setaf 9)" # default foreground color
Added: trunk/test/lib/functions.sh
===================================================================
--- trunk/test/lib/functions.sh (rev 0)
+++ trunk/test/lib/functions.sh 2009-11-04 21:39:03 UTC (rev 138)
@@ -0,0 +1,63 @@
+# Log output to screen and file
+log() {
+ echo "`$DATE '+%Y-%m-%d %H:%M:%S'` : $@"
+ echo "`$DATE '+%Y-%m-%d %H:%M:%S'` : $@" >> $LOGFILE
+}
+
+# Simple yes/no prompt
+# Usage: if yesno "Do stuff?"; then do_stuff; fi
+yesno() {
+ local REPLY
+ echo -n "$@ (y/n) "
+ read
+ while [[ "$REPLY" != "n" && $REPLY != "y" ]]; do
+ echo -n "Valid answers are y, n"
+ read
+ done
+ # log the question and answer
+ log "$@ (y/n) $REPLY"
+ # Return true if we answered yes
+ [[ $REPLY == 'y' ]]
+}
+
+# Exit if not running as root
+require_root() {
+ if [[ $UID != 0 ]]; then
+ echo This script must be run as root
+ exit 1
+ fi
+}
+
+##############################################################################
+## Test functions
+##############################################################################
+plan() {
+ log "Planning to run $1 tests"
+ TESTS_TOTAL=$1
+ TESTS_RUN=0
+ TESTS_OK=0
+}
+
+ok_if() {
+ (( TESTS_RUN++ ))
+ echo -n "Running test: $@ ... "
+ if "$@"; then
+ echo "[${GREEN}OK${RESET}]"
+ (( TESTS_OK++ ))
+ else
+ echo "[${RED}FAILED${RESET}]"
+ fi
+}
+
+finish() {
+ echo "Tests run: $TESTS_RUN"
+ echo "Tests successful: $TESTS_OK"
+ if [[ $TESTS_RUN -ne $TESTS_TOTAL ]]; then
+ echo "${RED}ERROR:${RESET} incorrect number of tests run"
+ fi
+ if [[ $TESTS_OK -lt $TESTS_RUN ]]; then
+ echo "${RED}ERROR:${RESET} some tests failed"
+ else
+ echo "${GREEN}SUCCESS:${RESET} all tests that were run succeeded"
+ fi
+}
Modified: trunk/test/test.sh
===================================================================
--- trunk/test/test.sh 2009-11-04 21:26:37 UTC (rev 137)
+++ trunk/test/test.sh 2009-11-04 21:39:03 UTC (rev 138)
@@ -1,43 +1,7 @@
#!/bin/bash
-SRCPOOL=zbsrctest
-DSTPOOL=zbdsttest
-POOLSIZE=100M
+. lib/config.sh
+. lib/functions.sh
-LOGFILE=zbtest.log
-
-# Commands
-ZPOOL=/usr/sbin/zpool
-ZFS=/usr/sbin/zfs
-DATE=/bin/date
-ZETABACK=$PWD/../zetaback
-
-# Utility functions
-log() {
- echo "`$DATE '+%Y-%m-%d %H:%M:%S'` : $@"
- echo "`$DATE '+%Y-%m-%d %H:%M:%S'` : $@" >> $LOGFILE
-}
-
-yesno() {
- local REPLY
- echo -n "$@ (y/n) "
- read
- while [[ "$REPLY" != "n" && $REPLY != "y" ]]; do
- echo -n "Valid answers are y, n"
- read
- done
- # log the question and answer
- log "$@ (y/n) $REPLY"
- # Return true if we answered yes
- [[ $REPLY == 'y' ]]
-}
-
-require_root() {
- if [[ $UID != 0 ]]; then
- echo This script must be run as root
- exit 1
- fi
-}
-
# Test script specific functions
delete_pool_if_exists() {
if $ZPOOL list -H -o name | grep "^$1$" > /dev/null; then
@@ -71,19 +35,25 @@
create_zfs $SRCPOOL/test/foo
create_zfs $SRCPOOL/test/foo/bar
create_zfs $SRCPOOL/test/baz
+ zetaback_setclass $SRCPOOL/test/baz testclass
}
generate_zetaback_conf() {
log "Generating zetaback config"
cat > zetaback_test.conf <<EOF
default {
- store = /$DSTPOOL
+ store = /$DSTPOOL/%h
archive = /$DSTPOOL/archives
agent = "$PWD/../zetaback_agent -c $PWD/zetaback_agent_test.conf"
backup_interval = 10
full_interval = 604800
}
+testclass {
+ type = class
+ store = /$DSTPOOL/classy/%h
+}
+
$HOSTNAME { }
EOF
}
@@ -106,6 +76,11 @@
`zfs set com.omniti.labs.zetaback:exclude=on $1`
}
+zetaback_setclass() {
+ log "Setting zetaback class property on $1 to $2"
+ `zfs set com.omniti.labs.zetaback:class=$2 $1`
+}
+
### Main program thread
require_root
# Set up filesystems
More information about the Zetaback-devel
mailing list