Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CBQE-6652: Back-port support for exit codes
Back-port of code from the master branch that will allow the use of
return codes for mad-hatter testing

Change-Id: Ibca60149528c37043a3a599f9bca29278bfb45a4
Reviewed-on: http://review.couchbase.org/c/testrunner/+/148387
Tested-by: Joe Mitchell Jones <joe.mitchelljones@couchbase.com>
Reviewed-by: Asad Zaidi <asad.zaidi@couchbase.com>
  • Loading branch information
Joe Mitchell Jones committed Mar 15, 2021
1 parent eb321c4 commit 8c9c987
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/remote/remote_util.py
Expand Up @@ -3153,7 +3153,7 @@ def execute_commands_inside(self, main_command,query, queries,bucket1,password,b
output = re.sub('\s+', '', output)
return (output)

def execute_command(self, command, info=None, debug=True, use_channel=False, timeout=600):
def execute_command(self, command, info=None, debug=True, use_channel=False, timeout=600, get_exit_code=False):
if getattr(self, "info", None) is None and info is not None :
self.info = info
else:
Expand All @@ -3165,14 +3165,15 @@ def execute_command(self, command, info=None, debug=True, use_channel=False, tim
if self.use_sudo:
command = "sudo " + command

return self.execute_command_raw(command, debug=debug, use_channel=use_channel, timeout=timeout)
return self.execute_command_raw(command, debug=debug, use_channel=use_channel, timeout=timeout, get_exit_code=get_exit_code)

def execute_command_raw(self, command, debug=True, use_channel=False, timeout=600):
def execute_command_raw(self, command, debug=True, use_channel=False, timeout=600, get_exit_code=False):
if debug:
log.info("running command.raw on {0}: {1}".format(self.ip, command))
output = []
error = []
temp = ''
p, stdout, exit_code = None, None, None
if self.remote and self.use_sudo or use_channel:
channel = self._ssh_client.get_transport().open_session()
channel.get_pty()
Expand All @@ -3195,6 +3196,12 @@ def execute_command_raw(self, command, debug=True, use_channel=False, timeout=60
p = Popen(command , shell=True, stdout=PIPE, stderr=PIPE)
output, error = p.communicate()

if get_exit_code:
if stdout:
exit_code = stdout.channel.recv_exit_status()
if p:
exit_code = p.returncode

if self.remote:
for line in stdout.read().splitlines():
output.append(line)
Expand All @@ -3207,7 +3214,7 @@ def execute_command_raw(self, command, debug=True, use_channel=False, timeout=60
stderro.close()
if debug:
log.info('command executed successfully')
return output, error
return (output, error, exit_code) if get_exit_code else (output, error)

def execute_non_sudo_command(self, command, info=None, debug=True, use_channel=False):
info = info or self.extract_remote_info()
Expand Down

0 comments on commit 8c9c987

Please sign in to comment.