From: Patrick Donnelly Date: Wed, 24 Jan 2024 02:25:35 +0000 (-0500) Subject: qa: use stdin-killer to timeout run_shell_payload X-Git-Tag: testing/wip-root-testing-20240411.174241~89^2~22 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=68ad717492bf907547fca44c9e73a79ffe8dda95;p=ceph-ci.git 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 (cherry picked from commit 4cfc5b802f4dcc4dec563b6dbc662feefb8ae951) --- diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 007be38e223..32f81551f99 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): """