From 603ca2c8fc12876bd9ee141a575ded8f16185f33 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 14 Feb 2019 17:19:06 +0700 Subject: [PATCH 1/2] [platform/cel] - Update Alibaba platform module --- platform/broadcom/sonic-platform-modules-cel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index 89630184a75b..1023cd4b2648 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit 89630184a75b38adae974588812e0e10aafe6d35 +Subproject commit 1023cd4b2648170051387092b097b576c25831c7 From e34a75a68d36b78b3f41cca2f6b0aa8263af0277 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 14 Feb 2019 17:20:19 +0700 Subject: [PATCH 2/2] [device/alibaba] - Update BMC Upgrade function --- .../plugins/fwmgrutil.py | 101 ++++++++++++------ .../plugins/fwmgrutil.py | 99 +++++++++++------ .../plugins/fwmgrutil.py | 99 +++++++++++------ 3 files changed, 199 insertions(+), 100 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 5d072bbeae26..16b97f6a143b 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 @@ -6,6 +6,8 @@ import subprocess import requests import os +import pexpect +import base64 try: from sonic_fwmgr.fwgmr_base import FwMgrUtilBase @@ -29,6 +31,7 @@ def __init__(self): self.switchboard_cpld2_path = "/sys/devices/platform/%s.switchboard/CPLD2/getreg" % self.platform_name self.switchboard_cpld3_path = "/sys/devices/platform/%s.switchboard/CPLD3/getreg" % self.platform_name self.switchboard_cpld4_path = "/sys/devices/platform/%s.switchboard/CPLD4/getreg" % self.platform_name + self.bmc_pwd_path = "/usr/local/etc/bmcpwd" def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) @@ -40,6 +43,19 @@ def __get_register_value(self, path, register): else: return raw_data.strip() + def get_bmc_pass(self): + with open(self.bmc_pwd_path) as file: + data = file.read() + + key = "bmc" + dec = [] + enc = base64.urlsafe_b64decode(data) + for i in range(len(enc)): + key_c = key[i % len(key)] + dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) + dec.append(dec_c) + return "".join(dec) + def get_bmc_version(self): """Get BMC version from SONiC :returns: version string @@ -109,6 +125,8 @@ def get_bios_version(self): p = subprocess.Popen( ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) raw_data = str(p.communicate()[0]) + if raw_data == '': + return str(None) raw_data_list = raw_data.split("\n") bios_version = raw_data_list[0] if len( raw_data_list) == 1 else raw_data_list[-2] @@ -129,10 +147,11 @@ def get_onie_version(self): onie_version_raw = line.split('=') onie_verison = onie_version_raw[1].strip() break + onie_config_file.close() return str(onie_verison) def get_pcie_version(self): - """Get PCiE version from SONiC + """Get PCiE version from SONiC :returns: version dict { "PCIE_FW_LOADER": "2.5", "PCIE_FW": "D102_08" } """ @@ -177,43 +196,57 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): """ if fw_type == 'bmc': - # Copy BMC image file to BMC - scp_command = 'scp ' + \ - os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/' - - print "Uploading image to BMC..." - print "Running command : ", scp_command - print "Please enter the BMC password" - p = subprocess.Popen( - scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err = p.communicate() - - if err != "": - print "Failed" - return False - - print "Installing BMC image..." + 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 filename_w_ext = os.path.basename(fw_path) json_data = dict() - json_data["data"] = "flashcp /home/root/" + \ - filename_w_ext + " /dev/mtd5" - json_data["timeout"] = 300 - - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code == 200: - print "DONE, Rebooting BMC....." + json_data["path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext + json_data["password"] = bmc_pwd + fw_extra_str = str(fw_extra).lower() + flash = fw_extra_str if fw_extra_str in [ + "master", "slave", "both"] else "both" + json_data["flash"] = flash + + if flash == "both": + print("Installing BMC as master mode...") + json_data["flash"] = "master" + r = requests.post(self.bmc_info_url, json=json_data) + return_data = r.json() + if r.status_code != 200 or 'success' not in return_data.get('result'): + print("Failed") + return False + print("Done") + json_data["flash"] = "slave" + + print("Installing BMC as %s mode..." % json_data["flash"]) + r = requests.post(self.bmc_info_url, json=json_data) + return_data = r.json() + if r.status_code == 200 and 'success' in return_data.get('result'): + print("Done, Rebooting BMC.....") reboot_dict = dict() - reboot_dict["data"] = "reboot" - r = requests.post(self.bmc_raw_command_url, json=reboot_dict) + reboot_dict["reboot"] = "yes" + r = requests.post(self.bmc_info_url, json=reboot_dict) + return True else: - print "Failed" + print("Failed") return False elif fw_type == 'fpga': command = 'fpga_prog ' + fw_path - print "Running command : ", command + print("Running command : ", command) process = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -222,16 +255,16 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if output == '' and process.poll() is not None: break if output: - print output.strip() + print(output.strip()) rc = process.poll() - return rc + return True elif 'cpld' in fw_type: command = 'ispvm ' + fw_path if fw_extra is not None: command = 'ispvm -c ' + \ str(fw_extra) + " " + os.path.abspath(fw_path) - print "Running command : ", command + print("Running command : ", command) process = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -240,8 +273,8 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if output == '' and process.poll() is not None: break if output: - print output.strip() + print(output.strip()) rc = process.poll() - return rc + return True - return None + return False 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 aaf0dae543b7..a84ed4a5946f 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 @@ -6,6 +6,8 @@ import subprocess import requests import os +import pexpect +import base64 try: from sonic_fwmgr.fwgmr_base import FwMgrUtilBase @@ -29,6 +31,7 @@ def __init__(self): self.switchboard_cpld2_path = "/sys/devices/platform/%s.switchboard/CPLD2/getreg" % self.platform_name self.switchboard_cpld3_path = "/sys/devices/platform/%s.switchboard/CPLD3/getreg" % self.platform_name self.switchboard_cpld4_path = "/sys/devices/platform/%s.switchboard/CPLD4/getreg" % self.platform_name + self.bmc_pwd_path = "/usr/local/etc/bmcpwd" def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) @@ -40,6 +43,19 @@ def __get_register_value(self, path, register): else: return raw_data.strip() + def get_bmc_pass(self): + with open(self.bmc_pwd_path) as file: + data = file.read() + + key = "bmc" + dec = [] + enc = base64.urlsafe_b64decode(data) + for i in range(len(enc)): + key_c = key[i % len(key)] + dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) + dec.append(dec_c) + return "".join(dec) + def get_bmc_version(self): """Get BMC version from SONiC :returns: version string @@ -109,6 +125,8 @@ def get_bios_version(self): p = subprocess.Popen( ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) raw_data = str(p.communicate()[0]) + if raw_data == '': + return str(None) raw_data_list = raw_data.split("\n") bios_version = raw_data_list[0] if len( raw_data_list) == 1 else raw_data_list[-2] @@ -129,6 +147,7 @@ def get_onie_version(self): onie_version_raw = line.split('=') onie_verison = onie_version_raw[1].strip() break + onie_config_file.close() return str(onie_verison) def get_pcie_version(self): @@ -177,43 +196,57 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): """ if fw_type == 'bmc': - # Copy BMC image file to BMC - scp_command = 'scp ' + \ - os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/' - - print "Uploading image to BMC..." - print "Running command : ", scp_command - print "Please enter the BMC password" - p = subprocess.Popen( - scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err = p.communicate() - - if err != "": - print "Failed" - return False - - print "Installing BMC image..." + 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 filename_w_ext = os.path.basename(fw_path) json_data = dict() - json_data["data"] = "flashcp /home/root/" + \ - filename_w_ext + " /dev/mtd5" - json_data["timeout"] = 300 - - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code == 200: - print "DONE, Rebooting BMC....." + json_data["path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext + json_data["password"] = bmc_pwd + fw_extra_str = str(fw_extra).lower() + flash = fw_extra_str if fw_extra_str in [ + "master", "slave", "both"] else "both" + json_data["flash"] = flash + + if flash == "both": + print("Installing BMC as master mode...") + json_data["flash"] = "master" + r = requests.post(self.bmc_info_url, json=json_data) + return_data = r.json() + if r.status_code != 200 or 'success' not in return_data.get('result'): + print("Failed") + return False + print("Done") + json_data["flash"] = "slave" + + print("Installing BMC as %s mode..." % json_data["flash"]) + r = requests.post(self.bmc_info_url, json=json_data) + return_data = r.json() + if r.status_code == 200 and 'success' in return_data.get('result'): + print("Done, Rebooting BMC.....") reboot_dict = dict() - reboot_dict["data"] = "reboot" - r = requests.post(self.bmc_raw_command_url, json=reboot_dict) + reboot_dict["reboot"] = "yes" + r = requests.post(self.bmc_info_url, json=reboot_dict) + return True else: - print "Failed" + print("Failed") return False elif fw_type == 'fpga': command = 'fpga_prog ' + fw_path - print "Running command : ", command + print("Running command : ", command) process = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -222,16 +255,16 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if output == '' and process.poll() is not None: break if output: - print output.strip() + print(output.strip()) rc = process.poll() - return rc + return True elif 'cpld' in fw_type: command = 'ispvm ' + fw_path if fw_extra is not None: command = 'ispvm -c ' + \ str(fw_extra) + " " + os.path.abspath(fw_path) - print "Running command : ", command + print("Running command : ", command) process = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -240,8 +273,8 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if output == '' and process.poll() is not None: break if output: - print output.strip() + print(output.strip()) rc = process.poll() - return rc + return True - return None + return False 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 58b5a4ece421..230f652cd639 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 @@ -6,6 +6,8 @@ import subprocess import requests import os +import pexpect +import base64 try: from sonic_fwmgr.fwgmr_base import FwMgrUtilBase @@ -29,6 +31,7 @@ def __init__(self): self.switchboard_cpld2_path = "/sys/devices/platform/%s.switchboard/CPLD2/getreg" % self.platform_name self.switchboard_cpld3_path = "/sys/devices/platform/%s.switchboard/CPLD3/getreg" % self.platform_name self.switchboard_cpld4_path = "/sys/devices/platform/%s.switchboard/CPLD4/getreg" % self.platform_name + self.bmc_pwd_path = "/usr/local/etc/bmcpwd" def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) @@ -40,6 +43,19 @@ def __get_register_value(self, path, register): else: return raw_data.strip() + def get_bmc_pass(self): + with open(self.bmc_pwd_path) as file: + data = file.read() + + key = "bmc" + dec = [] + enc = base64.urlsafe_b64decode(data) + for i in range(len(enc)): + key_c = key[i % len(key)] + dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) + dec.append(dec_c) + return "".join(dec) + def get_bmc_version(self): """Get BMC version from SONiC :returns: version string @@ -109,6 +125,8 @@ def get_bios_version(self): p = subprocess.Popen( ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) raw_data = str(p.communicate()[0]) + if raw_data == '': + return str(None) raw_data_list = raw_data.split("\n") bios_version = raw_data_list[0] if len( raw_data_list) == 1 else raw_data_list[-2] @@ -129,10 +147,11 @@ def get_onie_version(self): onie_version_raw = line.split('=') onie_verison = onie_version_raw[1].strip() break + onie_config_file.close() return str(onie_verison) def get_pcie_version(self): - """Get PCiE version from SONiC + """Get PCiE version from SONiC :returns: version dict { "PCIE_FW_LOADER": "2.5", "PCIE_FW": "D102_08" } """ @@ -177,43 +196,57 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): """ if fw_type == 'bmc': - # Copy BMC image file to BMC - scp_command = 'scp ' + \ - os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/' - - print "Uploading image to BMC..." - print "Running command : ", scp_command - print "Please enter the BMC password" - p = subprocess.Popen( - scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err = p.communicate() - - if err != "": - print "Failed" - return False - - print "Installing BMC image..." + 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 filename_w_ext = os.path.basename(fw_path) json_data = dict() - json_data["data"] = "flashcp /home/root/" + \ - filename_w_ext + " /dev/mtd5" - json_data["timeout"] = 300 - - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code == 200: - print "DONE, Rebooting BMC....." + json_data["path"] = "root@127.0.0.1:/home/root/%s" % filename_w_ext + json_data["password"] = bmc_pwd + fw_extra_str = str(fw_extra).lower() + flash = fw_extra_str if fw_extra_str in [ + "master", "slave", "both"] else "both" + json_data["flash"] = flash + + if flash == "both": + print("Installing BMC as master mode...") + json_data["flash"] = "master" + r = requests.post(self.bmc_info_url, json=json_data) + return_data = r.json() + if r.status_code != 200 or 'success' not in return_data.get('result'): + print("Failed") + return False + print("Done") + json_data["flash"] = "slave" + + print("Installing BMC as %s mode..." % json_data["flash"]) + r = requests.post(self.bmc_info_url, json=json_data) + return_data = r.json() + if r.status_code == 200 and 'success' in return_data.get('result'): + print("Done, Rebooting BMC.....") reboot_dict = dict() - reboot_dict["data"] = "reboot" - r = requests.post(self.bmc_raw_command_url, json=reboot_dict) + reboot_dict["reboot"] = "yes" + r = requests.post(self.bmc_info_url, json=reboot_dict) + return True else: - print "Failed" + print("Failed") return False elif fw_type == 'fpga': command = 'fpga_prog ' + fw_path - print "Running command : ", command + print("Running command : ", command) process = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -222,16 +255,16 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if output == '' and process.poll() is not None: break if output: - print output.strip() + print(output.strip()) rc = process.poll() - return rc + return True elif 'cpld' in fw_type: command = 'ispvm ' + fw_path if fw_extra is not None: command = 'ispvm -c ' + \ str(fw_extra) + " " + os.path.abspath(fw_path) - print "Running command : ", command + print("Running command : ", command) process = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -240,8 +273,8 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): if output == '' and process.poll() is not None: break if output: - print output.strip() + print(output.strip()) rc = process.poll() - return rc + return True return None