Fix build issue: cannot import name FW_AUTO_ERR_UKNOWN- required module not found (#9764)

This commit is contained in:
Junchao-Mellanox 2022-01-14 22:42:53 +08:00 committed by Judy Joseph
parent eb48a8ce14
commit ba28f10b25
2 changed files with 42 additions and 32 deletions

View File

@ -37,8 +37,13 @@ try:
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")
@ -371,7 +376,7 @@ class Component(ComponentBase):
# 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
@ -529,14 +534,14 @@ class ComponentSSD(Component):
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

View File

@ -29,8 +29,13 @@ from sonic_platform.component import Component, ComponentSSD
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
@ -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),