def _erase_board_simple(self, target, no_reset): """ :param target: target to which perform the erase :param no_reset: erase with/without reset :return: exit code """ if "mount_point" not in target: raise EraseError(message="mount point missing from target", return_code=EXIT_CODE_MOUNT_POINT_MISSING) if "serial_port" not in target: raise EraseError(message="serial port missing from target", return_code=EXIT_CODE_SERIAL_PORT_MISSING) Erase._can_be_erased(target) # Copy ERASE.ACT to target mount point, this will trigger the erasing. destination = MbedCommon.get_binary_destination(target["mount_point"], "ERASE.ACT") with open(destination, "wb"): pass target = MbedCommon.wait_for_file_disappear(target, "ERASE.ACT") if not no_reset: Reset(logger=self.logger).reset_board(target["serial_port"]) self._verify_erase_success(MbedCommon.get_binary_destination( target["mount_point"], "ERASE.ACT")) self.logger.info("erase %s completed", target["target_id"]) return EXIT_CODE_SUCCESS
def test_wait_for_file_disappear_tries_many_times( self, mock_sleep, mock_refresh_target_once): target = {"target_id": "test"} new_target = MbedCommon.wait_for_file_disappear(target, "") self.assertEqual(mock_sleep.call_count, 60) self.assertEqual(mock_refresh_target_once.call_count, 60) self.assertEqual(target, new_target)
def test_get_binary_destination_returns_expected_path(self): mount_point = "/test/mount_point_0_1_0" source = "/workspace/flasher/test.bin" result = MbedCommon.get_binary_destination(mount_point, source) self.assertEqual( result, os.path.abspath(os.path.join("/test/mount_point_0_1_0", "test.bin")))
def try_drag_and_drop_flash(self, source, target, target_filename, no_reset): """ Try to flash the target using drag and drop method. :param source: file to be flashed :param target: target board to be flashed :param no_reset: whether to reset the board after flash :return: 0 if success """ target = MbedCommon.refresh_target(target["target_id"]) if not target: raise FlashError(message="Target ID is missing", return_code=EXIT_CODE_TARGET_ID_MISSING) destination = MbedCommon.get_binary_destination( target["mount_point"], target_filename) try: if 'serial_port' in target and not no_reset: Reset(logger=self.logger).reset_board(target["serial_port"]) sleep(0.1) self.copy_file(source, destination) self.logger.debug("copy finished") target = MbedCommon.wait_for_file_disappear( target, target_filename) if not no_reset: Reset(logger=self.logger).reset_board(target["serial_port"]) sleep(0.4) # verify flashing went as planned self.logger.debug("verifying flash") return self.verify_flash_success( target, MbedCommon.get_binary_destination(target["mount_point"], target_filename)) # In python3 IOError is just an alias for OSError except (OSError, IOError) as error: msg = "File copy failed due to: {}".format(str(error)) self.logger.exception(msg) raise FlashError(message=msg, return_code=EXIT_CODE_OS_ERROR)
def test_wait_for_file_disappear_find_lowercase_htm_file( self, mock_sleep, mock_refresh_target_once, mock_isfile, mock_listdir): target = {"target_id": "test"} new_target = MbedCommon.wait_for_file_disappear(target, "") self.assertEqual(mock_sleep.call_count, 0) self.assertEqual(mock_refresh_target_once.call_count, 1) self.assertEqual(mock_isfile.call_count, 1) self.assertEqual(mock_listdir.call_count, 1) self.assertEqual(new_target, {"mount_point": ""})
def test_wait_for_file_disappear_survives_winerror( self, mock_sleep, mock_refresh_target_once, mock_isfile, mock_listdir): target = {"target_id": "test"} new_target = MbedCommon.wait_for_file_disappear(target, "") self.assertEqual(mock_sleep.call_count, 60) self.assertEqual(mock_refresh_target_once.call_count, 60) self.assertEqual(mock_isfile.call_count, 60) self.assertEqual(mock_listdir.call_count, 60) self.assertEqual(new_target, {"target_id": "test", "mount_point": ""})
def test_refresh_target_returns_empty_list_when_no_devices( self, mock_mbed_lstools_create, mock_sleep): # pylint:disable=too-few-public-methods class MockLS(object): def __init__(self): pass # pylint:disable=no-self-use def list_mbeds(self, filter_function=None): return [] mock_mbed_lstools_create.return_value = MockLS() target = {"target_id": "test_id"} self.assertEqual(None, MbedCommon.refresh_target(target["target_id"]))