Fix build issue: cannot import name FW_AUTO_ERR_UKNOWN- required module not found (#9764)
This commit is contained in:
parent
eb48a8ce14
commit
ba28f10b25
@ -37,8 +37,13 @@ try:
|
|||||||
from sonic_platform_base.component_base import ComponentBase, \
|
from sonic_platform_base.component_base import ComponentBase, \
|
||||||
FW_AUTO_INSTALLED, \
|
FW_AUTO_INSTALLED, \
|
||||||
FW_AUTO_ERR_BOOT_TYPE, \
|
FW_AUTO_ERR_BOOT_TYPE, \
|
||||||
FW_AUTO_ERR_IMAGE, \
|
FW_AUTO_ERR_IMAGE
|
||||||
FW_AUTO_ERR_UKNOWN
|
|
||||||
|
# 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:
|
except ImportError as e:
|
||||||
raise ImportError(str(e) + "- required module not found")
|
raise ImportError(str(e) + "- required module not found")
|
||||||
|
|
||||||
@ -138,9 +143,9 @@ class ONIEUpdater(object):
|
|||||||
self.__umount_onie_fs()
|
self.__umount_onie_fs()
|
||||||
|
|
||||||
cmd = "fdisk -l | grep 'ONIE boot' | awk '{print $1}'"
|
cmd = "fdisk -l | grep 'ONIE boot' | awk '{print $1}'"
|
||||||
fs_path = subprocess.check_output(cmd,
|
fs_path = subprocess.check_output(cmd,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
shell=True,
|
shell=True,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
|
|
||||||
os.mkdir(fs_mountpoint)
|
os.mkdir(fs_mountpoint)
|
||||||
@ -194,8 +199,8 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(),
|
output = subprocess.check_output(cmd.split(),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
||||||
@ -281,8 +286,8 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_IMAGE_INFO_COMMAND.format(image_path)
|
cmd = self.ONIE_IMAGE_INFO_COMMAND.format(image_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(),
|
output = subprocess.check_output(cmd.split(),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get ONIE firmware info: {}".format(str(e)))
|
raise RuntimeError("Failed to get ONIE firmware info: {}".format(str(e)))
|
||||||
@ -303,8 +308,8 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(),
|
output = subprocess.check_output(cmd.split(),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
||||||
@ -371,7 +376,7 @@ class Component(ComponentBase):
|
|||||||
# Successful update
|
# Successful update
|
||||||
return FW_AUTO_INSTALLED
|
return FW_AUTO_INSTALLED
|
||||||
# Failed update (unknown reason)
|
# Failed update (unknown reason)
|
||||||
return FW_AUTO_ERR_UKNOWN
|
return FW_AUTO_ERR_UNKNOWN
|
||||||
|
|
||||||
# boot_type did not match (skip)
|
# boot_type did not match (skip)
|
||||||
return FW_AUTO_ERR_BOOT_TYPE
|
return FW_AUTO_ERR_BOOT_TYPE
|
||||||
@ -395,10 +400,10 @@ class Component(ComponentBase):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_command_result(cmdline):
|
def _get_command_result(cmdline):
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(cmdline,
|
proc = subprocess.Popen(cmdline,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
shell=True,
|
shell=True,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
stdout = proc.communicate()[0]
|
stdout = proc.communicate()[0]
|
||||||
rc = proc.wait()
|
rc = proc.wait()
|
||||||
@ -510,7 +515,7 @@ class ComponentSSD(Component):
|
|||||||
def auto_update_firmware(self, image_path, boot_action):
|
def auto_update_firmware(self, image_path, boot_action):
|
||||||
"""
|
"""
|
||||||
Handling of attempted automatic update for a SSD of a Mellanox switch.
|
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.
|
then compares it against boot_action to determine whether to proceed with install.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -529,14 +534,14 @@ class ComponentSSD(Component):
|
|||||||
supported_boot += ['warm', 'fast', 'none', 'any']
|
supported_boot += ['warm', 'fast', 'none', 'any']
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
# Unknown error from firmware probe
|
# Unknown error from firmware probe
|
||||||
return FW_AUTO_ERR_UKNOWN
|
return FW_AUTO_ERR_UNKNOWN
|
||||||
|
|
||||||
if boot_action in supported_boot:
|
if boot_action in supported_boot:
|
||||||
if self.update_firmware(image_path):
|
if self.update_firmware(image_path):
|
||||||
# Successful update
|
# Successful update
|
||||||
return FW_AUTO_INSTALLED
|
return FW_AUTO_INSTALLED
|
||||||
# Failed update (unknown reason)
|
# Failed update (unknown reason)
|
||||||
return FW_AUTO_ERR_UKNOWN
|
return FW_AUTO_ERR_UNKNOWN
|
||||||
|
|
||||||
# boot_type did not match (skip)
|
# boot_type did not match (skip)
|
||||||
return FW_AUTO_ERR_BOOT_TYPE
|
return FW_AUTO_ERR_BOOT_TYPE
|
||||||
@ -545,8 +550,8 @@ class ComponentSSD(Component):
|
|||||||
cmd = self.SSD_INFO_COMMAND
|
cmd = self.SSD_INFO_COMMAND
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(),
|
output = subprocess.check_output(cmd.split(),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} info: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} info: {}".format(self.name, str(e)))
|
||||||
@ -561,8 +566,8 @@ class ComponentSSD(Component):
|
|||||||
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(),
|
output = subprocess.check_output(cmd.split(),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
||||||
@ -596,8 +601,8 @@ class ComponentSSD(Component):
|
|||||||
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(),
|
output = subprocess.check_output(cmd.split(),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
||||||
@ -670,8 +675,8 @@ class ComponentBIOS(Component):
|
|||||||
cmd = self.BIOS_VERSION_COMMAND
|
cmd = self.BIOS_VERSION_COMMAND
|
||||||
|
|
||||||
try:
|
try:
|
||||||
version = subprocess.check_output(cmd.split(),
|
version = subprocess.check_output(cmd.split(),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True).rstrip('\n')
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} version: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} version: {}".format(self.name, str(e)))
|
||||||
|
@ -29,8 +29,13 @@ from sonic_platform.component import Component, ComponentSSD
|
|||||||
from sonic_platform_base.component_base import ComponentBase, \
|
from sonic_platform_base.component_base import ComponentBase, \
|
||||||
FW_AUTO_INSTALLED, \
|
FW_AUTO_INSTALLED, \
|
||||||
FW_AUTO_ERR_BOOT_TYPE, \
|
FW_AUTO_ERR_BOOT_TYPE, \
|
||||||
FW_AUTO_ERR_IMAGE, \
|
FW_AUTO_ERR_IMAGE
|
||||||
FW_AUTO_ERR_UKNOWN
|
# 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):
|
def mock_update_firmware_success(image_path):
|
||||||
return True
|
return True
|
||||||
@ -50,14 +55,14 @@ def mock_update_notification_error(image_path):
|
|||||||
test_data_default = [
|
test_data_default = [
|
||||||
(None, False, None, FW_AUTO_ERR_IMAGE),
|
(None, False, None, FW_AUTO_ERR_IMAGE),
|
||||||
(None, True, 'warm', FW_AUTO_ERR_BOOT_TYPE),
|
(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)
|
(mock_update_firmware_success, True, 'cold', FW_AUTO_INSTALLED)
|
||||||
]
|
]
|
||||||
|
|
||||||
test_data_ssd = [
|
test_data_ssd = [
|
||||||
(None, None, False, None, FW_AUTO_ERR_IMAGE),
|
(None, None, False, None, FW_AUTO_ERR_IMAGE),
|
||||||
(None, mock_update_notification_error, True, None, 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_UKNOWN),
|
(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, '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_cold_boot, True, 'cold', FW_AUTO_INSTALLED),
|
||||||
(mock_update_firmware_success, mock_update_notification_warm_boot, True, 'warm', FW_AUTO_INSTALLED),
|
(mock_update_firmware_success, mock_update_notification_warm_boot, True, 'warm', FW_AUTO_INSTALLED),
|
||||||
|
Loading…
Reference in New Issue
Block a user