Skip to content

Commit

Permalink
Fix: agents: handle dampening parameter consistently and correctly
Browse files Browse the repository at this point in the history
Always quote variable when used (in case value incorrectly contains
whitespace), always use attrd_updater -B instead of -U to ensure dampening is
truly reloadable, and always mark parameter as reloadable in metadata.

Also, dampening doesn't need to be passed with attrd_updater -D.
  • Loading branch information
kgaillot committed Dec 7, 2023
1 parent 0f6fbd5 commit 1f8e3d6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
9 changes: 4 additions & 5 deletions agents/ocf/HealthCPU.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ healthcpu_monitor() {

if [ $IDLE -lt ${OCF_RESKEY_red_limit} ] ; then
# echo "System state RED!"
attrd_updater -n "#health-cpu" -B "red" -d ${OCF_RESKEY_dampening}
attrd_updater -n "#health-cpu" -B "red" -d "${OCF_RESKEY_dampening}"
return $OCF_SUCCESS
fi

if [ $IDLE -lt ${OCF_RESKEY_yellow_limit} ] ; then
# echo "System state yellow."
attrd_updater -n "#health-cpu" -B "yellow" -d ${OCF_RESKEY_dampening}
attrd_updater -n "#health-cpu" -B "yellow" -d "${OCF_RESKEY_dampening}"
else
# echo "System state green."
attrd_updater -n "#health-cpu" -B "green" -d ${OCF_RESKEY_dampening}
attrd_updater -n "#health-cpu" -B "green" -d "${OCF_RESKEY_dampening}"
fi

return $OCF_SUCCESS
Expand All @@ -145,8 +145,7 @@ healthcpu_monitor() {
}

healthcpu_reload_agent() {
# No action required
:;
return $OCF_SUCCESS
}

healthcpu_validate() {
Expand Down
16 changes: 8 additions & 8 deletions agents/ocf/HealthSMART.in
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,25 @@ check_temperature() {

if [ $1 -lt ${lower_red_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} too cold: ${1} C"
attrd_updater -n "#health-smart" -U "red" -d "${OCF_RESKEY_dampen}"
attrd_updater -n "#health-smart" -B "red" -d "${OCF_RESKEY_dampen}"
return 1
fi

if [ $1 -gt ${upper_red_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} too hot: ${1} C"
attrd_updater -n "#health-smart" -U "red" -d "${OCF_RESKEY_dampen}"
attrd_updater -n "#health-smart" -B "red" -d "${OCF_RESKEY_dampen}"
return 1
fi

if [ $1 -lt ${lower_yellow_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} quite cold: ${1} C"
attrd_updater -n "#health-smart" -U "yellow" -d "${OCF_RESKEY_dampen}"
attrd_updater -n "#health-smart" -B "yellow" -d "${OCF_RESKEY_dampen}"
return 1
fi

if [ $1 -gt ${upper_yellow_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} quite hot: ${1} C"
attrd_updater -n "#health-smart" -U "yellow" -d "${OCF_RESKEY_dampen}"
attrd_updater -n "#health-smart" -B "yellow" -d "${OCF_RESKEY_dampen}"
return 1
fi
}
Expand Down Expand Up @@ -244,7 +244,7 @@ HealthSMART_start() {
}

HealthSMART_stop() {
attrd_updater -D -n "#health-smart" -d "${OCF_RESKEY_dampen}"
attrd_updater -D -n "#health-smart"

rm "${OCF_RESKEY_state}"

Expand Down Expand Up @@ -278,7 +278,7 @@ HealthSMART_monitor() {
# Check overall S.M.A.R.T. status
"${OCF_RESKEY_smartctl}" -d "${DEVICE}" -H ${DRIVE} | grep -q "SMART overall-health self-assessment test result: PASSED"
if [ $? -ne 0 ]; then
attrd_updater -n "#health-smart" -U "red" -d "${OCF_RESKEY_dampen}"
attrd_updater -n "#health-smart" -B "red" -d "${OCF_RESKEY_dampen}"
return $OCF_SUCCESS
fi

Expand All @@ -290,7 +290,7 @@ HealthSMART_monitor() {
else
"${OCF_RESKEY_smartctl}" -H "${DRIVE}" | grep -q "SMART overall-health self-assessment test result: PASSED"
if [ $? -ne 0 ]; then
attrd_updater -n "#health-smart" -U "red" -d "${OCF_RESKEY_dampen}"
attrd_updater -n "#health-smart" -B "red" -d "${OCF_RESKEY_dampen}"
return $OCF_SUCCESS
fi

Expand All @@ -301,7 +301,7 @@ HealthSMART_monitor() {
fi
done

attrd_updater -n "#health-smart" -U "green" -d "${OCF_RESKEY_dampen}"
attrd_updater -n "#health-smart" -B "green" -d "${OCF_RESKEY_dampen}"
return $OCF_SUCCESS
fi

Expand Down
20 changes: 12 additions & 8 deletions agents/ocf/ifspeed.in
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Can be used to tune how big attribute value will be.
<content type="integer" default="${OCF_RESKEY_weight_base_default}"/>
</parameter>
<parameter name="dampen">
<parameter name="dampen" reloadable="1">
<longdesc lang="en">
The time to wait (dampening) for further changes to occur.
</longdesc>
Expand All @@ -147,14 +147,15 @@ Log more verbosely.
<action name="monitor" depth="0" timeout="30s" interval="10s"/>
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" depth="0" />
<action name="reload-agent" timeout="20s" />
</actions>
</resource-agent>
END
}

usage() {
cat <<END
Usage: $0 {start|stop|monitor|validate-all|meta-data}
Usage: $0 {start|stop|monitor|validate-all|meta-data|reload-agent}
Expects to have a fully populated OCF RA-compliant environment set.
END
Expand All @@ -172,7 +173,7 @@ start() {

stop() {
ha_pseudo_resource "${ha_pseudo_resource_name}" stop
attrd_updater -D -n "${OCF_RESKEY_name}" -d "${OCF_RESKEY_dampen}" ${attrd_options}
attrd_updater -D -n "${OCF_RESKEY_name}" ${attrd_options}
return $OCF_SUCCESS
}

Expand Down Expand Up @@ -491,11 +492,7 @@ update() {
speed=$( iface_get_speed "${nic}" )

: $(( score = speed * ${OCF_RESKEY_weight_base} / 1000 ))
if [ "$__OCF_ACTION" = "start" ] ; then
attrd_updater -n "${OCF_RESKEY_name}" -B "${score}" -d "${OCF_RESKEY_dampen}" ${attrd_options}
else
attrd_updater -n "${OCF_RESKEY_name}" -v "${score}" -d "${OCF_RESKEY_dampen}" ${attrd_options}
fi
attrd_updater -n "${OCF_RESKEY_name}" -B "${score}" -d "${OCF_RESKEY_dampen}" ${attrd_options}
rc=$?
case ${rc} in
0)
Expand All @@ -508,6 +505,10 @@ update() {
return ${rc}
}

reload_agent() {
return $OCF_SUCCESS
}

case $__OCF_ACTION in
meta-data)
meta_data
Expand Down Expand Up @@ -542,6 +543,9 @@ case "$__OCF_ACTION" in
validate-all)
validate "$OCF_CHECK_LEVEL"
;;
reload-agent)
reload_agent
;;
*)
usage
exit $OCF_ERR_UNIMPLEMENTED
Expand Down
13 changes: 4 additions & 9 deletions agents/ocf/ping.in
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ping_stop() {

rm -f "${OCF_RESKEY_pidfile}"

attrd_updater -D -n "$OCF_RESKEY_name" -d "$OCF_RESKEY_dampen"
attrd_updater -D -n "$OCF_RESKEY_name"

return $OCF_SUCCESS
}
Expand Down Expand Up @@ -237,8 +237,7 @@ ping_validate() {
}

ping_reload_agent() {
# No action required
:;
return $OCF_SUCCESS
}

fping_check() {
Expand Down Expand Up @@ -319,11 +318,7 @@ ping_update() {
fi

score=$(expr $active \* $OCF_RESKEY_multiplier)
if [ "$__OCF_ACTION" = "start" ] ; then
attrd_updater -n "$OCF_RESKEY_name" -B "$score" -d "$OCF_RESKEY_dampen"
else
attrd_updater -n "$OCF_RESKEY_name" -U "$score" -d "$OCF_RESKEY_dampen"
fi
attrd_updater -n "$OCF_RESKEY_name" -B "$score" -d "$OCF_RESKEY_dampen"
rc=$?
case $rc in
0) ping_conditional_log debug "Updated $OCF_RESKEY_name = $score" ;;
Expand Down Expand Up @@ -423,7 +418,7 @@ start) ping_start;;
stop) ping_stop;;
monitor) ping_monitor;;
validate-all) ping_validate;;
reload-agent) ping_reload_agent;;
reload-agent) ping_reload_agent;;
usage|help) ping_usage
exit $OCF_SUCCESS
;;
Expand Down

0 comments on commit 1f8e3d6

Please sign in to comment.