From 6614971ee8671c1e216c2f0b1704c2c993f5cae3 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 7 Mar 2019 16:18:08 +0700 Subject: [PATCH 1/3] [device/alibaba] - Add default_sku config file --- device/alibaba/x86_64-alibaba_as13-32h-cl-r0/default_sku | 1 + device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/default_sku | 1 + device/alibaba/x86_64-alibaba_as23-128h-cl-r0/default_sku | 1 + 3 files changed, 3 insertions(+) create mode 100644 device/alibaba/x86_64-alibaba_as13-32h-cl-r0/default_sku create mode 100644 device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/default_sku create mode 100644 device/alibaba/x86_64-alibaba_as23-128h-cl-r0/default_sku diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/default_sku b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/default_sku new file mode 100644 index 000000000000..d47b50be8491 --- /dev/null +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/default_sku @@ -0,0 +1 @@ +AS13-32H t1 \ No newline at end of file diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/default_sku b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/default_sku new file mode 100644 index 000000000000..6933928c3bdb --- /dev/null +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/default_sku @@ -0,0 +1 @@ +AS13-48F8H t1 \ No newline at end of file diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/default_sku b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/default_sku new file mode 100644 index 000000000000..30e5af958eb9 --- /dev/null +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/default_sku @@ -0,0 +1 @@ +AS23-128H t1 \ No newline at end of file From 12ab0164dc6e3f9ef65a619f5df02106c6c669b7 Mon Sep 17 00:00:00 2001 From: Pradchaya P Date: Wed, 6 Mar 2019 11:09:01 +0700 Subject: [PATCH 2/3] [devices/alibaba] Add cpu c-state limit in SONiC Linux boot argument --- device/alibaba/x86_64-alibaba_as13-32h-cl-r0/installer.conf | 1 + device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/installer.conf | 1 + device/alibaba/x86_64-alibaba_as23-128h-cl-r0/installer.conf | 1 + 3 files changed, 3 insertions(+) diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/installer.conf b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/installer.conf index a6377aebcd5f..dc3cf67d19e7 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/installer.conf +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/installer.conf @@ -1 +1,2 @@ CONSOLE_SPEED=9600 +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="processor.max_cstate=1 intel_idle.max_cstate=0" diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/installer.conf b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/installer.conf index a6377aebcd5f..dc3cf67d19e7 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/installer.conf +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/installer.conf @@ -1 +1,2 @@ CONSOLE_SPEED=9600 +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="processor.max_cstate=1 intel_idle.max_cstate=0" diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/installer.conf b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/installer.conf index a6377aebcd5f..dc3cf67d19e7 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/installer.conf +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/installer.conf @@ -1 +1,2 @@ CONSOLE_SPEED=9600 +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="processor.max_cstate=1 intel_idle.max_cstate=0" From 47cf5fe8d4a421c59ad8ba94c7d7edf3f90d6ba2 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Sat, 9 Mar 2019 16:12:09 +0700 Subject: [PATCH 3/3] [device/alibaba] - Update cpld upgrade function to support multiple image upgrade --- .../plugins/fwmgrutil.py | 145 +++++++++++------- .../plugins/fwmgrutil.py | 145 +++++++++++------- .../plugins/fwmgrutil.py | 145 +++++++++++------- 3 files changed, 276 insertions(+), 159 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 8f821915490a..b30c4c846345 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 @@ -95,9 +95,22 @@ def get_bmc_version(self): bmc_info_json = bmc_info_req.json() bmc_info = bmc_info_json.get('Information') bmc_version = bmc_info.get(bmc_version_key) - return str(bmc_version) + def upload_file_bmc(self, fw_path): + scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( + fw_path) + child = pexpect.spawn(scp_command) + i = child.expect(["root@240.1.1.1's password:"], timeout=30) + if i == 0: + bmc_pwd = self.get_bmc_pass() + child.sendline(bmc_pwd) + data = child.read() + print(data) + child.close + return True + return False + def get_cpld_version(self): """Get CPLD version from SONiC :returns: dict like {'CPLD_1': version_string, 'CPLD_2': version_string} @@ -223,22 +236,14 @@ 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' """ - + bmc_pwd = self.get_bmc_pass() if fw_type == 'bmc': # Copy BMC image file to BMC - scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( - fw_path) - child = pexpect.spawn(scp_command) - i = child.expect(["root@240.1.1.1's password:"], timeout=30) - if i == 0: - print("Uploading image to BMC...") - print("Running command : ", scp_command) - - bmc_pwd = self.get_bmc_pass() - child.sendline(bmc_pwd) - data = child.read() - print(data) - child.close + print("Uploading image to BMC...") + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed") + return False filename_w_ext = os.path.basename(fw_path) json_data = dict() @@ -296,53 +301,88 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): return False elif 'cpld' in fw_type: + # Check input fw_extra_str = str(fw_extra).upper() - fw_extra_str = { - "TOP_LC_CPLD": "top_lc", - "BOT_LC_CPLD": "bot_lc", - "FAN_CPLD": "fan", - "CPU_CPLD": "cpu", - "BASE_CPLD": "base", - "COMBO_CPLD": "combo", - "SW_CPLD": "switch" - }.get(fw_extra_str, None) - - if fw_extra_str is None: - print("Failed: Invalid extra information string") + if ":" in fw_path and ":" in fw_extra_str: + fw_path_list = fw_path.split(":") + fw_extra_str_list = fw_extra_str.split(":") + else: + fw_path_list = [fw_path] + fw_extra_str_list = [fw_extra_str] + + if len(fw_path_list) != len(fw_extra_str_list): + print("Failed: Invalid input") return False - scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( - fw_path) - child = pexpect.spawn(scp_command) - i = child.expect(["root@240.1.1.1's password:"], timeout=30) - if i == 0: + data_list = list(zip(fw_path_list, fw_extra_str_list)) + for data in data_list: + fw_path = data[0] + fw_extra_str = data[1] + + # Set fw_extra + fw_extra_str = { + "TOP_LC_CPLD": "top_lc", + "BOT_LC_CPLD": "bot_lc", + "FAN_CPLD": "fan", + "CPU_CPLD": "cpu", + "BASE_CPLD": "base", + "COMBO_CPLD": "combo", + "SW_CPLD": "switch" + }.get(fw_extra_str, None) + + if fw_extra_str is None: + print("Failed: Invalid extra information string") + return False + + # Uploading image to BMC print("Uploading image to BMC...") - print("Running command : ", scp_command) - bmc_pwd = self.get_bmc_pass() - child.sendline(bmc_pwd) - data = child.read() - print(data) - child.close + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed: Unable to upload image to BMC") + return False - filename_w_ext = os.path.basename(fw_path) - json_data = dict() - json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext - json_data["password"] = bmc_pwd - json_data["device"] = "cpld" - json_data["reboot"] = "no" - json_data["type"] = fw_extra_str + filename_w_ext = os.path.basename(fw_path) + json_data = dict() + json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext + json_data["password"] = bmc_pwd + json_data["device"] = "cpld" + json_data["reboot"] = "no" + json_data["type"] = fw_extra_str - print("Installing CPLD type :", fw_extra_str) - r = requests.post(self.fw_upgrade_url, json=json_data) - if r.status_code != 200 or 'success' not in r.json().get('result'): - print("Failed") - return False + # Call BMC api to install cpld image + print("Installing CPLD type :", fw_extra_str) + r = requests.post(self.fw_upgrade_url, json=json_data) + if r.status_code != 200 or 'success' not in r.json().get('result'): + print("Failed: Invalid cpld image") + return False + + print(fw_extra_str, "Done") - if fw_extra_str == "combo": + # Refresh CPLD + if "COMBO_CPLD" in fw_extra_str_list or "BASE_CPLD" in fw_extra_str_list or "CPU_CPLD" in fw_extra_str_list: + print(fw_extra_str, "Refreshing CPLD...") + dir_name = os.path.dirname(fw_path) + file_list = [i for i in os.listdir( + dir_name) if i.lower().endswith("_onlyrefresh.vme")] + + if len(file_list) < 1: + print("Failed: Refresh image not found") + return False + + fw_path = os.path.join(dir_name, file_list[0]) + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed: Unable to upload refresh image to BMC") + return False + + json_data = dict() + json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % file_list[0] + json_data["password"] = bmc_pwd + json_data["device"] = "cpld" json_data["type"] = "enable" r = requests.post(self.fw_upgrade_url, json=json_data) if r.status_code != 200 or 'success' not in r.json().get('result'): - print("Failed") + print("Failed: Invalid refresh image") return False print("Done") @@ -360,7 +400,6 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if i == 0: print("Uploading image to BMC...") print("Running command : ", scp_command) - bmc_pwd = self.get_bmc_pass() child.sendline(bmc_pwd) data = child.read() print(data) 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 47c0a7c9dd99..28dbc330771a 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 @@ -95,9 +95,22 @@ def get_bmc_version(self): bmc_info_json = bmc_info_req.json() bmc_info = bmc_info_json.get('Information') bmc_version = bmc_info.get(bmc_version_key) - return str(bmc_version) + def upload_file_bmc(self, fw_path): + scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( + fw_path) + child = pexpect.spawn(scp_command) + i = child.expect(["root@240.1.1.1's password:"], timeout=30) + if i == 0: + bmc_pwd = self.get_bmc_pass() + child.sendline(bmc_pwd) + data = child.read() + print(data) + child.close + return True + return False + def get_cpld_version(self): """Get CPLD version from SONiC :returns: dict like {'CPLD_1': version_string, 'CPLD_2': version_string} @@ -223,22 +236,14 @@ 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' """ - + bmc_pwd = self.get_bmc_pass() if fw_type == 'bmc': # Copy BMC image file to BMC - scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( - fw_path) - child = pexpect.spawn(scp_command) - i = child.expect(["root@240.1.1.1's password:"], timeout=30) - if i == 0: - print("Uploading image to BMC...") - print("Running command : ", scp_command) - - bmc_pwd = self.get_bmc_pass() - child.sendline(bmc_pwd) - data = child.read() - print(data) - child.close + print("Uploading image to BMC...") + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed") + return False filename_w_ext = os.path.basename(fw_path) json_data = dict() @@ -296,53 +301,88 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): return False elif 'cpld' in fw_type: + # Check input fw_extra_str = str(fw_extra).upper() - fw_extra_str = { - "TOP_LC_CPLD": "top_lc", - "BOT_LC_CPLD": "bot_lc", - "FAN_CPLD": "fan", - "CPU_CPLD": "cpu", - "BASE_CPLD": "base", - "COMBO_CPLD": "combo", - "SW_CPLD": "switch" - }.get(fw_extra_str, None) - - if fw_extra_str is None: - print("Failed: Invalid extra information string") + if ":" in fw_path and ":" in fw_extra_str: + fw_path_list = fw_path.split(":") + fw_extra_str_list = fw_extra_str.split(":") + else: + fw_path_list = [fw_path] + fw_extra_str_list = [fw_extra_str] + + if len(fw_path_list) != len(fw_extra_str_list): + print("Failed: Invalid input") return False - scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( - fw_path) - child = pexpect.spawn(scp_command) - i = child.expect(["root@240.1.1.1's password:"], timeout=30) - if i == 0: + data_list = list(zip(fw_path_list, fw_extra_str_list)) + for data in data_list: + fw_path = data[0] + fw_extra_str = data[1] + + # Set fw_extra + fw_extra_str = { + "TOP_LC_CPLD": "top_lc", + "BOT_LC_CPLD": "bot_lc", + "FAN_CPLD": "fan", + "CPU_CPLD": "cpu", + "BASE_CPLD": "base", + "COMBO_CPLD": "combo", + "SW_CPLD": "switch" + }.get(fw_extra_str, None) + + if fw_extra_str is None: + print("Failed: Invalid extra information string") + return False + + # Uploading image to BMC print("Uploading image to BMC...") - print("Running command : ", scp_command) - bmc_pwd = self.get_bmc_pass() - child.sendline(bmc_pwd) - data = child.read() - print(data) - child.close + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed: Unable to upload image to BMC") + return False - filename_w_ext = os.path.basename(fw_path) - json_data = dict() - json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext - json_data["password"] = bmc_pwd - json_data["device"] = "cpld" - json_data["reboot"] = "no" - json_data["type"] = fw_extra_str + filename_w_ext = os.path.basename(fw_path) + json_data = dict() + json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext + json_data["password"] = bmc_pwd + json_data["device"] = "cpld" + json_data["reboot"] = "no" + json_data["type"] = fw_extra_str - print("Installing CPLD type :", fw_extra_str) - r = requests.post(self.fw_upgrade_url, json=json_data) - if r.status_code != 200 or 'success' not in r.json().get('result'): - print("Failed") - return False + # Call BMC api to install cpld image + print("Installing CPLD type :", fw_extra_str) + r = requests.post(self.fw_upgrade_url, json=json_data) + if r.status_code != 200 or 'success' not in r.json().get('result'): + print("Failed: Invalid cpld image") + return False + + print(fw_extra_str, "Done") - if fw_extra_str == "combo": + # Refresh CPLD + if "COMBO_CPLD" in fw_extra_str_list or "BASE_CPLD" in fw_extra_str_list or "CPU_CPLD" in fw_extra_str_list: + print(fw_extra_str, "Refreshing CPLD...") + dir_name = os.path.dirname(fw_path) + file_list = [i for i in os.listdir( + dir_name) if i.lower().endswith("_onlyrefresh.vme")] + + if len(file_list) < 1: + print("Failed: Refresh image not found") + return False + + fw_path = os.path.join(dir_name, file_list[0]) + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed: Unable to upload refresh image to BMC") + return False + + json_data = dict() + json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % file_list[0] + json_data["password"] = bmc_pwd + json_data["device"] = "cpld" json_data["type"] = "enable" r = requests.post(self.fw_upgrade_url, json=json_data) if r.status_code != 200 or 'success' not in r.json().get('result'): - print("Failed") + print("Failed: Invalid refresh image") return False print("Done") @@ -360,7 +400,6 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if i == 0: print("Uploading image to BMC...") print("Running command : ", scp_command) - bmc_pwd = self.get_bmc_pass() child.sendline(bmc_pwd) data = child.read() print(data) 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 5e20715e6dc0..652e149b3fb3 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 @@ -95,9 +95,22 @@ def get_bmc_version(self): bmc_info_json = bmc_info_req.json() bmc_info = bmc_info_json.get('Information') bmc_version = bmc_info.get(bmc_version_key) - return str(bmc_version) + def upload_file_bmc(self, fw_path): + scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( + fw_path) + child = pexpect.spawn(scp_command) + i = child.expect(["root@240.1.1.1's password:"], timeout=30) + if i == 0: + bmc_pwd = self.get_bmc_pass() + child.sendline(bmc_pwd) + data = child.read() + print(data) + child.close + return True + return False + def get_cpld_version(self): """Get CPLD version from SONiC :returns: dict like {'CPLD_1': version_string, 'CPLD_2': version_string} @@ -223,22 +236,14 @@ 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' """ - + bmc_pwd = self.get_bmc_pass() if fw_type == 'bmc': # Copy BMC image file to BMC - scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( - fw_path) - child = pexpect.spawn(scp_command) - i = child.expect(["root@240.1.1.1's password:"], timeout=30) - if i == 0: - print("Uploading image to BMC...") - print("Running command : ", scp_command) - - bmc_pwd = self.get_bmc_pass() - child.sendline(bmc_pwd) - data = child.read() - print(data) - child.close + print("Uploading image to BMC...") + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed") + return False filename_w_ext = os.path.basename(fw_path) json_data = dict() @@ -296,53 +301,88 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): return False elif 'cpld' in fw_type: + # Check input fw_extra_str = str(fw_extra).upper() - fw_extra_str = { - "TOP_LC_CPLD": "top_lc", - "BOT_LC_CPLD": "bot_lc", - "FAN_CPLD": "fan", - "CPU_CPLD": "cpu", - "BASE_CPLD": "base", - "COMBO_CPLD": "combo", - "SW_CPLD": "switch" - }.get(fw_extra_str, None) - - if fw_extra_str is None: - print("Failed: Invalid extra information string") + if ":" in fw_path and ":" in fw_extra_str: + fw_path_list = fw_path.split(":") + fw_extra_str_list = fw_extra_str.split(":") + else: + fw_path_list = [fw_path] + fw_extra_str_list = [fw_extra_str] + + if len(fw_path_list) != len(fw_extra_str_list): + print("Failed: Invalid input") return False - scp_command = 'sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r %s root@240.1.1.1:/home/root/' % os.path.abspath( - fw_path) - child = pexpect.spawn(scp_command) - i = child.expect(["root@240.1.1.1's password:"], timeout=30) - if i == 0: + data_list = list(zip(fw_path_list, fw_extra_str_list)) + for data in data_list: + fw_path = data[0] + fw_extra_str = data[1] + + # Set fw_extra + fw_extra_str = { + "TOP_LC_CPLD": "top_lc", + "BOT_LC_CPLD": "bot_lc", + "FAN_CPLD": "fan", + "CPU_CPLD": "cpu", + "BASE_CPLD": "base", + "COMBO_CPLD": "combo", + "SW_CPLD": "switch" + }.get(fw_extra_str, None) + + if fw_extra_str is None: + print("Failed: Invalid extra information string") + return False + + # Uploading image to BMC print("Uploading image to BMC...") - print("Running command : ", scp_command) - bmc_pwd = self.get_bmc_pass() - child.sendline(bmc_pwd) - data = child.read() - print(data) - child.close + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed: Unable to upload image to BMC") + return False - filename_w_ext = os.path.basename(fw_path) - json_data = dict() - json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext - json_data["password"] = bmc_pwd - json_data["device"] = "cpld" - json_data["reboot"] = "no" - json_data["type"] = fw_extra_str + filename_w_ext = os.path.basename(fw_path) + json_data = dict() + json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext + json_data["password"] = bmc_pwd + json_data["device"] = "cpld" + json_data["reboot"] = "no" + json_data["type"] = fw_extra_str - print("Installing CPLD type :", fw_extra_str) - r = requests.post(self.fw_upgrade_url, json=json_data) - if r.status_code != 200 or 'success' not in r.json().get('result'): - print("Failed") - return False + # Call BMC api to install cpld image + print("Installing CPLD type :", fw_extra_str) + r = requests.post(self.fw_upgrade_url, json=json_data) + if r.status_code != 200 or 'success' not in r.json().get('result'): + print("Failed: Invalid cpld image") + return False + + print(fw_extra_str, "Done") - if fw_extra_str == "combo": + # Refresh CPLD + if "COMBO_CPLD" in fw_extra_str_list or "BASE_CPLD" in fw_extra_str_list or "CPU_CPLD" in fw_extra_str_list: + print(fw_extra_str, "Refreshing CPLD...") + dir_name = os.path.dirname(fw_path) + file_list = [i for i in os.listdir( + dir_name) if i.lower().endswith("_refresh.vme")] + + if len(file_list) < 1: + print("Failed: Refresh image not found") + return False + + fw_path = os.path.join(dir_name, file_list[0]) + upload_file = self.upload_file_bmc(fw_path) + if not upload_file: + print("Failed: Unable to upload refresh image to BMC") + return False + + json_data = dict() + json_data["image_path"] = "root@127.0.0.1:/home/root/%s" % file_list[0] + json_data["password"] = bmc_pwd + json_data["device"] = "cpld" json_data["type"] = "enable" r = requests.post(self.fw_upgrade_url, json=json_data) if r.status_code != 200 or 'success' not in r.json().get('result'): - print("Failed") + print("Failed: Invalid refresh image") return False print("Done") @@ -360,7 +400,6 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if i == 0: print("Uploading image to BMC...") print("Running command : ", scp_command) - bmc_pwd = self.get_bmc_pass() child.sendline(bmc_pwd) data = child.read() print(data)