From 7e4b3d8fe99ff257326b8239699b7ca65ed09c2e Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 23 May 2019 16:58:14 +0700 Subject: [PATCH 1/2] [device/alibaba]: Update firmware_refresh to support multiple refresh image --- .../plugins/fwmgrutil.py | 47 ++++++++++++++----- .../plugins/fwmgrutil.py | 47 ++++++++++++++----- .../plugins/fwmgrutil.py | 47 ++++++++++++++----- 3 files changed, 102 insertions(+), 39 deletions(-) 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 4bc5840e2724..a56bb9301546 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 @@ -725,40 +725,61 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): No operation if the power cycle is not needed. Example: - self.firmware_refresh(["FPGA"], ["CPU_CPLD", "LC_CPLD"], "/tmp/fw/refresh.vme") + self.firmware_refresh(["FPGA"], ["BASE_CPLD", "LC_CPLD"],"/tmp/fw/refresh.vme") or - self.firmware_refresh("FPGA", None, None) + self.firmware_refresh(["FPGA"], None, None) or - self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BOARD_CPLD"], "/tmp/fw/refresh.vme") + self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:/tmp/fw/base_refresh.vme") """ upgrade_list = [] if not fpga_list and not cpld_list: return False - if cpld_list and ("COMBO_CPLD" in cpld_list or "BASE_CPLD" in cpld_list or "CPU_CPLD" in cpld_list): - fw_path = fw_extra - upload_file = self.upload_file_bmc(fw_path) - if not upload_file: - print("Failed: Unable to upload refresh image to BMC") + if cpld_list and ("BASE_CPLD" in cpld_list or "FAN_CPLD" in cpld_list): + fw_path_list = fw_extra.split(':') + command = "echo " + if len(fw_path_list) != len(cpld_list): + print("Failed: Invalid fw_extra") return False - filename_w_ext = os.path.basename(fw_path) - upgrade_list.append(filename_w_ext.lower()) - self.upgrade_logger(upgrade_list) + for idx in range(0, len(cpld_list)): + fw_path = fw_path_list[idx] + refresh_type = { + "BASE_CPLD": "base", + "FAN_CPLD": "fan" + }.get(cpld_list[idx], None) + + if not refresh_type: + continue + elif not self.upload_file_bmc(fw_path): + print("Failed: Unable to upload refresh image to BMC") + return False + else: + filename_w_ext = os.path.basename(fw_path) + upgrade_list.append(filename_w_ext.lower()) + self.upgrade_logger(upgrade_list) + + sub_command = "%s /home/root/%s > /tmp/cpld_refresh " % ( + refresh_type, filename_w_ext) + command += sub_command + json_data = dict() - json_data["data"] = "echo base /home/root/%s > /tmp/cpld_refresh" % filename_w_ext + json_data["data"] = command r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: print("Failed: Invalid refresh image") return False - if fpga_list: + elif fpga_list: json_data = dict() json_data["data"] = "echo fpga > /tmp/cpld_refresh" r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: print("Failed: Unable to load new FPGA") return False + else: + print("Failed: Invalid input") + return False return True 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 bd73ce7da6d5..ea11c14ea242 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 @@ -725,40 +725,61 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): No operation if the power cycle is not needed. Example: - self.firmware_refresh(["FPGA"], ["CPU_CPLD", "LC_CPLD"], "/tmp/fw/refresh.vme") + self.firmware_refresh(["FPGA"], ["BASE_CPLD", "LC_CPLD"],"/tmp/fw/refresh.vme") or - self.firmware_refresh("FPGA", None, None) + self.firmware_refresh(["FPGA"], None, None) or - self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BOARD_CPLD"], "/tmp/fw/refresh.vme") + self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:/tmp/fw/base_refresh.vme") """ upgrade_list = [] if not fpga_list and not cpld_list: return False - if cpld_list and ("COMBO_CPLD" in cpld_list or "BASE_CPLD" in cpld_list or "CPU_CPLD" in cpld_list): - fw_path = fw_extra - upload_file = self.upload_file_bmc(fw_path) - if not upload_file: - print("Failed: Unable to upload refresh image to BMC") + if cpld_list and ("BASE_CPLD" in cpld_list or "FAN_CPLD" in cpld_list): + fw_path_list = fw_extra.split(':') + command = "echo " + if len(fw_path_list) != len(cpld_list): + print("Failed: Invalid fw_extra") return False - filename_w_ext = os.path.basename(fw_path) - upgrade_list.append(filename_w_ext.lower()) - self.upgrade_logger(upgrade_list) + for idx in range(0, len(cpld_list)): + fw_path = fw_path_list[idx] + refresh_type = { + "BASE_CPLD": "base", + "FAN_CPLD": "fan" + }.get(cpld_list[idx], None) + + if not refresh_type: + continue + elif not self.upload_file_bmc(fw_path): + print("Failed: Unable to upload refresh image to BMC") + return False + else: + filename_w_ext = os.path.basename(fw_path) + upgrade_list.append(filename_w_ext.lower()) + self.upgrade_logger(upgrade_list) + + sub_command = "%s /home/root/%s > /tmp/cpld_refresh " % ( + refresh_type, filename_w_ext) + command += sub_command + json_data = dict() - json_data["data"] = "echo base /home/root/%s > /tmp/cpld_refresh" % filename_w_ext + json_data["data"] = command r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: print("Failed: Invalid refresh image") return False - if fpga_list: + elif fpga_list: json_data = dict() json_data["data"] = "echo fpga > /tmp/cpld_refresh" r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: print("Failed: Unable to load new FPGA") return False + else: + print("Failed: Invalid input") + return False return True 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 1e93ba8780a3..27d794f7f1d9 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 @@ -725,40 +725,61 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): No operation if the power cycle is not needed. Example: - self.firmware_refresh(["FPGA"], ["CPU_CPLD", "LC_CPLD"], "/tmp/fw/refresh.vme") + self.firmware_refresh(["FPGA"], ["BASE_CPLD", "LC_CPLD"],"/tmp/fw/refresh.vme") or - self.firmware_refresh("FPGA", None, None) + self.firmware_refresh(["FPGA"], None, None) or - self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BOARD_CPLD"], "/tmp/fw/refresh.vme") + self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:/tmp/fw/base_refresh.vme") """ upgrade_list = [] if not fpga_list and not cpld_list: return False - if cpld_list and ("COMBO_CPLD" in cpld_list or "BASE_CPLD" in cpld_list or "CPU_CPLD" in cpld_list): - fw_path = fw_extra - upload_file = self.upload_file_bmc(fw_path) - if not upload_file: - print("Failed: Unable to upload refresh image to BMC") + if cpld_list and ("BASE_CPLD" in cpld_list or "FAN_CPLD" in cpld_list): + fw_path_list = fw_extra.split(':') + command = "echo " + if len(fw_path_list) != len(cpld_list): + print("Failed: Invalid fw_extra") return False - filename_w_ext = os.path.basename(fw_path) - upgrade_list.append(filename_w_ext.lower()) - self.upgrade_logger(upgrade_list) + for idx in range(0, len(cpld_list)): + fw_path = fw_path_list[idx] + refresh_type = { + "BASE_CPLD": "base", + "FAN_CPLD": "fan" + }.get(cpld_list[idx], None) + + if not refresh_type: + continue + elif not self.upload_file_bmc(fw_path): + print("Failed: Unable to upload refresh image to BMC") + return False + else: + filename_w_ext = os.path.basename(fw_path) + upgrade_list.append(filename_w_ext.lower()) + self.upgrade_logger(upgrade_list) + + sub_command = "%s /home/root/%s > /tmp/cpld_refresh " % ( + refresh_type, filename_w_ext) + command += sub_command + json_data = dict() - json_data["data"] = "echo base /home/root/%s > /tmp/cpld_refresh" % filename_w_ext + json_data["data"] = command r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: print("Failed: Invalid refresh image") return False - if fpga_list: + elif fpga_list: json_data = dict() json_data["data"] = "echo fpga > /tmp/cpld_refresh" r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: print("Failed: Unable to load new FPGA") return False + else: + print("Failed: Invalid input") + return False return True From 092093e53408e45dace9efbc511fa6bf4a1999af Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 23 May 2019 17:14:11 +0700 Subject: [PATCH 2/2] [device/alibaba]: Update firmware_refresh error handler --- .../x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py | 6 +++--- .../x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py | 6 +++--- .../x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) 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 a56bb9301546..da04992d6022 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 @@ -729,7 +729,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): or self.firmware_refresh(["FPGA"], None, None) or - self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:/tmp/fw/base_refresh.vme") + self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:none:/tmp/fw/base_refresh.vme") """ upgrade_list = [] if not fpga_list and not cpld_list: @@ -767,7 +767,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): json_data["data"] = command r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: - print("Failed: Invalid refresh image") + print("Failed: %d Invalid refresh image" % r.status_code) return False elif fpga_list: @@ -775,7 +775,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): json_data["data"] = "echo fpga > /tmp/cpld_refresh" r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: - print("Failed: Unable to load new FPGA") + print("Failed: %d Unable to load new FPGA" % r.status_code) return False else: print("Failed: Invalid input") 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 ea11c14ea242..3f3dde9a2ed2 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 @@ -729,7 +729,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): or self.firmware_refresh(["FPGA"], None, None) or - self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:/tmp/fw/base_refresh.vme") + self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:none:/tmp/fw/base_refresh.vme") """ upgrade_list = [] if not fpga_list and not cpld_list: @@ -767,7 +767,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): json_data["data"] = command r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: - print("Failed: Invalid refresh image") + print("Failed: %d Invalid refresh image" % r.status_code) return False elif fpga_list: @@ -775,7 +775,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): json_data["data"] = "echo fpga > /tmp/cpld_refresh" r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: - print("Failed: Unable to load new FPGA") + print("Failed: %d Unable to load new FPGA" % r.status_code) return False else: print("Failed: Invalid input") 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 27d794f7f1d9..659ba828289c 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 @@ -729,7 +729,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): or self.firmware_refresh(["FPGA"], None, None) or - self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:/tmp/fw/base_refresh.vme") + self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BASE_CPLD"], "/tmp/fw/fan_refresh.vme:none:/tmp/fw/base_refresh.vme") """ upgrade_list = [] if not fpga_list and not cpld_list: @@ -767,7 +767,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): json_data["data"] = command r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: - print("Failed: Invalid refresh image") + print("Failed: %d Invalid refresh image" % r.status_code) return False elif fpga_list: @@ -775,7 +775,7 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): json_data["data"] = "echo fpga > /tmp/cpld_refresh" r = requests.post(self.bmc_raw_command_url, json=json_data) if r.status_code != 200: - print("Failed: Unable to load new FPGA") + print("Failed: %d Unable to load new FPGA" % r.status_code) return False else: print("Failed: Invalid input")