implement: dont return command output by default
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
86cb65cd9c
commit
829b0b2d0b
1 changed files with 12 additions and 6 deletions
|
@ -85,7 +85,7 @@ class Remote(object):
|
|||
command.extend(["-r", source, self.target_host + ":" + destination])
|
||||
self.run_command(command)
|
||||
|
||||
def run(self, command, env=None):
|
||||
def run(self, command, env=None, return_output=False):
|
||||
"""Run the given command with the given environment on the remote side.
|
||||
Return the output as a string.
|
||||
|
||||
|
@ -94,9 +94,9 @@ class Remote(object):
|
|||
cmd = self._exec.split()
|
||||
cmd.append(self.target_host)
|
||||
cmd.extend(command)
|
||||
return self.run_command(cmd, env=env)
|
||||
return self.run_command(cmd, env=env, return_output=return_output)
|
||||
|
||||
def run_command(self, command, env=None):
|
||||
def run_command(self, command, env=None, return_output=False):
|
||||
"""Run the given command with the given environment.
|
||||
Return the output as a string.
|
||||
|
||||
|
@ -113,13 +113,16 @@ class Remote(object):
|
|||
|
||||
self.log.debug("Remote run: %s", command)
|
||||
try:
|
||||
return subprocess.check_output(cmd).decode()
|
||||
if return_output:
|
||||
return subprocess.check_output(command, env=env).decode()
|
||||
else:
|
||||
subprocess.check_call(command, env=env)
|
||||
except subprocess.CalledProcessError:
|
||||
raise cdist.Error("Command failed: " + " ".join(command))
|
||||
except OSError as error:
|
||||
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
|
||||
|
||||
def run_script(self, script, env=None):
|
||||
def run_script(self, script, env=None, return_output=False):
|
||||
"""Run the given script with the given environment on the remote side.
|
||||
Return the output as a string.
|
||||
|
||||
|
@ -140,7 +143,10 @@ class Remote(object):
|
|||
self.log.debug("Remote run script env: %s", env)
|
||||
|
||||
try:
|
||||
return subprocess.check_output(command).decode()
|
||||
if return_output:
|
||||
return subprocess.check_output(command, env=env).decode()
|
||||
else:
|
||||
subprocess.check_call(command, env=env)
|
||||
except subprocess.CalledProcessError as error:
|
||||
script_content = self.run(["cat", script])
|
||||
self.log.error("Code that raised the error:\n%s", script_content)
|
||||
|
|
Loading…
Reference in a new issue