@@ -41,7 +41,7 @@ def test_main_success_bmc_firmware_updated(self, mock_logger_class, mock_exit, m
4141 mock_bmc .update_firmware .return_value = (0 , ('Success' , ['BMC_FW_0' , 'OTHER_FW' ]))
4242 mock_bmc .get_firmware_id .return_value = 'BMC_FW_0'
4343 mock_bmc .request_bmc_reset .return_value = (0 , 'BMC reset successful' )
44- mock_bmc .get_status .return_value = True
44+ mock_bmc .wait_until_redfish_ready .return_value = 0
4545
4646 test_args = ['bmc_fw_update.py' , '/path/to/firmware.bin' ]
4747 with mock .patch .dict (sys .modules , {'sonic_platform' : mock_sonic_platform }):
@@ -53,7 +53,8 @@ def test_main_success_bmc_firmware_updated(self, mock_logger_class, mock_exit, m
5353 mock_bmc .update_firmware .assert_called_once_with ('/path/to/firmware.bin' )
5454 mock_bmc .get_firmware_id .assert_called_once ()
5555 mock_bmc .request_bmc_reset .assert_called_once ()
56- mock_bmc .get_status .assert_called_once ()
56+ mock_bmc .wait_until_redfish_ready .assert_called_once ()
57+ mock_bmc .get_status .assert_not_called ()
5758 mock_sleep .assert_called_once_with (20 )
5859 mock_exit .assert_not_called ()
5960
@@ -143,9 +144,10 @@ def test_main_update_firmware_failure(self, mock_logger_class, mock_exit):
143144 mock_logger .log_error .assert_called_once_with ('Failed to update BMC firmware. Error 1: Update failed' )
144145 mock_exit .assert_called_once_with (1 )
145146
147+ @mock .patch ('sonic_platform_base.bmc_fw_update.time.sleep' )
146148 @mock .patch ('sys.exit' )
147149 @mock .patch ('sonic_py_common.logger.Logger' )
148- def test_main_bmc_reset_failure (self , mock_logger_class , mock_exit ):
150+ def test_main_bmc_reset_failure (self , mock_logger_class , mock_exit , mock_sleep ):
149151 """Test main when BMC reset fails"""
150152 mock_logger = mock .MagicMock ()
151153 mock_bmc = mock .MagicMock ()
@@ -159,6 +161,9 @@ def test_main_bmc_reset_failure(self, mock_logger_class, mock_exit):
159161 mock_bmc .update_firmware .return_value = (0 , ('Success' , ['BMC_FW_0' ]))
160162 mock_bmc .get_firmware_id .return_value = 'BMC_FW_0'
161163 mock_bmc .request_bmc_reset .return_value = (1 , 'Reset failed' )
164+ # sys.exit is mocked to a no-op, so main() falls through past the reset
165+ # failure; keep the readiness probe benign so it adds no extra error/exit.
166+ mock_bmc .wait_until_redfish_ready .return_value = 0
162167
163168 test_args = ['bmc_fw_update.py' , '/path/to/firmware.bin' ]
164169 with mock .patch .dict (sys .modules , {'sonic_platform' : mock_sonic_platform }):
@@ -171,8 +176,8 @@ def test_main_bmc_reset_failure(self, mock_logger_class, mock_exit):
171176 @mock .patch ('sonic_platform_base.bmc_fw_update.time.sleep' )
172177 @mock .patch ('sys.exit' )
173178 @mock .patch ('sonic_py_common.logger.Logger' )
174- def test_main_bmc_waiting_after_restart (self , mock_logger_class , mock_exit , mock_sleep ):
175- """Test waiting loop when BMC is not yet operational after restart"""
179+ def test_main_redfish_not_ready_after_restart (self , mock_logger_class , mock_exit , mock_sleep ):
180+ """Test failure when the Redfish service does not become ready after restart"""
176181 mock_logger = mock .MagicMock ()
177182 mock_bmc = mock .MagicMock ()
178183 mock_chassis = mock .MagicMock ()
@@ -185,44 +190,18 @@ def test_main_bmc_waiting_after_restart(self, mock_logger_class, mock_exit, mock
185190 mock_bmc .update_firmware .return_value = (0 , ('Success' , ['BMC_FW_0' ]))
186191 mock_bmc .get_firmware_id .return_value = 'BMC_FW_0'
187192 mock_bmc .request_bmc_reset .return_value = (0 , 'BMC reset successful' )
188- mock_bmc .get_status .side_effect = [False , True ]
193+ # -6 == ERR_CODE_TIMEOUT: readiness never reached before the deadline.
194+ mock_bmc .wait_until_redfish_ready .return_value = - 6
189195
190196 test_args = ['bmc_fw_update.py' , '/path/to/firmware.bin' ]
191197 with mock .patch .dict (sys .modules , {'sonic_platform' : mock_sonic_platform }):
192198 with mock .patch .object (sys , 'argv' , test_args ):
193199 bmc_fw_update .main ()
194200
195- mock_logger .log_notice .assert_any_call ("Waiting for BMC to restart..." )
196- assert mock_bmc .get_status .call_count == 2
197- assert mock_sleep .call_count == 2
198- mock_sleep .assert_has_calls ([mock .call (20 ), mock .call (20 )])
199- mock_exit .assert_not_called ()
200-
201- @mock .patch ('sonic_platform_base.bmc_fw_update.time.sleep' )
202- @mock .patch ('sys.exit' )
203- @mock .patch ('sonic_py_common.logger.Logger' )
204- def test_main_bmc_not_operational_after_restart (self , mock_logger_class , mock_exit , mock_sleep ):
205- """Test failure when BMC does not become operational after restart"""
206- mock_logger = mock .MagicMock ()
207- mock_bmc = mock .MagicMock ()
208- mock_chassis = mock .MagicMock ()
209- mock_platform = mock .MagicMock ()
210- mock_chassis .get_bmc .return_value = mock_bmc
211- mock_platform .get_chassis .return_value = mock_chassis
212- mock_sonic_platform = mock .MagicMock ()
213- mock_sonic_platform .platform .Platform .return_value = mock_platform
214- mock_logger_class .return_value = mock_logger
215- mock_bmc .update_firmware .return_value = (0 , ('Success' , ['BMC_FW_0' ]))
216- mock_bmc .get_firmware_id .return_value = 'BMC_FW_0'
217- mock_bmc .request_bmc_reset .return_value = (0 , 'BMC reset successful' )
218- mock_bmc .get_status .return_value = False
219-
220- test_args = ['bmc_fw_update.py' , '/path/to/firmware.bin' ]
221- with mock .patch .dict (sys .modules , {'sonic_platform' : mock_sonic_platform }):
222- with mock .patch .object (sys , 'argv' , test_args ):
223- bmc_fw_update .main ()
224-
225- mock_logger .log_error .assert_any_call ("BMC did not become operational after restart" )
226- assert mock_bmc .get_status .call_count == 5
227- assert mock_sleep .call_count == 5
201+ # Only the settle sleep runs; the ping wait loop is gone.
202+ mock_bmc .get_status .assert_not_called ()
203+ mock_bmc .wait_until_redfish_ready .assert_called_once ()
204+ mock_sleep .assert_called_once_with (20 )
205+ mock_logger .log_error .assert_any_call (
206+ "BMC Redfish service did not become ready after restart (last error code: -6)" )
228207 mock_exit .assert_called_once_with (1 )
0 commit comments