diff options
author | PMR <pmr@pmr-lander> | 2021-07-15 14:01:33 +0000 |
---|---|---|
committer | PMR <pmr@pmr-lander> | 2021-07-15 14:01:33 +0000 |
commit | d82e5c29ea247eaa2cadac534ebe8886d53089ec (patch) | |
tree | 64f7835f13dadd52b9ced492b3e37d5d22238700 | |
parent | 6689ffb78b2cbc45bb1da0c05ae05a3ee4d3dab1 (diff) | |
parent | a610500792657874537e8f1633cb746b891fa777 (diff) |
Merge #405172 from ~zongminl/plainbox-provider-checkbox:sync-watchdog-test-between-classic-and-core
Change: Align the test for watchdog config on classic and core image Watchdog implementation on both classic and core image no longer rely on watchdogd service since 20.04, with this change watchdog/systemd-config tests only systemd configuration on 20.04 and later series while keeping the original test for prior releases
-rwxr-xr-x | bin/watchdog_config_test.py | 90 | ||||
-rw-r--r-- | units/watchdog/jobs.pxu | 27 |
2 files changed, 91 insertions, 26 deletions
diff --git a/bin/watchdog_config_test.py b/bin/watchdog_config_test.py new file mode 100755 index 0000000..a650976 --- /dev/null +++ b/bin/watchdog_config_test.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# Copyright 2021 Canonical Ltd. +# All rights reserved. +# +# Written by: +# Vic Liu <vic.liu@canonical.com> +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# Checkbox is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Checkbox. If not, see <http://www.gnu.org/licenses/>. + +import subprocess + +from checkbox_support.snap_utils.system import on_ubuntucore +from checkbox_support.snap_utils.system import get_series + + +def get_systemd_wdt_usec(): + """ + Return value of systemd-watchdog RuntimeWatchdogUSec + """ + cmd = ['systemctl', 'show', '-p', 'RuntimeWatchdogUSec'] + try: + result = subprocess.check_output(cmd, universal_newlines=True) + except Exception as err: + raise SystemExit("Error: {}".format(err)) + + if result: + runtime_watchdog_usec = result.split("=")[1].strip() + return runtime_watchdog_usec + else: + raise SystemExit( + "Unexpected failure occurred when executing: {}".format(cmd)) + + +def watchdog_service_check(): + """ + Check if the watchdog service is configured correctly + """ + cmd = ['systemctl', 'is-active', 'watchdog.service', '--quiet'] + try: + return not subprocess.run(cmd).returncode + except Exception as err: + raise SystemExit("Error: {}".format(err)) + + +def main(): + runtime_watchdog_usec = get_systemd_wdt_usec() + systemd_wdt_configured = (runtime_watchdog_usec != "0") + wdt_service_configured = watchdog_service_check() + ubuntu_version = int(get_series().split(".")[0]) + watchdog_config_ready = True + + if (ubuntu_version >= 20) or (on_ubuntucore()): + if not systemd_wdt_configured: + print("systemd watchdog should be enabled but reset timeout: " + "{}".format(runtime_watchdog_usec)) + watchdog_config_ready = False + if wdt_service_configured: + print("found unexpected active watchdog.service unit") + watchdog_config_ready = False + if watchdog_config_ready: + print("systemd watchdog enabled, reset timeout: {}".format( + runtime_watchdog_usec)) + print("watchdog.service is not active") + else: + if systemd_wdt_configured: + print("systemd watchdog should not be enabled but reset timeout: " + "{}".format(runtime_watchdog_usec)) + watchdog_config_ready = False + if not wdt_service_configured: + print("watchdog.service unit does not report as active") + watchdog_config_ready = False + if watchdog_config_ready: + print("systemd watchdog disabled") + print("watchdog.service active") + + raise SystemExit(not watchdog_config_ready) + + +if __name__ == "__main__": + main() diff --git a/units/watchdog/jobs.pxu b/units/watchdog/jobs.pxu index 0e16f82..c2bd868 100644 --- a/units/watchdog/jobs.pxu +++ b/units/watchdog/jobs.pxu @@ -9,32 +9,7 @@ command: udev_resource.py -f WATCHDOG id: watchdog/systemd-config _summary: Check if the hardware watchdog is properly configured template-engine: jinja2 -command: - inbuilt=$(systemctl show -p RuntimeWatchdogUSec | awk -F= '{print $2}') - external=$(systemctl is-active watchdog.service) - {%- if __on_ubuntucore__ %} - if [ "$inbuilt" == "0" ]; then - echo "systemd watchdog should be enabled but reset timeout: $inbuilt" - exit 1 - fi - if [ "$external" == "active" ]; then - echo "found unexpected active watchdog.service unit" - exit 1 - fi - echo "systemd watchdog enabled, reset timeout: $inbuilt" - echo "watchdog.service is not active" - {%- else %} - if [ "$inbuilt" != "0" ]; then - echo "systemd watchdog should not be enabled but reset timeout: $inbuilt" - exit 1 - fi - if [ "$external" != "active" ]; then - echo "watchdog.service unit does not report as active" - exit 1 - fi - echo "systemd watchdog disabled" - echo "watchdog.service active" - {% endif -%} +command: watchdog_config_test.py category_id: com.canonical.plainbox::power-management flags: simple imports: from com.canonical.plainbox import manifest |