From a280edbe82dbca8d3a9639fd8ceee38e09a3f33a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 16 Apr 2021 12:09:14 +0800 Subject: [PATCH] qa/workunits/mon/test_mon_config_key: use subprocess.run() instead of proc.communicate() the loop of proc.communicate() on python3.6, where we always are able to get something out of stdout and/or stderr PIPEs. and the `stdout` and `stderr` keep growing until out of memory. and teuthology considers the command crashed after a while. Fixes: https://tracker.ceph.com/issues/50393 Signed-off-by: Kefu Chai (cherry picked from commit f2e0770c276e6fffa01a0bcb2d969f02ee1aafef) --- qa/workunits/mon/test_mon_config_key.py | 38 ++++++------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/qa/workunits/mon/test_mon_config_key.py b/qa/workunits/mon/test_mon_config_key.py index bcc1a79dd3519..0d8ec1c27d9a2 100755 --- a/qa/workunits/mon/test_mon_config_key.py +++ b/qa/workunits/mon/test_mon_config_key.py @@ -78,39 +78,19 @@ def run_cmd(cmd, expects=0): cmdlog = LOG.getChild('run_cmd') cmdlog.debug('{fc}'.format(fc=' '.join(full_cmd))) - proc = subprocess.Popen(full_cmd, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - - stdout = [] - stderr = [] - while True: - try: - out, err = proc.communicate() - if out is not None: - stdout += out.decode().split('\n') - cmdlog.debug('stdout: {s}'.format(s=out)) - if err is not None: - stdout += err.decode().split('\n') - cmdlog.debug('stderr: {s}'.format(s=err)) - except ValueError: - ret = proc.wait() - break - - if ret != expects: - cmdlog.error('cmd > {cmd}'.format(cmd=full_cmd)) - cmdlog.error("expected return '{expected}' got '{got}'".format( - expected=expects, got=ret)) + proc = subprocess.run(full_cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + if proc.returncode != expects: + cmdlog.error(f'cmd > {proc.args}') + cmdlog.error(f'expected return "{expects}" got "{proc.returncode}"') cmdlog.error('stdout') - for i in stdout: - cmdlog.error('{x}'.format(x=i)) + cmdlog.error(proc.stdout) cmdlog.error('stderr') - for i in stderr: - cmdlog.error('{x}'.format(x=i)) + cmdlog.error(proc.stderr) -# end run_cmd - def gen_data(size, rnd): chars = string.ascii_letters + string.digits return ''.join(rnd.choice(chars) for _ in range(size)) -- 2.39.5