[Ocfs2-tools-devel] [PATCH] A new ocfs2 configure file verify tool.

=?GB2312?B?uvrP/s6w?= redfuture.kernel at gmail.com
Wed Nov 28 18:26:26 PST 2007


A tool used for verify the ocfs2 configure file.Implemented using BASH
script.for detail information,see this wiki page:
http://oss.oracle.com/osswiki/OCFS2/DesignDocs/ClusterVerificationUtility
Signed-off-by: xiaowei.hu <xiaowei.hu at oracle.com>
---
 ocfs2verify/verif.sh |  661
++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 661 insertions(+), 0 deletions(-)
 create mode 100755 ocfs2verify/verif.sh

diff --git a/ocfs2verify/verif.sh b/ocfs2verify/verif.sh
new file mode 100755
index 0000000..ce13527
--- /dev/null
+++ b/ocfs2verify/verif.sh
@@ -0,0 +1,661 @@
+#!/bin/bash
+VERSION=1.2.6-6.1
+
+CONFIG_FILE="/etc/ocfs2/cluster.conf"
+TEMP_DIR="./.cluster_verif"
+ERRLOG="$TEMP_DIR/error.log"
+
+DEBUG=0
+
+SSHSUC=0
+SSH_CMD_FAILED=1
+SSHSKIP=254
+SSHERR=255
+
+USER="root"
+TIMEOUT=5
+COMMAND="hostname;cat $CONFIG_FILE"
+
+NODE_ALIVE=1
+NODE_HOSTNAME=2
+NODE_SYNC=3 #need sync -1 no need-0
+
+NODE_INDEX=1
+CLUSTER_INDEX=2
+
+IP_PORT_INDEX=1
+IP_ADDRESS_INDEX=2
+NODE_NAME_INDEX=3
+NODE_NUMBER_INDEX=4
+NODE_CLUSTER_INDEX=5
+
+CLUSTER_NAME_INDEX=1
+NODE_COUNT_INDEX=2
+
+VALID=1
+UNKNOWN=1
+INVALID=0
+#properties' names array
+NODE_PRO=(0 ip_port ip_address name number cluster)
+CLUSTER_PRO=(0 name node_count)
+
+check_ident()
+{
+if (echo $1|egrep -i
"^[[:blank:]]+$2[[:blank:]]*=[[:blank:]]*[[:alnum:]_.@]*[[:blank:]]*">/dev/null)
+then
+       return $VALID
+else
+       return $INVALID
+fi
+}
+#get corresponding value from the line,parameter:$line
+get_value()
+{
+        local index
+        local substr
+        local len
+        local count
+        len=$(expr length $1)
+        #echo $len
+        index=$(( $(expr index $1 '=') + 1 ))
+        count=$(( len - index + 1 ))
+        substr=$(expr substr $1 $index $count)
+        substr=$(expr $substr : '[[:blank:]]*\(.*\)[[:blank:]]*')
+       echo $substr
+       return 0
+}
+
+#parameter: $NODEX_INDEX/$CLUSTER_INDEX $node_num/$cluster_num
$IP_PORT_INDEX|$IP_ADDRESS_INDEX ...
+get_index()
+{
+if (( $1 == $NODE_INDEX ))
+then
+       local index
+       (( index = ($2 - 1) * 5 + $3 ))
+       #echo $index
+       return $index
+elif (( $1 == $CLUSTER_INDEX ))
+then
+       get_cluster_index $2 $3
+       return $?
+fi
+
+}
+
+#parameter: $cluster_num $CLUSTER_NAME_INDEX/$NODE_COUNT_INDEX
+get_cluster_index()
+{
+       local index
+       (( index = ($1 - 1) * 2 + $2 ))
+       #echo $index
+       return $index
+}
+
+#parameter: $node_num $NODE_ALVIE/$NODE_HOSTNAME/$NODE_SYNC
+get_ssh_index()
+{
+       local index
+       (( index = ($1 - 1) * 3 + $2 ))
+       #echo $index
+       return $index
+}
+
+#parameter: $NODE_CLUSTER_INDEX/$NODE_NAME_INDEX.... $node_num
$cluster_count
+process_node()
+{
+       local value
+       local index
+       get_index $NODE_INDEX $2 $1
+       index=$?
+       #echo $index
+       if (( $loop == 1 ))
+       then
+               value=`get_value $line`
+               #echo $value
+               nodes[$index]=$value
+       fi
+       #echo ${nodes[$index]}
+       #echo "$line  node_num=$node_num"
+       #continue
+       if (( $loop == 2 ))
+       then
+               value=${nodes[$index]}
+               case $1 in
+               #probe wrong case for the values;
+               $IP_PORT_INDEX)
+                       if ( check_port $value;(( $? == $INVALID )) )
+                       then
+                               echo -e "$line\e[0;31m......[Invalid ip_port
value]\e[0m"
+                               continue
+                       fi;;
+               $IP_ADDRESS_INDEX)
+                       if ( check_ip $value;(( $? == $INVALID )) )
+                       then
+                               echo -e "$line\e[0;31m......[Invalid
ip_address value]\e[0m"
+                               continue
+                       fi;;
+               $NODE_NAME_INDEX)
+                       if ( check_node_name $value $2;(( $? == $INVALID ))
)
+                       then
+                               echo -e "$line\e[0;31m......[Invalid node
name value]\e[0m"
+                               continue
+                       fi;;
+               $NODE_NUMBER_INDEX)
+                       if ( check_number $value $2;(( $? == $INVALID )) )
+                       then
+                               echo -e "$line\e[0;31m......[Invalid node
number value]\e[0m"
+                               continue
+                       fi;;
+               $NODE_CLUSTER_INDEX)
+                       if ( check_cluster $value $2 $3;(( $? == $INVALID ))
)
+                       then
+                               echo -e "$line\e[0;31m......[Invalid cluster
name value]\e[0m"
+                               continue
+                       fi;;
+               *)
+                       echo "BUG in process_node():please report this to
the dev team.";;
+               esac
+       fi
+
+       return 0
+}
+
+#parameter: $NODE_COUNT_INDEX/$CLUSTER_NAME_INDEX $cluster_num
+process_cluster()
+{
+       local value
+       get_index $CLUSTER_INDEX $2 $1
+       index=$?
+       #echo $index
+       value=`get_value $line`
+       #echo $value
+       if (( $loop == 1 ))
+       then
+       clusters[$index]=$value
+       fi
+       if (( $loop == 2 ))
+       then
+       value=${clusters[$index]}
+       case $1 in
+       $CLUSTER_NAME_INDEX)
+               if ( check_cluster_name $value;(( $? == $INVALID )) )
+               then
+                       echo -e "$line\e[0;31m......[Invalid cluster name
value]\e[0m"
+                       continue
+               fi;;
+       $NODE_COUNT_INDEX)
+               if ( check_node_count $value $2;(( $? == $INVALID )) )
+               then
+                       echo -e "$line\e[0;31m......[Invalid node_count
value,should be
${cluster_st[$2]}]\e[0m"
+                       continue
+               fi;;
+       *)
+               echo "BUG in process_cluster():please report this to the dev
team.";;
+       esac
+       fi
+       #echo ${nodes[$index]}
+       #echo "$line  node_num=$node_num"
+       #continue
+       return 0
+}
+
+#parameter
+check_port()
+{
+#echo "---$1---"
+if ( [[ -z $1 ]] || (($1 < 1024)) || (($1 > 65535)) )
+then
+       return $INVALID
+else
+       return $VALID
+fi
+}
+
+check_ip()
+{
+local part1
+local part2
+local part3
+local part4
+#echo "---$1---"
+if (echo $1|egrep "^([0-9]{1,3}\.){3}[0-9]{1,3}$">/dev/null)
+then
+       part1=`echo $1|awk 'BEGIN{FS="."}{print $1}'`
+       part2=`echo $1|awk 'BEGIN{FS="."}{print $2}'`
+       part3=`echo $1|awk 'BEGIN{FS="."}{print $3}'`
+       part4=`echo $1|awk 'BEGIN{FS="."}{print $4}'`
+       #echo "$part1-$part2-$part3-$part4"
+       if [[ $part1 < 255 ]] #&& $part2 < 255 && $part3 < 255 && $part4 <
255 ]]
+       then
+               return $VALID
+       fi
+fi
+       return $INVALID
+}
+
+#parameter $value $node_num
+check_number()
+{
+local ret
+if ( [[ -n $1 ]] && (( $1 < 255 || $1 > 0 )) )
+then
+       for (( i=1;i < $2;i += 1 ))
+       do
+       get_index $NODE_INDEX $i $NODE_NUMBER_INDEX
+       ret=$?
+       if (( $1 == ${nodes[$ret]} ))
+       then
+               return $INVALID
+       fi
+       done
+       return $VALID
+fi
+       return $INVALID
+}
+
+#para: $value $node_num
+check_node_name()
+{
+get_ssh_index $2 $NODE_HOSTNAME
+if [[ $1 = ${nodes_ssh[$?]} ]]
+then
+       return $VALID
+elif (echo $1|egrep ".+">/dev/null)
+then
+       return $UNKNOWN
+fi
+       return $INVALID
+}
+
+#para $value $cluster_count
+check_cluster()
+{
+       for (( i=1;i <= $2;i += 1 ))
+       do
+       get_index $CLUSTER_INDEX $i $CLUSTER_NAME_INDEX
+       if [[ $1 = ${clusters[$?]} ]]
+       then
+       return $VALID
+       fi
+       done
+
+       return $INVALID
+}
+
+check_cluster_name()
+{
+if (echo $1|egrep ".+">/dev/null)
+# to be changed,check using ssh
+then
+       return $VALID
+fi
+       return $INVALID
+}
+
+#para:$value $cluster_num
+check_node_count()
+{
+if (( $1 == ${cluster_st[$2]} ))
+then
+       return $VALID
+fi
+       return $INVALID
+}
+
+#para:$NODE_INDEX/$CLUSTER_INDEX $node_num/$cluster_num
+missing_warning()
+{
+local proindex
+local index
+if (( $1 == $NODE_INDEX ))
+then
+       for (( proindex=1; proindex <= $NODE_CLUSTER_INDEX; proindex++
))
+       do
+               get_index $1 $2 $proindex
+               index=$?
+               if [[ -z ${nodes[$index]} ]]
+               then
+                       echo -e "\t\e[0;33mWarning:missing
${NODE_PRO[$proindex]} for this
node\e[0m"
+               fi
+       done
+elif (( $1 == $CLUSTER_INDEX ))
+then
+       for (( proindex=1; proindex <= $NODE_COUNT_INDEX; proindex++
))
+       do
+               get_index $1 $2 $proindex
+               index=$?
+               if [[ -z ${clusters[$index]} ]]
+               then
+                       echo -e "\t\e[0;33mWarning:missing
${CLUSTER_PRO[$proindex]} for
this cluster\e[0m"
+               fi
+       done
+else
+       echo "BUG:invalid index in missing_warning()"
+fi
+
+}
+
+get_ssh()
+{
+if ( check_ip $1;(( $? == $VALID )) )
+then
+       #echo "connecting"
+       if [[ -f "$TEMP_DIR/$value" ]]
+       then
+               echo -e "$line\e[0;31m......[Duplicated ip_address!]\e[0m"
+               continue
+       else
+               #echo "sshing.............."
+               #echo "$TEMP_DIR/$1"
+               #echo "$COMMAND"
+               ssh 255.255.255.255>/dev/null 2>&1
+               if (( $? == 1 ))
+               then
+                       ssh -oConnectTimeout=$TIMEOUT "$USER@$1" $COMMAND 1>
"$TEMP_DIR/$1"
2>>$ERRLOG
+                       ret=$?
+                       tail -2 $ERRLOG |grep 'unreachable'
+                       if (( $? == 0 ))
+                       then
+                               return $SSHSKIP
+                       else
+                               return $ret
+                       fi
+               else
+                       ssh -oConnectTimeout=$TIMEOUT "$USER@$1" $COMMAND 1>
"$TEMP_DIR/$1"
2>>$ERRLOG
+                       return $?
+               fi
+       fi
+fi
+return $SSHSKIP
+}
+
+
+if [[ -r $CONFIG_FILE ]]
+then
+       if [[ -d "$TEMP_DIR" ]]
+       then
+               rm -f -r $TEMP_DIR
+       fi
+       mkdir -p $TEMP_DIR
+       IFS=;
+       #declare value
+       #declare index
+       declare -a cluster_st
+       declare -a clusters
+       declare -a nodes
+       declare -a nodes_ssh
+       cluster_count=$INVALID
+       node_count=$INVALID
+
+       loop=1
+       # to determine how to display,we need know some information advance.
+       # so at least loop twice.
+       while (( $loop <= 2 ))
+       do
+
+       cluster_num=$INVALID
+       node_num=$INVALID
+       node_match=$INVALID
+       cluster_match=$INVALID
+       match=$INVALID
+       node_err=$INVALID
+       cluster_err=$INVALID
+       section=$INVALID
+
+       match=$INVALID
+       node_match=$INVALID
+       cluster_match=$INVALID
+       check_missing=$INVALID
+
+       while read line
+       do
+
+               if (echo $line|egrep "^[[:blank:]]*#+">/dev/null || \
+                   echo $line|egrep "^[[:blank:]]*$">/dev/null)
+               then
+                       #remove blank and comment lines
+                       #echo "$line"
+                       continue
+               fi
+               if (echo $line|egrep -i "^node:[[:blank:]]*">/dev/null)
+               then
+                       (( node_num++ ))
+                       (( node_err=$node_num ))
+                       (( cluster_err=$cluster_num ))
+                       node_match=$VALID
+                       cluster_match=$INVALID
+                       section=$NODE_INDEX
+                       check_missing=$NODE_INDEX
+                       #echo $node_err
+                       if (( $loop == 2))
+                       then
+                               get_ssh_index $node_num $NODE_ALIVE
+                               if (( ${nodes_ssh[$?]} <= $SSH_CMD_FAILED ))
+                               then
+                                       get_ssh_index $node_num $NODE_SYNC
+                                       if (( ${nodes_ssh[$?]} == $VALID ))
+                                       then
+                                       echo -e "$line \e[0;32m[ALIVE] but
\e[0;33m[Need
Synchronization]\e[0m"
+                                       else
+                                       echo -e "$line \e[0;32m[ALIVE] and
\e[0;32m[No Need
Synchronization]\e[0m"
+                                       fi
+                               else
+                                       echo -e "$line \e[0;33m[
SKIPED.Unreachable through SSH]\e[0m"
+                               fi
+                       fi
+                       continue
+               fi
+
+               if (echo $line|egrep -i "^cluster:[[:blank:]]*">/dev/null)
+               then
+                       (( cluster_num++ ))
+                       (( node_err=$node_num ))
+                       (( cluster_err=$cluster_num ))
+                       #echo $cluster_err
+                       node_match=$INVALID
+                       cluster_match=$VALID
+                       section=$CLUSTER_INDEX
+                       check_missing=$CLUSTER_INDEX
+                       if (( $loop == 2))
+                       then
+                               echo "$line"
+                       fi
+                       continue
+               fi
+
+               if [[ $loop == 2 && $check_missing != $INVALID ]]
+               then
+                       if (( $check_missing == $NODE_INDEX ))
+                       then
+                               missing_warning $NODE_INDEX $node_num
+                       elif (( $check_missing == $CLUSTER_INDEX ))
+                       then
+                               missing_warning $CLUSTER_INDEX $cluster_num
+                       fi
+
+                       check_missing=$INVALID
+               fi
+
+               if [[ $node_err == $node_num && $cluster_err == $cluster_num
]]
+               then
+
+                       if ( check_ident $line "ip_port";(( $? == $VALID ))
)
+                       then
+                               match=$VALID
+                               process_node $IP_PORT_INDEX $node_num
+                       elif ( check_ident $line "ip_address";(( $? ==
$VALID )) )
+                       then
+                               match=$VALID
+                               process_node $IP_ADDRESS_INDEX $node_num
+                       elif ( check_ident $line "number";(( $? == $VALID ))
)
+                       then
+                               match=$VALID
+                               process_node $NODE_NUMBER_INDEX $node_num
+                       elif ( check_ident $line "cluster";(( $? == $VALID
)) )
+                       then
+                               match=$VALID
+                               process_node $NODE_CLUSTER_INDEX $node_num
$cluster_count
+                       elif ( check_ident $line "name";(( $? == $VALID )) )
+                       then
+                               match=$VALID
+                               if (( section == $NODE_INDEX ))
+                               then
+                                       process_node $NODE_NAME_INDEX
$node_num
+                               elif (( section == $CLUSTER_INDEX ))
+                               then
+                                       process_cluster $CLUSTER_NAME_INDEX
$cluster_num
+                               else
+                               if (( $loop == 2 ))
+                               then
+                                       echo -e "$line  \e[31m[ERROR:The
\"name\" property \
+                                       should in a valid node or cluster
section!]\e[0m"
+                               fi
+                                       continue
+                               fi
+
+                       elif ( check_ident $line "node_count";(( $? ==
$VALID )) )
+                       then
+                               match=$VALID
+                               process_cluster $NODE_COUNT_INDEX
$cluster_num
+                       else
+                               match=$INVALID
+                               node_match=$INVALID
+                               cluster_match=$INVALID
+                       fi
+               fi
+
+               #if (echo $line|egrep "[[:blank:]]*[cluster
node]*:[[:blank:]]*">/dev/null)
+               #then
+               #       (( section++ ))
+               #       echo $section
+                       #echo "$line"  #node_num=$node_num
+               #fi
+
+               #for all lines,determine how to display
+               if (( $loop == 2))
+               then
+
+                       if (( node_match == $INVALID && cluster_match ==
$INVALID && match
== $INVALID ))
+                       then
+                               if (echo $line|egrep -i
"[[:blank:]]*[cluster
node]*:[[:blank:]]*">/dev/null)
+                               # unknown identifer and willing it to be a
node: or cluster:
+                               then
+                                       (( node_err++ ))
+                                       (( cluster_err++ ))
+                               else
+                                       echo -e "$line......\e[0;31m[Unknown
identifer]\e[0m"
+                                       continue
+                               fi
+                       fi
+
+                       if (( node_err > node_num||cluster_err > cluster_num
))
+                       then
+                               echo -e "\e[0;31m$line......[Invalid
section]\e[0m"
+                               continue
+                       fi
+                       if (( $DEBUG == 1 ))
+                       then
+                               echo "$line  node_num=$node_num
cluster_num=$cluster_num"
+                       else
+                               echo "$line"
+                       fi
+               fi
+
+
+       done < $CONFIG_FILE
+
+       #get ssh in loop1
+       if (( $loop == 1 ))
+       then
+               node_count=$node_num
+               cluster_count=$cluster_num
+
+               for (( j=1;j <= $cluster_count;j += 1 ))
+               do
+                       cluster_st[$j]=0
+               done
+
+               for ((i=1;i <= (( $node_num ));i += 1 ))
+               do
+                       #echo ${nodes[$i]}
+                       get_index $NODE_INDEX $i $IP_ADDRESS_INDEX
+                       ip=${nodes[$?]}
+                       if (( $DEBUG == $VALID ))
+                       then
+                               echo "Connecting node $ip."
+                       fi
+                       get_ssh $ip
+                       ssh_ret=$?
+                       #echo $ssh_ret
+                       get_ssh_index $i $NODE_ALIVE
+                       ssh_index=$?
+                       nodes_ssh[$ssh_index]=$ssh_ret
+
+                       if (( $ssh_ret == $SSHERR ))
+                       then
+                               echo -e "\e[0;33mThe node whose ip address
is $ip is
unreachable.[SKIPED]\e[0m"
+                       elif (( $ssh_ret == $SSHSKIP ))
+                       then
+                               echo -e "\e[0;33mThe node whose ip address
is $ip is
invalid.[SKIPED]\e[0m"
+                       else
+                               echo -e "\e[0;32mNode $ip connected.\e[0m"
+                               get_ssh_index $i $NODE_HOSTNAME
+                               ssh_index=$?
+                               nodes_ssh[$ssh_index]=`head -1
"$TEMP_DIR/$ip"`
+                               #echo ${nodes_ssh[$ssh_index]}
+                               if (( $ssh_ret == $SSH_CMD_FAILED ))
+                               then
+                                       echo "File $CONFIG_FILE doesn't
exist on node $ip"
+                               fi
+                               sed '1d' "$TEMP_DIR/$ip" >| "$TEMP_DIR/$i"
2>|$ERRLOG
+                               rm -f "$TEMP_DIR/$ip" 1>/dev/null 2>|$ERRLOG
+                               get_ssh_index $i $NODE_SYNC
+                               ssh_index=$?
+                               diff -B --brief "$CONFIG_FILE"
"$TEMP_DIR/$i" 1>/dev/null 2>|
$ERRLOG
+                               nodes_ssh[$ssh_index]=$?
+                       fi
+
+                       get_index $NODE_INDEX $i $NODE_CLUSTER_INDEX
+                       cluster=${nodes[$?]}
+                       #echo "---$cluster---"
+
+                       for (( j=1;j <= $cluster_count;j += 1 ))
+                       do
+                               get_index $CLUSTER_INDEX $j
$CLUSTER_NAME_INDEX
+                               if [[ $cluster = ${clusters[$?]} ]]
+                               then
+                                       #echo ${cluster_st[$j]}
+                                       (( cluster_st[$j] += 1 ))
+                                       #echo ${cluster_st[$j]}
+                               fi
+                       done
+               done
+       fi
+
+       if (( $DEBUG == 1 ))
+       then
+               echo "------Array:nodes:------"
+               for ((i=1;i <= (( $node_count*5 ));i += 1 ))
+               do
+                       echo ${nodes[$i]}
+               done
+               echo "------Array:clusters:------"
+               for ((i=1;i <= (( $cluster_count*2 ));i += 1 ))
+               do
+                       echo ${clusters[$i]}
+               done
+               echo "------Array:nodes_ssh:------"
+               for ((i=1;i <= (( $node_count*3 ));i += 1 ))
+               do
+                       echo ${nodes_ssh[$i]}
+               done
+       fi
+       (( loop = $loop + 1 ))
+       done
+
+       #rm -f -r $TEMP_DIR
+
+else
+       echo -e "\e[0;31mERROR:configure file:$CONFIG_FILE does not exist or
not readable now.\e[0m"
+fi
+exit 0
-- 
1.5.3.4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/ocfs2-tools-devel/attachments/20071129/fdf2880c/attachment-0001.html


More information about the Ocfs2-tools-devel mailing list