Skip to content

Commit

Permalink
[device/alibaba]: Update error handler for bmc watchdog on fwmgrutil
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirut Getbamrung authored and tiantianlv committed May 25, 2019
1 parent 63dafab commit dcd851d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
26 changes: 21 additions & 5 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
26 changes: 21 additions & 5 deletions device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit dcd851d

Please sign in to comment.