mirror of
https://github.com/schoebel/mars
synced 2025-02-09 16:47:55 +00:00
test_suite: refactoring
This commit is contained in:
parent
87f7c94260
commit
9678782188
@ -22,14 +22,15 @@
|
||||
## defaults for module net
|
||||
|
||||
## 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
|
||||
net_impact_cmd=(\
|
||||
["on"]="net_impact_cmd_on_not_defined" \
|
||||
["off"]="net_impact_cmd_off_not_defined" \
|
||||
["ctrl_on"]="net_impact_cmd_ctrl_on_not_defined" \
|
||||
["ctrl_on_rc"]="net_impact_cmd_ctrl_on_rc_not_defined" \
|
||||
["ctrl_off"]="net_impact_cmd_ctrl_off_not_defined" \
|
||||
["ctrl_off_rc"]="net_impact_cmd_ctrl_off_rc_not_defined" \
|
||||
["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 \
|
||||
)
|
||||
|
||||
## time to let the data device writer run
|
||||
|
@ -29,52 +29,57 @@ function net_run
|
||||
|
||||
net_check_variables
|
||||
|
||||
# replace string remote_host with $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"
|
||||
net_do_impact_cmd $primary_host "check_off" "remote_host:$secondary_host"
|
||||
|
||||
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
|
||||
### 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
|
||||
|
||||
sleep $net_time_data_dev_writer
|
||||
net_do_impact_cmd $primary_host "on" "remote_host:$secondary_host"
|
||||
|
||||
net_do_impact_cmd $primary_host "impact_cmd" "on"
|
||||
### sleep $net_time_data_dev_writer
|
||||
|
||||
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" "off"
|
||||
|
||||
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
|
||||
### 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
|
||||
{
|
||||
local host=$1 cmd_array_varname="$2" array_index="$3"
|
||||
local declare_string="$(declare -p $cmd_array_varname)"
|
||||
eval declare -A cmd_array="${declare_string#*$cmd_array_varname=}"
|
||||
local cmd="${cmd_array[$array_index]}"
|
||||
local rc_req=0 check_array_index
|
||||
local host=$1 array_index="$2" replace_expression="$3"
|
||||
local cmd="${net_impact_cmd[$array_index]}"
|
||||
local pattern="${replace_expression%:*}" replace="${replace_expression#*:}"
|
||||
local rc_req=0 check_array_index var
|
||||
|
||||
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 #(((
|
||||
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
|
||||
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
|
||||
main_error_recovery_functions["net_do_impact_cmd"]=
|
||||
fi
|
||||
@ -90,10 +95,10 @@ function net_do_impact_cmd
|
||||
if [ \( $rc -eq 0 -a $rc_req -ne 0 \) \
|
||||
-o \( $rc -ne 0 -a $rc_req -eq 0 \) ]
|
||||
then
|
||||
lib_exit 1 "command $impact_cmd on $host returned unexpectedly $rc"
|
||||
lib_exit 1 "command $cmd on $host returned unexpectedly $rc"
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user