From 4cfc5b802f4dcc4dec563b6dbc662feefb8ae951 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Tue, 23 Jan 2024 21:25:35 -0500 Subject: [PATCH] qa: use stdin-killer to timeout run_shell_payload - simplify argument processing / forwarding - use stdin-killer to kill all sub-processes of the shell - do not needlessly use run_shell to execute the command as it adds a timeout to the stdout/stderr processing - provide a stdin (PIPE) by default otherwise teuthology's code closes stdin and triggers stdin-killer to timeout the shell. - use a 15 minute timeout by default Signed-off-by: Patrick Donnelly --- qa/tasks/cephfs/mount.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 007be38e223f7..32f81551f99c8 100644 --- a/qa/tasks/cephfs/mount.py +++ b/qa/tasks/cephfs/mount.py @@ -785,12 +785,25 @@ class CephFSMount(object): return self.client_remote.run(args=args, **kwargs) - def run_shell_payload(self, payload, **kwargs): - kwargs['args'] = ["bash", "-c", Raw(f"'{payload}'")] + def run_shell_payload(self, payload, wait=True, timeout=900, **kwargs): + kwargs.setdefault('cwd', self.mountpoint) + kwargs.setdefault('omit_sudo', False) + kwargs.setdefault('stdout', StringIO()) + kwargs.setdefault('stderr', StringIO()) + kwargs.setdefault('stdin', run.PIPE) + args = [] if kwargs.pop('sudo', False): - kwargs['args'].insert(0, 'sudo') + args.append('sudo') kwargs['omit_sudo'] = False - return self.run_shell(**kwargs) + args.append("stdin-killer") + if timeout is not None: + args.append(f"--timeout={timeout}") + args += ("--", "bash", "-c", Raw(f"'{payload}'")) + p = self.client_remote.run(args=args, wait=False, **kwargs) + if wait: + p.stdin.close() + p.wait() + return p def run_as_user(self, **kwargs): """ -- 2.39.5