|
|
@ -94,7 +94,7 @@ 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=None) |
|
|
|
return self.run_command(cmd, env=env) |
|
|
|
|
|
|
|
|
|
|
|
def run_command(self, command, env=None): |
|
|
|
def run_command(self, command, env=None): |
|
|
|
"""Run the given command with the given environment. |
|
|
|
"""Run the given command with the given environment. |
|
|
@ -102,9 +102,18 @@ class Remote(object): |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command |
|
|
|
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# can't pass environment to remote side, so prepend command with |
|
|
|
|
|
|
|
# variable declarations |
|
|
|
|
|
|
|
if env: |
|
|
|
|
|
|
|
cmd = ["%s=%s" % item for item in env.items()] |
|
|
|
|
|
|
|
cmd.extend(command) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
cmd = command |
|
|
|
|
|
|
|
|
|
|
|
self.log.debug("Remote run: %s", command) |
|
|
|
self.log.debug("Remote run: %s", command) |
|
|
|
try: |
|
|
|
try: |
|
|
|
return subprocess.check_output(command, env=env).decode() |
|
|
|
return subprocess.check_output(cmd).decode() |
|
|
|
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: |
|
|
@ -117,6 +126,12 @@ class Remote(object): |
|
|
|
""" |
|
|
|
""" |
|
|
|
command = self._exec.split() |
|
|
|
command = self._exec.split() |
|
|
|
command.append(self.target_host) |
|
|
|
command.append(self.target_host) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# can't pass environment to remote side, so prepend command with |
|
|
|
|
|
|
|
# variable declarations |
|
|
|
|
|
|
|
if env: |
|
|
|
|
|
|
|
command.extend(["%s=%s" % item for item in env.items()]) |
|
|
|
|
|
|
|
|
|
|
|
command.extend(["/bin/sh", "-e"]) |
|
|
|
command.extend(["/bin/sh", "-e"]) |
|
|
|
command.append(script) |
|
|
|
command.append(script) |
|
|
|
|
|
|
|
|
|
|
@ -125,7 +140,7 @@ 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, env=env).decode() |
|
|
|
return subprocess.check_output(command).decode() |
|
|
|
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) |
|
|
|