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])
|
command.extend(["-r", source, self.target_host + ":" + destination])
|
||||||
self.run_command(command)
|
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.
|
"""Run the given command with the given environment on the remote side.
|
||||||
Return the output as a string.
|
Return the output as a string.
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ class Remote(object):
|
||||||
cmd = self._exec.split()
|
cmd = self._exec.split()
|
||||||
cmd.append(self.target_host)
|
cmd.append(self.target_host)
|
||||||
cmd.extend(command)
|
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.
|
"""Run the given command with the given environment.
|
||||||
Return the output as a string.
|
Return the output as a string.
|
||||||
|
|
||||||
|
@ -113,13 +113,16 @@ class Remote(object):
|
||||||
|
|
||||||
self.log.debug("Remote run: %s", command)
|
self.log.debug("Remote run: %s", command)
|
||||||
try:
|
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:
|
except subprocess.CalledProcessError:
|
||||||
raise cdist.Error("Command failed: " + " ".join(command))
|
raise cdist.Error("Command failed: " + " ".join(command))
|
||||||
except OSError as error:
|
except OSError as error:
|
||||||
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
|
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.
|
"""Run the given script with the given environment on the remote side.
|
||||||
Return the output as a string.
|
Return the output as a string.
|
||||||
|
|
||||||
|
@ -140,7 +143,10 @@ class Remote(object):
|
||||||
self.log.debug("Remote run script env: %s", env)
|
self.log.debug("Remote run script env: %s", env)
|
||||||
|
|
||||||
try:
|
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:
|
except subprocess.CalledProcessError as error:
|
||||||
script_content = self.run(["cat", script])
|
script_content = self.run(["cat", script])
|
||||||
self.log.error("Code that raised the error:\n%s", script_content)
|
self.log.error("Code that raised the error:\n%s", script_content)
|
||||||
|
|
Loading…
Reference in a new issue