From d58586500ca96c43d29e5746d7f208ad8bd224ce Mon Sep 17 00:00:00 2001 From: paavaanan Date: Fri, 19 Jul 2019 05:20:05 -0400 Subject: [PATCH] [DellEMC] Watchdog support DellEMCS6100 --- build_debian.sh | 7 + .../s6100/scripts/s6100_platform.sh | 4 + .../s6100/sonic_platform/watchdog.py | 183 ++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100755 platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/watchdog.py diff --git a/build_debian.sh b/build_debian.sh index 9910ea742e9b..63759626cb80 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -250,6 +250,7 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in locales \ flashrom \ cgroup-tools \ + watchdog \ mcelog #Adds a locale to a debian system in non-interactive mode @@ -411,6 +412,12 @@ sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d sudo cp files/dhcp/vrf $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/ sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/ +## Config watchdog device and disable at startup +sudo sed -i 's/#watchdog-device/watchdog-device/' $FILESYSTEM_ROOT/etc/watchdog.conf +sudo sed -i 's/run_watchdog=1/run_watchdog=0/' $FILESYSTEM_ROOT/etc/default/watchdog +sudo rm -rf $FILESYSTEM_ROOT/lib/systemd/system/wd_keepalive.service +sudo rm -rf $FILESYSTEM_ROOT/etc/init.d/wd_keepalive + ## Version file sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic sudo tee $FILESYSTEM_ROOT/etc/sonic/sonic_version.yml > /dev/null < seconds. + If the watchdog is currently armed, calling this function will + simply reset the timer to the provided value. If the underlying + hardware does not support the value provided in , this + method should arm the watchdog with the *next greater* available + value. + + Returns: + An integer specifying the *actual* number of seconds the watchdog + was armed with. On failure returns -1. + """ + + # Max timeout is 30 seconds + if seconds > 30: + seconds = 30 + + # Enable watchdog in boot-up + watchdog_enable = self.check_config( + self.WATCHDOG_DEFAULT_FILE, + "run_watchdog=1") + if watchdog_enable is None: + self.write_config( + self.WATCHDOG_DEFAULT_FILE, + "run_watchdog=0", + "run_watchdog=1") + + # configure watchdog-timeout + new_timeout = 'watchdog-timeout = ' + str(seconds) + old_timeout = self.check_config( + self.WATCHDOG_CONFIG_FILE, + "watchdog-timeout") + + if old_timeout is not None: + self.write_config( + self.WATCHDOG_CONFIG_FILE, + old_timeout, + new_timeout) + else: + with open(self.WATCHDOG_CONFIG_FILE, "a") as wd_file: + wd_file.write(new_timeout) + self.run_command(self.WATCHDOG_START) + + # Restart watchdog service + self.run_command(self.WATCHDOG_RESTART) + + if self.get_wd_register("timeout") == str(seconds): + return seconds + + return -1 + + def disarm(self): + """ + Disarm 'watchdog-timeout' in open(self.WATCHDOG_CONFIG_FILE).read(): + the hardware watchdog + + Returns: + A boolean, True if watchdog is disarmed successfully, False if not + """ + if self.get_wd_register("state") == "active": + + # Disable watchdog in boot-up + self.write_config( + self.WATCHDOG_DEFAULT_FILE, + "run_watchdog=1", + "run_watchdog=0") + + return True + + return False + + def is_armed(self): + """ + Retrieves the armed state of the hardware watchdog. + + Returns: + A boolean, True if watchdog is armed, False if not + """ + + if self.get_wd_register("state") == "active": + return True + + return False + + def get_remaining_time(self): + """ + If the watchdog is armed, retrieve the number of seconds remaining on + the watchdog timer + + Returns: + An integer specifying the number of seconds remaining on thei + watchdog timer. If the watchdog is not armed, returns -1. + """ + if self.get_wd_register("state") == "active": + return self.get_wd_register("timeleft") + + return -1 +