diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py index da04992d6022..1da9228ceee1 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py @@ -38,9 +38,11 @@ def __init__(self): self.switchboard_cpld4_path = "/sys/devices/platform/%s.switchboard/CPLD4/getreg" % self.platform_name self.bmc_pwd_path = "/usr/local/etc/bmcpwd" self.bmc_wdt_ctrl = "/usr/local/etc/bmc_wdt.sh" + self.bmc_wdt_trig = False def __del__(self): - self.__bmc_watchdog_handler("enable") + if self.bmc_wdt_trig: + self.__bmc_watchdog_handler("enable") def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) @@ -77,8 +79,22 @@ def __fpga_pci_rescan(self): return 0 def __bmc_watchdog_handler(self, state): - command = "systemctl stop2 bmc_wdt.timer && sh %s stop" % self.bmc_wdt_ctrl if state == "disable" else "systemctl start bmc_wdt.timer" - return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + command = "systemctl start bmc_wdt.timer" + if state == "disable": + command = "systemctl stop bmc_wdt.timer;sh % s stop" % self.bmc_wdt_ctrl + p = subprocess.Popen(command, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + json_object = {} + try: + json_object = json.loads(raw_data) + except: + pass + finally: + if json_object.get('result') != "success" and err != '': + print("Warning: %s" % err) + return False + return True def get_bmc_pass(self): if os.path.exists(self.bmc_pwd_path): @@ -256,7 +272,7 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc', value should be one of 'master' or 'slave' or 'both' """ - self.__bmc_watchdog_handler("disable") + self.bmc_wdt_trig = self.__bmc_watchdog_handler("disable") fw_type = fw_type.lower() upgrade_list = [] bmc_pwd = self.get_bmc_pass() @@ -607,7 +623,7 @@ def firmware_program(self, fw_type, fw_path, fw_extra=None): or self.firmware_program("FPGA", "/fpga.bin") """ - self.__bmc_watchdog_handler("disable") + self.bmc_wdt_trig = self.__bmc_watchdog_handler("disable") fw_type = fw_type.lower() upgrade_list = [] bmc_pwd = self.get_bmc_pass() diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py index 3f3dde9a2ed2..d70730fe8ee2 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py @@ -38,9 +38,11 @@ def __init__(self): self.switchboard_cpld4_path = "/sys/devices/platform/%s.switchboard/CPLD4/getreg" % self.platform_name self.bmc_pwd_path = "/usr/local/etc/bmcpwd" self.bmc_wdt_ctrl = "/usr/local/etc/bmc_wdt.sh" + self.bmc_wdt_trig = False def __del__(self): - self.__bmc_watchdog_handler("enable") + if self.bmc_wdt_trig: + self.__bmc_watchdog_handler("enable") def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) @@ -77,8 +79,22 @@ def __fpga_pci_rescan(self): return 0 def __bmc_watchdog_handler(self, state): - command = "systemctl stop2 bmc_wdt.timer && sh %s stop" % self.bmc_wdt_ctrl if state == "disable" else "systemctl start bmc_wdt.timer" - return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + command = "systemctl start bmc_wdt.timer" + if state == "disable": + command = "systemctl stop bmc_wdt.timer;sh % s stop" % self.bmc_wdt_ctrl + p = subprocess.Popen(command, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + json_object = {} + try: + json_object = json.loads(raw_data) + except: + pass + finally: + if json_object.get('result') != "success" and err != '': + print("Warning: %s" % err) + return False + return True def get_bmc_pass(self): if os.path.exists(self.bmc_pwd_path): @@ -256,7 +272,7 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc', value should be one of 'master' or 'slave' or 'both' """ - self.__bmc_watchdog_handler("disable") + self.bmc_wdt_trig = self.__bmc_watchdog_handler("disable") fw_type = fw_type.lower() upgrade_list = [] bmc_pwd = self.get_bmc_pass() @@ -607,7 +623,7 @@ def firmware_program(self, fw_type, fw_path, fw_extra=None): or self.firmware_program("FPGA", "/fpga.bin") """ - self.__bmc_watchdog_handler("disable") + self.bmc_wdt_trig = self.__bmc_watchdog_handler("disable") fw_type = fw_type.lower() upgrade_list = [] bmc_pwd = self.get_bmc_pass() diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py index 659ba828289c..04bd0f1305c9 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py @@ -38,9 +38,11 @@ def __init__(self): self.switchboard_cpld4_path = "/sys/devices/platform/%s.switchboard/CPLD4/getreg" % self.platform_name self.bmc_pwd_path = "/usr/local/etc/bmcpwd" self.bmc_wdt_ctrl = "/usr/local/etc/bmc_wdt.sh" + self.bmc_wdt_trig = False def __del__(self): - self.__bmc_watchdog_handler("enable") + if self.bmc_wdt_trig: + self.__bmc_watchdog_handler("enable") def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) @@ -77,8 +79,22 @@ def __fpga_pci_rescan(self): return 0 def __bmc_watchdog_handler(self, state): - command = "systemctl stop2 bmc_wdt.timer && sh %s stop" % self.bmc_wdt_ctrl if state == "disable" else "systemctl start bmc_wdt.timer" - return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + command = "systemctl start bmc_wdt.timer" + if state == "disable": + command = "systemctl stop bmc_wdt.timer;sh % s stop" % self.bmc_wdt_ctrl + p = subprocess.Popen(command, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + json_object = {} + try: + json_object = json.loads(raw_data) + except: + pass + finally: + if json_object.get('result') != "success" and err != '': + print("Warning: %s" % err) + return False + return True def get_bmc_pass(self): if os.path.exists(self.bmc_pwd_path): @@ -256,7 +272,7 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc', value should be one of 'master' or 'slave' or 'both' """ - self.__bmc_watchdog_handler("disable") + self.bmc_wdt_trig = self.__bmc_watchdog_handler("disable") fw_type = fw_type.lower() upgrade_list = [] bmc_pwd = self.get_bmc_pass() @@ -607,7 +623,7 @@ def firmware_program(self, fw_type, fw_path, fw_extra=None): or self.firmware_program("FPGA", "/fpga.bin") """ - self.__bmc_watchdog_handler("disable") + self.bmc_wdt_trig = self.__bmc_watchdog_handler("disable") fw_type = fw_type.lower() upgrade_list = [] bmc_pwd = self.get_bmc_pass()