Skip to content

Commit

Permalink
Refactor watchdog test case
Browse files Browse the repository at this point in the history
 - one prerequisite: Set watchdog config variable before starting the tests
  • Loading branch information
LiaoU3 committed Apr 17, 2024
1 parent 1e71971 commit 9c710a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 3 additions & 4 deletions providers/base/bin/watchdog_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ def watchdog_service_check():


def main():
runtime_watchdog_usec = get_systemd_wdt_usec()
systemd_wdt_configured = runtime_watchdog_usec != "0"
wdt_service_configured = watchdog_service_check()
args = watchdog_argparse()

ubuntu_version = int(get_series().split(".")[0])
watchdog_config_ready = True

Expand Down Expand Up @@ -111,7 +110,7 @@ def main():
print("watchdog.service unit does not report as active")
watchdog_config_ready = False
if watchdog_config_ready:
print("watchdog.service is active")
print("watchdog.service active")

return not watchdog_config_ready

Expand Down
18 changes: 10 additions & 8 deletions providers/base/units/watchdog/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ requires:
image_source_and_type.type == 'classic'
environ: WATCHDOG_TYPE
command:
if [[ -z "$WATCHDOG_TYPE" ]]; then
if [[ ! -n "$WATCHDOG_TYPE" ]]; then
>&2 echo "WATCHDOG_TYPE is not available"
exit 1
fi
echo "Trying to probe '$WATCHDOG_TYPE' module"
if ! modprobe "$WATCHDOG_TYPE"; then
modprobe $WATCHDOG_TYPE
if [[ "$?" -ne 0 ]]; then
>&2 echo "Unable to probe the '$WATCHDOG_TYPE' module"
exit 1
fi
if ! lsmod | grep -q -i "$WATCHDOG_TYPE"; then
lsmod | grep -q -i $WATCHDOG_TYPE
if [[ "$?" -ne 0 ]]; then
>&2 echo "Unable to find the '$WATCHDOG_TYPE' module after probing it"
exit 1
fi
Expand Down Expand Up @@ -111,7 +113,7 @@ command:
search_pattern="#RuntimeWatchdogSec=[0-9]*s*"
for i in {0..1}
do
result=$(grep $DEFAULT_WATCHDOG /etc/systemd/system.conf)
result=`grep $DEFAULT_WATCHDOG /etc/systemd/system.conf`
if [[ -n "$result" && $i -eq 0 ]]; then
echo "Modifying the watchdog timeout"
sed -i "s/$search_pattern/RuntimeWatchdogSec=35/g" /etc/systemd/system.conf
Expand All @@ -130,7 +132,7 @@ command:
break
fi
done
exit "$RET"
exit $RET


id: watchdog/revert-timeout
Expand All @@ -150,7 +152,7 @@ command:
SET_WATCHDOG="RuntimeWatchdogSec=35"
for i in {0..1}
do
result=$(grep $SET_WATCHDOG /etc/systemd/system.conf)
result=`grep $SET_WATCHDOG /etc/systemd/system.conf`
if [[ "$result" == "$SET_WATCHDOG" && $i -eq 0 ]]; then
echo "Modifying the watchdog timeout"
sed -i "s/$SET_WATCHDOG/#RuntimeWatchdogSec=0/g" /etc/systemd/system.conf
Expand All @@ -165,13 +167,13 @@ command:
fi
fi
else
timeout_value=$(grep RuntimeWatchdogSec /etc/systemd/system.conf | awk -F '=' '{print $2}')
timeout_value=`grep RuntimeWatchdogSec /etc/systemd/system.conf | awk -F '=' {'print $2'}`
echo "The watchdog timeout is $timeout_value now, not the value we set in previouse job"
echo "No need to revert watchdog timeout"
break
fi
done
exit "$RET"
exit $RET


id: watchdog/trigger-system-reset-auto
Expand Down

0 comments on commit 9c710a8

Please sign in to comment.