diff --git a/lisa/target.py b/lisa/target.py index 69efd5778b720034bd713be129bbbd4c06d35b84..775fa73c80fab7f71eea1ec6ff04dadc97513d80 100644 --- a/lisa/target.py +++ b/lisa/target.py @@ -180,7 +180,7 @@ class TargetConf(SimpleMultiSrcConf, HideExekallID): KeyDesc('excluded-modules', 'List of devlib modules to *not* load', [typing.Sequence[str]]), KeyDesc('file-xfer', 'File transfer method. Can be "sftp" (default) or "scp". (Only valid for linux targets)', [typing.Sequence[str]]), KeyDesc('max-async', 'Maximum number of asynchronous commands in flight at any time', [int, None]), - + KeyDesc('connection-kind', 'Kind of connection to use. One of "ssh", "adb", "host" or None (inferred from target kind).', [typing.Literal['ssh', 'adb', 'host'], None]), )) )) @@ -260,6 +260,7 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): INIT_KWARGS_KEY_MAP = { 'devlib_excluded_modules': ['devlib', 'excluded-modules'], 'devlib_file_xfer': ['devlib', 'file-xfer'], + 'devlib_connection_kind': ['devlib', 'connection-kind'], 'devlib_max_async': ['devlib', 'max-async'], 'wait_boot': ['wait-boot', 'enable'], 'wait_boot_timeout': ['wait-boot', 'timeout'], @@ -274,6 +275,7 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): devlib_platform=None, devlib_excluded_modules=[], devlib_file_xfer=None, wait_boot=True, wait_boot_timeout=10, kernel_src=None, kmod_build_env=None, kmod_make_vars=None, kmod_overlay_backend=None, devlib_max_async=None, + devlib_connection_kind=None, ): # Determine file transfer method. Currently avaliable options # are 'sftp' and 'scp', defaults to sftp. @@ -283,6 +285,7 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): target = self._init_target( kind=kind, + connection_kind=devlib_connection_kind, name=name, workdir=workdir, device=device, @@ -788,7 +791,7 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): return custom_args, cls.from_conf(conf=target_conf, plat_info=platform_info, res_dir=args.res_dir) @classmethod - def _init_target(cls, kind, name, workdir, device, host, + def _init_target(cls, kind, connection_kind, name, workdir, device, host, port, username, password, keyfile, strict_host_check, use_scp, devlib_platform, wait_boot, wait_boot_timeout, max_async, ): @@ -799,11 +802,25 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): conn_settings = {} resolved_username = username or 'root' - logger.debug(f'Setting up {kind} target...') + default_connection_kind = { + 'android': 'adb', + 'linux': 'ssh', + 'host': 'host', + } + connection_kind = connection_kind or default_connection_kind[kind] + + logger.debug(f'Setting up {kind} target (connection kind {connection_kind})...') + + target_cls = { + 'android': devlib.AndroidTarget, + 'linux': devlib.LinuxTarget, + 'host': devlib.LocalLinuxTarget, + } + devlib_target_cls = target_cls[kind] # If the target is Android, we need just (eventually) the device - if kind == 'android': - devlib_target_cls = devlib.AndroidTarget + if connection_kind == 'android': + conn_cls = devlib.AdbConnection # Workaround for ARM-software/devlib#225 workdir = workdir or '/data/local/tmp/devlib-target' @@ -816,8 +833,8 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): # as early as possible adb_as_root=(username == 'root'), ) - elif kind == 'linux': - devlib_target_cls = devlib.LinuxTarget + elif connection_kind == 'ssh': + conn_cls = devlib.SshConnection conn_settings.update( username=resolved_username, port=port or cls.SSH_PORT_DEFAULT, @@ -831,8 +848,8 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): conn_settings['keyfile'] = keyfile else: conn_settings['password'] = password - elif kind == 'host': - devlib_target_cls = devlib.LocalLinuxTarget + elif connection_kind == 'host': + conn_cls = devlib.LocalConnection # If we are given a password, assume we can use it as a sudo # password. conn_settings.update( @@ -840,7 +857,7 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): password=password, ) else: - raise ValueError(f'Unsupported platform type {kind}') + raise ValueError(f'Unsupported connection kind: {connection_kind}') conn_settings = { k: v @@ -853,7 +870,7 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): for key, val in conn_settings.items() if key != 'password' ) - logger.debug(f'{kind} {name} target connection settings:\n {settings}') + logger.debug(f'{kind} {name} target ({connection_kind}) connection settings:\n {settings}') ######################################################################## # Devlib Platform configuration @@ -871,6 +888,7 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): devlib_kwargs = dict( platform=devlib_platform, load_default_modules=False, + conn_cls=conn_cls, connection_settings=conn_settings, working_directory=workdir, connect=False,