Skip to content

Commit

Permalink
[device/alibaba]: update fwmgrutil to support new firmware_refresh me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
Wirut Getbamrung committed Mar 17, 2020
1 parent 0ba1e39 commit 1a82bed
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 55 deletions.
40 changes: 19 additions & 21 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 @@ -106,17 +106,19 @@ def get_bmc_version(self):
"""
bmc_version = None
bmc_version_key = "Version"
bmc_info_req = requests.get(self.bmc_info_url, timeout=self.api_time_out)
bmc_info_req = requests.get(
self.bmc_info_url, timeout=self.api_time_out)
if bmc_info_req.status_code == 200:
bmc_info_json = bmc_info_req.json()
bmc_info = bmc_info_json.get('data')
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)
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)
child.timeout=self.api_time_out
child.timeout = self.api_time_out
i = child.expect(["root@240.1.1.1's password:"])
bmc_pwd = self.get_bmc_pass()
if i == 0 and bmc_pwd:
Expand Down Expand Up @@ -146,8 +148,6 @@ def get_cpld_version(self):
fancpld_info_json = fan_cpld_req.json()
fancpld_info_data = fancpld_info_json.get('data')
fan_cpld = fancpld_info_data.get(fan_cpld_key)
print(fan_cpld)
print(fancpld_info_json)

CPLD_B = 'None' if CPLD_B is 'None' else "{}.{}".format(
int(CPLD_B[2], 16), int(CPLD_B[3], 16))
Expand All @@ -171,8 +171,6 @@ def get_cpld_version(self):
cpld_version_dict.update({'CPLD_3': CPLD_3})
cpld_version_dict.update({'CPLD_4': CPLD_4})
cpld_version_dict.update({'CPLD_FAN': FAN_CPLD})
print(cpld_version_dict.keys())
print(cpld_version_dict.keys().sort())

return cpld_version_dict

Expand Down Expand Up @@ -515,7 +513,6 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None):
print("Installing...")
r = requests.post(self.fw_upgrade_url, json=json_data)
if r.status_code != 200 or r.json().get('status') != 'OK':
print(r.json())
self.__update_fw_upgrade_logger(
"bios_upgrade", "fail, message={}".format(r.json().get('messages')))
self.__update_fw_upgrade_logger(
Expand Down Expand Up @@ -760,25 +757,25 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None):
cpld_list = [x.lower() for x in cpld_list] if cpld_list else []
fpga_list = [x.lower() for x in fpga_list] if fpga_list else []
refresh_list = cpld_list + fpga_list
fw_path_list = fw_extra.split(
':') if not fpga_list else fw_extra.split(':') + ["none"]
fw_path_list = str(fw_extra).split(':')
refresh_img_list = ["none" for i in range(len(refresh_list))]

if len(refresh_list) == 0 \
or ((len(fpga_list) > 1 and "fpga" not in fpga_list)) \
or (len(refresh_list) != len(fw_path_list)):
if len(refresh_list) == 0 :
self.__update_fw_upgrade_logger(
"fw_refresh", "fail, message=Invalid input")
return False

for idx in range(0, len(cpld_list)):
fw_path = fw_path_list[idx]
if cpld_list[idx] in ["fan_cpld", "base_cpld"] and not self.upload_file_bmc(fw_path):
self.__update_fw_upgrade_logger(
"cpld_refresh", "fail, message=Unable to upload refresh image to BMC")
return False
for idx in range(0, len(refresh_list)):
if refresh_list[idx] in ["fan_cpld", "base_cpld"]:
if not self.upload_file_bmc(fw_path_list[idx]):
self.__update_fw_upgrade_logger(
"cpld_refresh", "fail, message=Unable to upload refresh image to BMC")
return False
refresh_img_list[idx] = "/home/root/%s" % os.path.basename(
fw_path_list[idx])

json_data = dict()
json_data["Paths"] = fw_path_list
json_data["Paths"] = refresh_img_list
json_data["Names"] = refresh_list
r = requests.post(self.fw_refresh_url, json=json_data)
if r.status_code != 200 or r.json().get('status') != 'OK':
Expand All @@ -797,7 +794,8 @@ def get_running_bmc(self):
"""
running_bmc = "master"
running_bmc_key = "Flash"
bmc_info_req = requests.get(self.bmc_info_url, timeout=self.api_time_out)
bmc_info_req = requests.get(
self.bmc_info_url, timeout=self.api_time_out)
if bmc_info_req.status_code == 200:
bmc_info_json = bmc_info_req.json()
bmc_info = bmc_info_json.get('data')
Expand Down
36 changes: 19 additions & 17 deletions device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,19 @@ def get_bmc_version(self):
"""
bmc_version = None
bmc_version_key = "Version"
bmc_info_req = requests.get(self.bmc_info_url, timeout=self.api_time_out)
bmc_info_req = requests.get(
self.bmc_info_url, timeout=self.api_time_out)
if bmc_info_req.status_code == 200:
bmc_info_json = bmc_info_req.json()
bmc_info = bmc_info_json.get('data')
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)
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)
child.timeout=self.api_time_out
child.timeout = self.api_time_out
i = child.expect(["root@240.1.1.1's password:"])
bmc_pwd = self.get_bmc_pass()
if i == 0 and bmc_pwd:
Expand Down Expand Up @@ -511,7 +513,6 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None):
print("Installing...")
r = requests.post(self.fw_upgrade_url, json=json_data)
if r.status_code != 200 or r.json().get('status') != 'OK':
print(r.json())
self.__update_fw_upgrade_logger(
"bios_upgrade", "fail, message={}".format(r.json().get('messages')))
self.__update_fw_upgrade_logger(
Expand Down Expand Up @@ -756,25 +757,25 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None):
cpld_list = [x.lower() for x in cpld_list] if cpld_list else []
fpga_list = [x.lower() for x in fpga_list] if fpga_list else []
refresh_list = cpld_list + fpga_list
fw_path_list = fw_extra.split(
':') if not fpga_list else fw_extra.split(':') + ["none"]
fw_path_list = str(fw_extra).split(':')
refresh_img_list = ["none" for i in range(len(refresh_list))]

if len(refresh_list) == 0 \
or ((len(fpga_list) > 1 and "fpga" not in fpga_list)) \
or (len(refresh_list) != len(fw_path_list)):
if len(refresh_list) == 0 :
self.__update_fw_upgrade_logger(
"fw_refresh", "fail, message=Invalid input")
return False

for idx in range(0, len(cpld_list)):
fw_path = fw_path_list[idx]
if cpld_list[idx] in ["fan_cpld", "base_cpld"] and not self.upload_file_bmc(fw_path):
self.__update_fw_upgrade_logger(
"cpld_refresh", "fail, message=Unable to upload refresh image to BMC")
return False
for idx in range(0, len(refresh_list)):
if refresh_list[idx] in ["fan_cpld", "base_cpld"]:
if not self.upload_file_bmc(fw_path_list[idx]):
self.__update_fw_upgrade_logger(
"cpld_refresh", "fail, message=Unable to upload refresh image to BMC")
return False
refresh_img_list[idx] = "/home/root/%s" % os.path.basename(
fw_path_list[idx])

json_data = dict()
json_data["Paths"] = fw_path_list
json_data["Paths"] = refresh_img_list
json_data["Names"] = refresh_list
r = requests.post(self.fw_refresh_url, json=json_data)
if r.status_code != 200 or r.json().get('status') != 'OK':
Expand All @@ -793,7 +794,8 @@ def get_running_bmc(self):
"""
running_bmc = "master"
running_bmc_key = "Flash"
bmc_info_req = requests.get(self.bmc_info_url, timeout=self.api_time_out)
bmc_info_req = requests.get(
self.bmc_info_url, timeout=self.api_time_out)
if bmc_info_req.status_code == 200:
bmc_info_json = bmc_info_req.json()
bmc_info = bmc_info_json.get('data')
Expand Down
36 changes: 19 additions & 17 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 @@ -106,17 +106,19 @@ def get_bmc_version(self):
"""
bmc_version = None
bmc_version_key = "Version"
bmc_info_req = requests.get(self.bmc_info_url, timeout=self.api_time_out)
bmc_info_req = requests.get(
self.bmc_info_url, timeout=self.api_time_out)
if bmc_info_req.status_code == 200:
bmc_info_json = bmc_info_req.json()
bmc_info = bmc_info_json.get('data')
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)
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)
child.timeout=self.api_time_out
child.timeout = self.api_time_out
i = child.expect(["root@240.1.1.1's password:"])
bmc_pwd = self.get_bmc_pass()
if i == 0 and bmc_pwd:
Expand Down Expand Up @@ -511,7 +513,6 @@ def firmware_upgrade(self, fw_type, fw_path, fw_extra=None):
print("Installing...")
r = requests.post(self.fw_upgrade_url, json=json_data)
if r.status_code != 200 or r.json().get('status') != 'OK':
print(r.json())
self.__update_fw_upgrade_logger(
"bios_upgrade", "fail, message={}".format(r.json().get('messages')))
self.__update_fw_upgrade_logger(
Expand Down Expand Up @@ -756,25 +757,25 @@ def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None):
cpld_list = [x.lower() for x in cpld_list] if cpld_list else []
fpga_list = [x.lower() for x in fpga_list] if fpga_list else []
refresh_list = cpld_list + fpga_list
fw_path_list = fw_extra.split(
':') if not fpga_list else fw_extra.split(':') + ["none"]
fw_path_list = str(fw_extra).split(':')
refresh_img_list = ["none" for i in range(len(refresh_list))]

if len(refresh_list) == 0 \
or ((len(fpga_list) > 1 and "fpga" not in fpga_list)) \
or (len(refresh_list) != len(fw_path_list)):
if len(refresh_list) == 0 :
self.__update_fw_upgrade_logger(
"fw_refresh", "fail, message=Invalid input")
return False

for idx in range(0, len(cpld_list)):
fw_path = fw_path_list[idx]
if cpld_list[idx] in ["fan_cpld", "base_cpld"] and not self.upload_file_bmc(fw_path):
self.__update_fw_upgrade_logger(
"cpld_refresh", "fail, message=Unable to upload refresh image to BMC")
return False
for idx in range(0, len(refresh_list)):
if refresh_list[idx] in ["fan_cpld", "base_cpld"]:
if not self.upload_file_bmc(fw_path_list[idx]):
self.__update_fw_upgrade_logger(
"cpld_refresh", "fail, message=Unable to upload refresh image to BMC")
return False
refresh_img_list[idx] = "/home/root/%s" % os.path.basename(
fw_path_list[idx])

json_data = dict()
json_data["Paths"] = fw_path_list
json_data["Paths"] = refresh_img_list
json_data["Names"] = refresh_list
r = requests.post(self.fw_refresh_url, json=json_data)
if r.status_code != 200 or r.json().get('status') != 'OK':
Expand All @@ -793,7 +794,8 @@ def get_running_bmc(self):
"""
running_bmc = "master"
running_bmc_key = "Flash"
bmc_info_req = requests.get(self.bmc_info_url, timeout=self.api_time_out)
bmc_info_req = requests.get(
self.bmc_info_url, timeout=self.api_time_out)
if bmc_info_req.status_code == 200:
bmc_info_json = bmc_info_req.json()
bmc_info = bmc_info_json.get('data')
Expand Down

0 comments on commit 1a82bed

Please sign in to comment.