mirror of https://github.com/schoebel/mars
test_suite: refactoring
This commit is contained in:
parent
87f7c94260
commit
9678782188
|
@ -22,14 +22,15 @@
|
||||||
## defaults for module net
|
## defaults for module net
|
||||||
|
|
||||||
## array containing the shell commands manipulating the network connection
|
## array containing the shell commands manipulating the network connection
|
||||||
|
## The string remote_host must be replaced by the actual host name at runtime
|
||||||
declare -g -A net_impact_cmd
|
declare -g -A net_impact_cmd
|
||||||
net_impact_cmd=(\
|
net_impact_cmd=(\
|
||||||
["on"]="net_impact_cmd_on_not_defined" \
|
["on"]="iptables -I INPUT -s remote_host -j DROP && iptables -I OUTPUT -d remote_host -j DROP" \
|
||||||
["off"]="net_impact_cmd_off_not_defined" \
|
["off"]="iptables -D INPUT -s remote_host -j DROP && iptables -D OUTPUT -d remote_host -j DROP" \
|
||||||
["ctrl_on"]="net_impact_cmd_ctrl_on_not_defined" \
|
["check_on"]="ping -c1 -W5 remote_host" \
|
||||||
["ctrl_on_rc"]="net_impact_cmd_ctrl_on_rc_not_defined" \
|
["check_on_rc"]=1 \
|
||||||
["ctrl_off"]="net_impact_cmd_ctrl_off_not_defined" \
|
["check_off"]="ping -c1 -W5 remote_host" \
|
||||||
["ctrl_off_rc"]="net_impact_cmd_ctrl_off_rc_not_defined" \
|
["check_off_rc"]=0 \
|
||||||
)
|
)
|
||||||
|
|
||||||
## time to let the data device writer run
|
## time to let the data device writer run
|
||||||
|
|
|
@ -29,52 +29,57 @@ function net_run
|
||||||
|
|
||||||
net_check_variables
|
net_check_variables
|
||||||
|
|
||||||
# replace string remote_host with $secondary_host
|
net_do_impact_cmd $primary_host "check_off" "remote_host:$secondary_host"
|
||||||
declare -A impact_cmd
|
|
||||||
eval impact_cmd=(\
|
|
||||||
$(for x in ${!net_impact_cmd[@]};do
|
|
||||||
printf "[$x]='${net_impact_cmd[$x]//remote_host/$secondary_host}' ";
|
|
||||||
done)\
|
|
||||||
)
|
|
||||||
|
|
||||||
net_do_impact_cmd $primary_host "impact_cmd" "check_off"
|
### mount_mount_data_device
|
||||||
|
### resource_clear_data_device $primary_host $res
|
||||||
|
###
|
||||||
|
### lib_rw_start_writing_data_device $primary_host "writer_pid" \
|
||||||
|
### "writer_script" 0 1 $res
|
||||||
|
###
|
||||||
|
### sleep $net_time_data_dev_writer
|
||||||
|
|
||||||
mount_mount_data_device
|
net_do_impact_cmd $primary_host "on" "remote_host:$secondary_host"
|
||||||
resource_clear_data_device $primary_host $res
|
|
||||||
|
|
||||||
lib_rw_start_writing_data_device $primary_host "writer_pid" \
|
### sleep $net_time_data_dev_writer
|
||||||
"writer_script" 0 1 $res
|
|
||||||
|
|
||||||
sleep $net_time_data_dev_writer
|
net_do_impact_cmd $primary_host "off" "remote_host:$secondary_host"
|
||||||
|
|
||||||
net_do_impact_cmd $primary_host "impact_cmd" "on"
|
### lib_rw_stop_writing_data_device $primary_host $writer_script "write_count"
|
||||||
|
### main_error_recovery_functions["lib_rw_stop_scripts"]=
|
||||||
sleep $net_time_data_dev_writer
|
###
|
||||||
|
### mount_umount_data_device $primary_host $res
|
||||||
net_do_impact_cmd $primary_host "impact_cmd" "off"
|
### lib_wait_for_secondary_to_become_uptodate_and_cmp_cksums "net" \
|
||||||
|
### $secondary_host $primary_host $res $dev 0
|
||||||
lib_rw_stop_writing_data_device $primary_host $writer_script "write_count"
|
|
||||||
main_error_recovery_functions["lib_rw_stop_scripts"]=
|
|
||||||
|
|
||||||
mount_umount_data_device $primary_host $res
|
|
||||||
lib_wait_for_secondary_to_become_uptodate_and_cmp_cksums "net" \
|
|
||||||
$secondary_host $primary_host $res $dev 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function net_do_impact_cmd
|
function net_do_impact_cmd
|
||||||
{
|
{
|
||||||
local host=$1 cmd_array_varname="$2" array_index="$3"
|
local host=$1 array_index="$2" replace_expression="$3"
|
||||||
local declare_string="$(declare -p $cmd_array_varname)"
|
local cmd="${net_impact_cmd[$array_index]}"
|
||||||
eval declare -A cmd_array="${declare_string#*$cmd_array_varname=}"
|
local pattern="${replace_expression%:*}" replace="${replace_expression#*:}"
|
||||||
local cmd="${cmd_array[$array_index]}"
|
local rc_req=0 check_array_index var
|
||||||
local rc_req=0 check_array_index
|
|
||||||
|
if [ -z "$cmd" ]; then
|
||||||
|
lib_exit 1 "no value to index $array_index in array net_impact_cmd"
|
||||||
|
fi
|
||||||
|
for var in pattern replace; do
|
||||||
|
local x
|
||||||
|
eval x='$'$var
|
||||||
|
if [ -z "$x" ]; then
|
||||||
|
lib_exit 1 "cannot determine $var in replace_expression $replace_expression"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
cmd="${cmd//$pattern/$replace}"
|
||||||
|
|
||||||
|
|
||||||
case $array_index in #(((
|
case $array_index in #(((
|
||||||
check*) rc_req=${cmd_array[${array_index}_rc]}
|
check*) rc_req=${net_impact_cmd[${array_index}_rc]}
|
||||||
;;
|
;;
|
||||||
on|off) check_array_index=check_$array_index
|
on|off) check_array_index=check_$array_index
|
||||||
if [ $array_index = "on" ]; then
|
if [ $array_index = "on" ]; then
|
||||||
main_error_recovery_functions["net_do_impact_cmd"]="$host cmd_array off"
|
main_error_recovery_functions["net_do_impact_cmd"]="$host off $replace_expression"
|
||||||
else
|
else
|
||||||
main_error_recovery_functions["net_do_impact_cmd"]=
|
main_error_recovery_functions["net_do_impact_cmd"]=
|
||||||
fi
|
fi
|
||||||
|
@ -90,10 +95,10 @@ function net_do_impact_cmd
|
||||||
if [ \( $rc -eq 0 -a $rc_req -ne 0 \) \
|
if [ \( $rc -eq 0 -a $rc_req -ne 0 \) \
|
||||||
-o \( $rc -ne 0 -a $rc_req -eq 0 \) ]
|
-o \( $rc -ne 0 -a $rc_req -eq 0 \) ]
|
||||||
then
|
then
|
||||||
lib_exit 1 "command $impact_cmd on $host returned unexpectedly $rc"
|
lib_exit 1 "command $cmd on $host returned unexpectedly $rc"
|
||||||
fi
|
fi
|
||||||
if [ -n "$check_array_index" ];then
|
if [ -n "$check_array_index" ];then
|
||||||
net_do_impact_cmd $host cmd_array $check_array_index
|
net_do_impact_cmd $host $check_array_index "$replace_expression"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,4 @@
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
|
|
||||||
net_impact_cmd=(\
|
|
||||||
["on"]="iptables -I INPUT -s remote_host -j DROP && iptables -I OUTPUT -d remote_host -j DROP" \
|
|
||||||
["off"]="iptables -D INPUT -s remote_host -j DROP && iptables -D OUTPUT -d remote_host -j DROP" \
|
|
||||||
["check_on"]="ping -c1 -W5 remote_host" \
|
|
||||||
["check_on_rc"]=1 \
|
|
||||||
["check_off"]="ping -c1 -W5 remote_host" \
|
|
||||||
["check_off_rc"]=0 \
|
|
||||||
)
|
|
||||||
|
|
||||||
run_list="resource_prepare resource_run_first net_run"
|
run_list="resource_prepare resource_run_first net_run"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue