From aa0ecc93ff0faad6663add73d5e013775ce4a68f Mon Sep 17 00:00:00 2001 From: Sergey Orlov Date: Nov 06 2019 08:42:12 +0000 Subject: ipatests: modify run_command to allow specify successful return codes Reviewed-By: Michal Polovka Reviewed-By: Alexander Bokovoy Reviewed-By: Rob Crittenden --- diff --git a/ipatests/pytest_ipa/integration/host.py b/ipatests/pytest_ipa/integration/host.py index 7205f0a..d02f534 100644 --- a/ipatests/pytest_ipa/integration/host.py +++ b/ipatests/pytest_ipa/integration/host.py @@ -63,13 +63,21 @@ class Host(pytest_multihost.host.Host): def run_command(self, argv, set_env=True, stdin_text=None, log_stdout=True, raiseonerr=True, - cwd=None): - # Wrap run_command to log stderr on raiseonerr=True + cwd=None, ok_returncode=0): + """Wrapper around run_command to log stderr on raiseonerr=True + + :param ok_returncode: return code considered to be correct, + you can pass an integer or sequence of integers + """ result = super(Host, self).run_command( argv, set_env=set_env, stdin_text=stdin_text, log_stdout=log_stdout, raiseonerr=False, cwd=cwd ) - if result.returncode and raiseonerr: + try: + result_ok = result.returncode in ok_returncode + except TypeError: + result_ok = result.returncode == ok_returncode + if not result_ok and raiseonerr: result.log.error('stderr: %s', result.stderr_text) raise subprocess.CalledProcessError( result.returncode, argv,