Skip to content

Commit

Permalink
Fix build issue: cannot import name FW_AUTO_ERR_UKNOWN- required modu…
Browse files Browse the repository at this point in the history
…le not found (#9764)
  • Loading branch information
Junchao-Mellanox authored and judyjoseph committed Jan 17, 2022
1 parent eb48a8c commit ba28f10
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
59 changes: 32 additions & 27 deletions platform/mellanox/mlnx-platform-api/sonic_platform/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
from sonic_platform_base.component_base import ComponentBase, \
FW_AUTO_INSTALLED, \
FW_AUTO_ERR_BOOT_TYPE, \
FW_AUTO_ERR_IMAGE, \
FW_AUTO_ERR_UKNOWN
FW_AUTO_ERR_IMAGE

# Temp workaround to fix build issue, shall be refactor once sonic-platform-common submodule pointer is updated
try:
from sonic_platform_base.component_base import FW_AUTO_ERR_UNKNOWN
except ImportError as e:
from sonic_platform_base.component_base import FW_AUTO_ERR_UKNOWN as FW_AUTO_ERR_UNKNOWN
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -138,9 +143,9 @@ def __mount_onie_fs(self):
self.__umount_onie_fs()

cmd = "fdisk -l | grep 'ONIE boot' | awk '{print $1}'"
fs_path = subprocess.check_output(cmd,
stderr=subprocess.STDOUT,
shell=True,
fs_path = subprocess.check_output(cmd,
stderr=subprocess.STDOUT,
shell=True,
universal_newlines=True).rstrip('\n')

os.mkdir(fs_mountpoint)
Expand Down Expand Up @@ -194,8 +199,8 @@ def __is_update_staged(self, image_path):
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING

try:
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
universal_newlines=True).rstrip('\n')
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
Expand Down Expand Up @@ -281,8 +286,8 @@ def get_onie_firmware_info(self, image_path):
cmd = self.ONIE_IMAGE_INFO_COMMAND.format(image_path)

try:
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
universal_newlines=True).rstrip('\n')
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to get ONIE firmware info: {}".format(str(e)))
Expand All @@ -303,8 +308,8 @@ def update_firmware(self, image_path):
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING

try:
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
universal_newlines=True).rstrip('\n')
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
Expand Down Expand Up @@ -371,7 +376,7 @@ def auto_update_firmware(self, image_path, boot_action):
# Successful update
return FW_AUTO_INSTALLED
# Failed update (unknown reason)
return FW_AUTO_ERR_UKNOWN
return FW_AUTO_ERR_UNKNOWN

# boot_type did not match (skip)
return FW_AUTO_ERR_BOOT_TYPE
Expand All @@ -395,10 +400,10 @@ def _read_generic_file(filename, len, ignore_errors=False):
@staticmethod
def _get_command_result(cmdline):
try:
proc = subprocess.Popen(cmdline,
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT,
proc = subprocess.Popen(cmdline,
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT,
universal_newlines=True)
stdout = proc.communicate()[0]
rc = proc.wait()
Expand Down Expand Up @@ -510,7 +515,7 @@ def __install_firmware(self, image_path):
def auto_update_firmware(self, image_path, boot_action):
"""
Handling of attempted automatic update for a SSD of a Mellanox switch.
Will first check the image_path to determine if a post-install reboot is required,
Will first check the image_path to determine if a post-install reboot is required,
then compares it against boot_action to determine whether to proceed with install.
"""

Expand All @@ -529,14 +534,14 @@ def auto_update_firmware(self, image_path, boot_action):
supported_boot += ['warm', 'fast', 'none', 'any']
except RuntimeError:
# Unknown error from firmware probe
return FW_AUTO_ERR_UKNOWN
return FW_AUTO_ERR_UNKNOWN

if boot_action in supported_boot:
if self.update_firmware(image_path):
# Successful update
return FW_AUTO_INSTALLED
# Failed update (unknown reason)
return FW_AUTO_ERR_UKNOWN
return FW_AUTO_ERR_UNKNOWN

# boot_type did not match (skip)
return FW_AUTO_ERR_BOOT_TYPE
Expand All @@ -545,8 +550,8 @@ def get_firmware_version(self):
cmd = self.SSD_INFO_COMMAND

try:
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
universal_newlines=True).rstrip('\n')
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to get {} info: {}".format(self.name, str(e)))
Expand All @@ -561,8 +566,8 @@ def get_available_firmware_version(self, image_path):
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)

try:
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
universal_newlines=True).rstrip('\n')
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
Expand Down Expand Up @@ -596,8 +601,8 @@ def get_firmware_update_notification(self, image_path):
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)

try:
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
output = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
universal_newlines=True).rstrip('\n')
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
Expand Down Expand Up @@ -670,8 +675,8 @@ def get_firmware_version(self):
cmd = self.BIOS_VERSION_COMMAND

try:
version = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
version = subprocess.check_output(cmd.split(),
stderr=subprocess.STDOUT,
universal_newlines=True).rstrip('\n')
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to get {} version: {}".format(self.name, str(e)))
Expand Down
15 changes: 10 additions & 5 deletions platform/mellanox/mlnx-platform-api/tests/test_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
from sonic_platform_base.component_base import ComponentBase, \
FW_AUTO_INSTALLED, \
FW_AUTO_ERR_BOOT_TYPE, \
FW_AUTO_ERR_IMAGE, \
FW_AUTO_ERR_UKNOWN
FW_AUTO_ERR_IMAGE
# Temp workaround to fix build issue, shall be refactor once sonic-platform-common submodule pointer is updated
try:
from sonic_platform_base.component_base import FW_AUTO_ERR_UNKNOWN
except ImportError as e:
from sonic_platform_base.component_base import FW_AUTO_ERR_UKNOWN as FW_AUTO_ERR_UNKNOWN


def mock_update_firmware_success(image_path):
return True
Expand All @@ -50,14 +55,14 @@ def mock_update_notification_error(image_path):
test_data_default = [
(None, False, None, FW_AUTO_ERR_IMAGE),
(None, True, 'warm', FW_AUTO_ERR_BOOT_TYPE),
(mock_update_firmware_fail, True, 'cold', FW_AUTO_ERR_UKNOWN),
(mock_update_firmware_fail, True, 'cold', FW_AUTO_ERR_UNKNOWN),
(mock_update_firmware_success, True, 'cold', FW_AUTO_INSTALLED)
]

test_data_ssd = [
(None, None, False, None, FW_AUTO_ERR_IMAGE),
(None, mock_update_notification_error, True, None, FW_AUTO_ERR_UKNOWN),
(mock_update_firmware_fail, mock_update_notification_cold_boot, True, 'cold', FW_AUTO_ERR_UKNOWN),
(None, mock_update_notification_error, True, None, FW_AUTO_ERR_UNKNOWN),
(mock_update_firmware_fail, mock_update_notification_cold_boot, True, 'cold', FW_AUTO_ERR_UNKNOWN),
(mock_update_firmware_success, mock_update_notification_cold_boot, True, 'warm', FW_AUTO_ERR_BOOT_TYPE),
(mock_update_firmware_success, mock_update_notification_cold_boot, True, 'cold', FW_AUTO_INSTALLED),
(mock_update_firmware_success, mock_update_notification_warm_boot, True, 'warm', FW_AUTO_INSTALLED),
Expand Down

0 comments on commit ba28f10

Please sign in to comment.