diff --git a/tools/ocft/ocft.in b/tools/ocft/ocft.in index 80a94a0f4..c9e788ec9 100644 --- a/tools/ocft/ocft.in +++ b/tools/ocft/ocft.in @@ -1,666 +1,666 @@ #!/bin/bash # Copyright (c) 2010 Novell Inc, John Shi # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. die() { local str str="$1" echo "ERROR: $str" >&2 exit 1 } warn() { local str str="$1" echo "WARNING: $str" >&2 } parse_die() { local str str="$1" die "${agent}: line ${line_num}: ${str}" } # add quotes to string for Here Documents add_quotes() { local typ str a b typ="$1" str="$2" case "$typ" in 1) a=\'; b=\";; 2) a=\"; b=\';; esac echo "$str" | sed "s/$a/$a$b$a$b$a/g; 1 s/^/$a/; $ s/$/$a/" } # split strings explode() { local str str="$1" echo "$str" | awk -F'"' '{ if (NF > 0 && NF%2 == 0) exit(1); for (i=1; i<=NF; i++) { if (i%2 == 0) print $i; else { - split($i, str, /[[:blank:]]+/); - for (j=0; j>"$macro" else echo "$line$num" >>"$CASES_DIR/${agent}.preparse" fi done <"$opt_cfgsdir/$agent" rm -f $CASES_DIR/${agent}_macro.* } case_finish() { local host if [ -n "$sh" ]; then cat >>$sh <>$sh done echo "quit 0" >>$sh fi atexit_num=0 hosts= sh= } parse_cfg() { local agents i line stat sh trunk branch atexit_num host hosts if [ $# -eq 0 ]; then agents=($opt_cfgsdir/*) else agents=("$@") fi for agent in "${agents[@]}"; do i=0 agent="$(basename "$agent")" rm -f $CASES_DIR/*_${agent}.sh rm -f $CASES_DIR/${agent}_setup echo "Making '$agent': " preparse_cfg "$agent" while read -r line; do line_num="${line##* }" line="${line% *}" line2trunk # state switch case "${trunk[0]}" in CONFIG) case_finish stat=1 continue ;; SETUP-AGENT) case_finish stat=2 continue ;; CASE) case_finish trunk2branch sh="$CASES_DIR/${i}_${agent}.sh" echo " - case ${i}: ${branch[0]}" cat >$sh <>$sh <>$sh <>$sh <>$CASES_DIR/${agent}_setup ;; 3) host=$(echo ${trunk[0]} | awk -F@ '{print $2}') if [ -n "$host" ]; then if ! echo "$hosts" | grep -q "$host"; then hosts=$hosts$'\n'$host cat >>$sh <>$sh <>$sh <>$sh fi fi echo " # CASE statement: $line" >>$sh if [ -n "$host" ]; then echo "backbash $host <<'CMD'" >>$sh fi case "${trunk[0]}" in Var|Var@*) cat >>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh fi ;; *) parse_die "unimplemented statement: ${trunk[0]}" ;; esac done <$CASES_DIR/${agent}.preparse rm -f $CASES_DIR/${agent}.preparse rm -f $CASES_DIR/${agent}_setup case_finish done } start_test() { local sh shs agents line ret if ! cd $CASES_DIR >/dev/null 2>&1; then die "cases directory not found." fi export OCFT_VERBOSE=$opt_verbose if [ $# -eq 0 ]; then agents=($(ls -1 *.sh 2>/dev/null | sed 's/.*_\([^_]*\)\.sh$/\1/' | sort | uniq)) else agents=("$@") fi for shs in "${agents[@]}"; do for sh in $(ls -1 *_${shs}.sh 2>/dev/null | sort -n); do ./$sh ret=$? if [ $ret -eq 3 ]; then die "core function failed, break all tests." fi if [ $ret -eq 2 ]; then warn "core function failed, break all tests of '$shs'." break fi done done | while read -r line; do echo "$line" echo "$(date '+%F %T'): $line" | cat -A | sed -r 's/\^\[\[[0-9]+m|\^I|.$//g' >>ocft.log done } delete_cases() { local shs if [ $# -eq 0 ]; then rm -f $CASES_DIR/*.sh else for shs in "$@"; do rm -f $CASES_DIR/*_${shs}.sh done fi } usage() { cat <