diff --git a/lisa/target.py b/lisa/target.py index 6a6250f4eca67c3254c49c93a7cbbe559f6ccf81..94c1b9983ae8f6fd01a7c73f0e43c228ab662c57 100644 --- a/lisa/target.py +++ b/lisa/target.py @@ -179,6 +179,7 @@ class TargetConf(SimpleMultiSrcConf, HideExekallID): _KernelBuildEnvConf, ), )), + KeyDesc('hooks', 'Command hooks to be executed at various stages. "post-connect" stage will run commands right after the connection to the target. Note that each command runs in its own shell', [typing.Dict[str, typing.List[str]], None]), LevelKeyDesc('wait-boot', 'Wait for the target to finish booting', ( KeyDesc('enable', 'Enable the boot check', [bool]), KeyDesc('timeout', 'Timeout of the boot check', [int]), @@ -294,6 +295,7 @@ class Target( 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, + hooks=None, ): # Determine file transfer method. Currently avaliable options # are 'sftp' and 'scp', defaults to sftp. @@ -326,6 +328,7 @@ class Target( kernel_src=kernel_src, kmod_build_env=kmod_build_env, kmod_make_vars=kmod_make_vars, kmod_overlay_backend=kmod_overlay_backend, + hooks=hooks, ) @classmethod @@ -337,7 +340,7 @@ class Target( @update_params_from(__init__) def _init_post_devlib(self, *, name, res_dir, target, tools, plat_info, lazy_platinfo, devlib_excluded_modules, kernel_src, - kmod_build_env, kmod_make_vars, kmod_overlay_backend, + kmod_build_env, kmod_make_vars, kmod_overlay_backend, hooks=None, ): self._uuid = uuid.uuid4().hex self._user_res_dir = res_dir @@ -403,6 +406,13 @@ class Target( target=self, ) + hooks = hooks or {} + for cmd in hooks.get('post-connect', []): + logger.debug(f'Running post-connect hook command: {cmd}') + out = self.execute(cmd) + out = out.strip() + logger.info(f'Executed post-connect hook command "{cmd}": {out}') + def _init_plat_info(self, plat_info=None, name=None, **kwargs): if plat_info is None: