Merge "Fix the proc_kill ocf helper func"

This commit is contained in:
Jenkins 2015-12-29 11:40:28 +00:00 committed by Gerrit Code Review
commit be585ad0db
2 changed files with 51 additions and 1 deletions

View File

@ -127,7 +127,7 @@ proc_stop()
if [ -n "${pid}" ]; then
ocf_log info "${LH} Stopping ${service_name}"
proc_kill "${pid}" "${service_name}" $stop_count
proc_kill "${pid}" "${service_name}" SIGTERM $stop_count
if [ $? -ne 0 ]; then
# SIGTERM failed, send a single SIGKILL
proc_kill "${pid}" "${service_name}" SIGKILL 1 2

50
tests/bats/ocf-fuel-funcs Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env bats
# For testing use bats framework -
# https://github.com/sstephenson/bats
fms="$BATS_TEST_DIRNAME/../../files/fuel-ha-utils/ocf/ocf-fuel-funcs"
load "$fms"
@test "Check proc_kill params" {
# $1 - pid of the process to try and kill
# $2 - service name used for logging
# $3 - signal to use, defaults to SIGTERM
# $4 - number of retries, defaults to 5
# $5 - time to sleep between retries, defaults to 2
ocf_log(){
true
}
ocf_run(){
echo $@
}
sleep(){
true
}
pid=$$
pgrp=$(ps -o pgid= ${pid} | tr -d '[[:space:]]')
echo "When used with default params"
expected="pkill -SIGTERM -g $pgrp"
run proc_kill $pid
echo -e "Actual:\n${output}"
for l in {0..4}; do
echo "Expected line $l: ${expected}"
[ "${lines[$l]}" = "${expected}" ]
done
echo "When used with correct params"
expected="pkill -SIGSTOP -g $pgrp"
run proc_kill $pid foo SIGSTOP 2
echo "Expected line 1: ${expected}"
echo -e "Actual:\n${output}"
[ "${lines[1]}" = "${expected}" ]
echo "When misused with wrong params"
expected="pkill -1 -g $pgrp"
echo "Expected line 4: ${expected}"
run proc_kill $pid foo 1
echo "Actual: ${output}"
[ "${lines[4]}" = "${expected}" ]
}