From 2513cee2e0c50a92a301d6e1b84a6cd8dc475be7 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Mon, 21 Aug 2023 16:21:59 +0100 Subject: [PATCH] lisa.target: Add hooks FEATURE Add lisa.target.Target(hooks={'post-connect': ['echo hello', 'echo world']}, ...) parameter. This allows running custom commands on the target after connection, which can be useful to do custom setup on some devices such as disabling SE Linux. The commands can be added in target_conf.yml as follows: target-conf: hooks: post-connect: - echo hello - echo world --- lisa/target.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisa/target.py b/lisa/target.py index 6a6250f4e..94c1b9983 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: -- GitLab