Ejemplo n.º 1
0
 async def test_spawn_companion(self) -> None:
     spawner = CompanionSpawner("idb_path", logger=mock.Mock())
     spawner._log_file_path = mock.Mock()
     spawner.pid_saver = mock.Mock()
     udid = "someUdid"
     with mock.patch(
             "idb.common.companion_spawner.asyncio.create_subprocess_exec",
             new=AsyncMock(),
     ) as exec_mock, mock.patch("idb.common.companion_spawner.open"):
         process_mock = mock.Mock()
         process_mock.stdout.readline = AsyncMock(
             return_value=json.dumps({
                 "hostname": "myHost",
                 "grpc_port": 1234
             }).encode("utf-8"))
         exec_mock.return_value = process_mock
         port = await spawner.spawn_companion(udid)
         exec_mock.assert_called_once_with(
             "idb_path",
             "--udid",
             "someUdid",
             "--grpc-port",
             "0",
             stdout=mock.ANY,
             stdin=mock.ANY,
             stderr=mock.ANY,
         )
         self.assertEqual(port, 1234)
Ejemplo n.º 2
0
 def __init__(
     self,
     port: int,
     host: str,
     target_udid: Optional[str],
     logger: Optional[logging.Logger] = None,
     force_kill_daemon: bool = False,
 ) -> None:
     self.port: int = port
     self.host: str = host
     self.logger: logging.Logger = (
         logger if logger else logging.getLogger("idb_grpc_client")
     )
     self.force_kill_daemon = force_kill_daemon
     self.target_udid = target_udid
     self.daemon_spawner = DaemonSpawner(host=self.host, port=self.port)
     self.daemon_channel: Optional[Channel] = None
     self.daemon_stub: Optional[CompanionServiceStub] = None
     for (call_name, f) in ipc_loader.client_calls(
         daemon_provider=self.provide_client
     ):
         setattr(self, call_name, f)
     self.direct_companion_manager = DirectCompanionManager(logger=self.logger)
     self.companion_spawner = CompanionSpawner(companion_path="idb_companion")
     self.companion_info: Optional[CompanionInfo] = None
Ejemplo n.º 3
0
 async def spawn_notifier(self) -> None:
     if platform == "darwin" and os.path.exists(
             "/usr/local/bin/idb_companion"):
         companion_spawner = CompanionSpawner(
             companion_path="/usr/local/bin/idb_companion",
             logger=self.logger)
         await companion_spawner.spawn_notifier()
Ejemplo n.º 4
0
 async def _spawn_notifier(self) -> None:
     companion_path = self.companion_path
     if companion_path:
         companion_spawner = CompanionSpawner(
             companion_path=companion_path, logger=self.logger
         )
         await companion_spawner.spawn_notifier()
Ejemplo n.º 5
0
 def __init__(self, companion_path: Optional[str], logger: Logger) -> None:
     self._udid_companion_map: Dict[str, CompanionInfo] = {}
     self._udid_target_map: Dict[str, TargetDescription] = {}
     self.companion_spawner = (CompanionSpawner(
         companion_path=companion_path) if companion_path else None)
     self._stub_map: Dict[str, CompanionServiceStub] = {}
     self._logger = logger
Ejemplo n.º 6
0
 async def test_spawn_notifier(self) -> None:
     spawner = CompanionSpawner("idb_path", logger=mock.Mock())
     spawner._log_file_path = mock.Mock()
     spawner._is_notifier_running = mock.Mock(return_value=False)
     spawner.pid_saver = mock.Mock()
     with mock.patch(
             "idb.common.companion_spawner.asyncio.create_subprocess_exec",
             new=AsyncMock(),
     ) as exec_mock, mock.patch("idb.common.companion_spawner.open"):
         process_mock = mock.Mock()
         exec_mock.return_value = process_mock
         await spawner.spawn_notifier()
         exec_mock.assert_called_once_with(
             "idb_path",
             "--notify",
             IDB_LOCAL_TARGETS_FILE,
             stderr=mock.ANY,
             stdout=mock.ANY,
         )
Ejemplo n.º 7
0
 def __init__(
     self,
     companion_path: Optional[str] = None,
     device_set_path: Optional[str] = None,
     prune_dead_companion: bool = True,
     logger: Optional[logging.Logger] = None,
 ) -> None:
     os.makedirs(BASE_IDB_FILE_PATH, exist_ok=True)
     self._logger: logging.Logger = (logger if logger else
                                     logging.getLogger("idb_grpc_client"))
     self._direct_companion_manager = DirectCompanionManager(
         logger=self._logger)
     self._local_targets_manager = LocalTargetsManager(logger=self._logger)
     self._companion_spawner: Optional[CompanionSpawner] = (
         CompanionSpawner(companion_path=companion_path,
                          logger=self._logger)
         if companion_path is not None else None)
     self._prune_dead_companion = prune_dead_companion
Ejemplo n.º 8
0
 async def spawn_companion(self, target_udid: str) -> Optional[CompanionInfo]:
     if self.local_targets_manager.is_local_target_available(
         target_udid=target_udid
     ):
         companion_spawner = CompanionSpawner(
             companion_path="idb_companion", logger=self.logger
         )
         self.logger.info(f"will attempt to spawn a companion for {target_udid}")
         port = await companion_spawner.spawn_companion(target_udid=target_udid)
         if port:
             self.logger.info(f"spawned a companion for {target_udid}")
             host = "localhost"
             companion_info = CompanionInfo(
                 host=host, port=port, udid=target_udid, is_local=True
             )
             self.direct_companion_manager.add_companion(companion_info)
             return companion_info
     return None
Ejemplo n.º 9
0
 async def spawn_notifier(self) -> None:
     if platform == "darwin":
         companion_spawner = CompanionSpawner(
             companion_path="idb_companion", logger=self.logger)
         await companion_spawner.spawn_notifier()
Ejemplo n.º 10
0
 async def test_close(self) -> None:
     spawner = CompanionSpawner("idb_path")
     spawner.companion_processes = [mock.Mock() for _ in range(3)]
     spawner.close()
     for process in spawner.companion_processes:
         process.terminate.assert_called_once()
Ejemplo n.º 11
0
Archivo: grpc.py Proyecto: Vishalan/idb
 async def spawn_notifier(self) -> None:
     if platform == "darwin" and os.path.exists(self.companion_path):
         companion_spawner = CompanionSpawner(
             companion_path=self.companion_path, logger=self.logger)
         await companion_spawner.spawn_notifier()