Skip to content

Commit

Permalink
[platform] [mellanox] Use correct API call to update firmware in auto…
Browse files Browse the repository at this point in the history
…_update_firmware (#8961)

Why I did it
The fwutil update all utility expects the auto_update_firmware method in the Platform API to execute the update_firmware() call and not the install_firmware() call.

How I did it
Changed the method in the mellanox platform API component implementation.

How to verify it
Run fwutil update all with a CPLD update on a Mellanox platform and verify that it properly updates the firmware using the MPFA file.
  • Loading branch information
alexrallen authored and judyjoseph committed Oct 21, 2021
1 parent dcd389f commit 3e8a612
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def auto_update_firmware(self, image_path, boot_action):
return FW_AUTO_ERR_IMAGE

if boot_action in default_supported_boot:
if self.install_firmware(image_path):
if self.update_firmware(image_path):
# Successful update
return FW_AUTO_INSTALLED
# Failed update (unknown reason)
Expand Down Expand Up @@ -520,7 +520,7 @@ def auto_update_firmware(self, image_path, boot_action):
return FW_AUTO_ERR_UKNOWN

if boot_action in supported_boot:
if self.install_firmware(image_path):
if self.update_firmware(image_path):
# Successful update
return FW_AUTO_INSTALLED
# Failed update (unknown reason)
Expand Down
30 changes: 15 additions & 15 deletions platform/mellanox/mlnx-platform-api/tests/test_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
FW_AUTO_ERR_IMAGE, \
FW_AUTO_ERR_UKNOWN

def mock_install_firmware_success(image_path):
def mock_update_firmware_success(image_path):
return True

def mock_install_firmware_fail(image_path):
def mock_update_firmware_fail(image_path):
return False

def mock_update_notification_cold_boot(image_path):
Expand All @@ -34,45 +34,45 @@ 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_install_firmware_fail, True, 'cold', FW_AUTO_ERR_UKNOWN),
(mock_install_firmware_success, True, 'cold', FW_AUTO_INSTALLED)
(mock_update_firmware_fail, True, 'cold', FW_AUTO_ERR_UKNOWN),
(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_install_firmware_fail, mock_update_notification_cold_boot, True, 'cold', FW_AUTO_ERR_UKNOWN),
(mock_install_firmware_success, mock_update_notification_cold_boot, True, 'warm', FW_AUTO_ERR_BOOT_TYPE),
(mock_install_firmware_success, mock_update_notification_cold_boot, True, 'cold', FW_AUTO_INSTALLED),
(mock_install_firmware_success, mock_update_notification_warm_boot, True, 'warm', FW_AUTO_INSTALLED),
(mock_install_firmware_success, mock_update_notification_warm_boot, True, 'cold', FW_AUTO_INSTALLED)
(mock_update_firmware_fail, mock_update_notification_cold_boot, True, 'cold', FW_AUTO_ERR_UKNOWN),
(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),
(mock_update_firmware_success, mock_update_notification_warm_boot, True, 'cold', FW_AUTO_INSTALLED)
]

@pytest.mark.parametrize('install_func, image_found, boot_type, expect', test_data_default)
def test_auto_update_firmware_default(monkeypatch, install_func, image_found, boot_type, expect):
@pytest.mark.parametrize('update_func, image_found, boot_type, expect', test_data_default)
def test_auto_update_firmware_default(monkeypatch, update_func, image_found, boot_type, expect):

def mock_path_exists(path):
return image_found

test_component = Component()

monkeypatch.setattr(test_component, 'install_firmware', install_func)
monkeypatch.setattr(test_component, 'update_firmware', update_func)
monkeypatch.setattr(os.path, 'exists', mock_path_exists)

result = test_component.auto_update_firmware(None, boot_type)

assert result == expect


@pytest.mark.parametrize('install_func, notify, image_found, boot_type, expect', test_data_ssd)
def test_auto_update_firmware_default(monkeypatch, install_func, notify, image_found, boot_type, expect):
@pytest.mark.parametrize('update_func, notify, image_found, boot_type, expect', test_data_ssd)
def test_auto_update_firmware_default(monkeypatch, update_func, notify, image_found, boot_type, expect):

def mock_path_exists(path):
return image_found

test_component_ssd = ComponentSSD()

monkeypatch.setattr(test_component_ssd, 'install_firmware', install_func)
monkeypatch.setattr(test_component_ssd, 'update_firmware', update_func)
monkeypatch.setattr(test_component_ssd, 'get_firmware_update_notification', notify)
monkeypatch.setattr(os.path, 'exists', mock_path_exists)

Expand Down

0 comments on commit 3e8a612

Please sign in to comment.