From a4882e7e30a40c453735f4e727f267a9e759dcd8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 15 Feb 2012 16:17:49 +0100 Subject: [PATCH] remove useless script printing and reuse run() method Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 3 --- lib/cdist/exec/local.py | 21 +-------------------- lib/cdist/exec/remote.py | 28 ++-------------------------- 3 files changed, 3 insertions(+), 49 deletions(-) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index 828ff917..bead6d72 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -3,9 +3,6 @@ - cleanup object_id handling - have a look at singletons -- remove useless - ERROR: monitoring02: Code that raised the error: - - ensure that all types, which support --state support present and absent (consistent look and feel) diff --git a/lib/cdist/exec/local.py b/lib/cdist/exec/local.py index cdf06205..e24ae484 100644 --- a/lib/cdist/exec/local.py +++ b/lib/cdist/exec/local.py @@ -119,26 +119,7 @@ class Local(object): command = ["/bin/sh", "-e"] command.append(script) - self.log.debug("Local run script: %s", command) - - if env is None: - env = os.environ.copy() - # Export __target_host for use in __remote_{copy,exec} scripts - env['__target_host'] = self.target_host - - self.log.debug("Local run script env: %s", env) - - try: - 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], return_output=True) - self.log.error("Code that raised the error:\n%s", script_content) - raise LocalScriptError(script, command, script_content) - except EnvironmentError as error: - raise cdist.Error(" ".join(command) + ": " + error.args[1]) + self.run(command, env, return_output) def link_emulator(self, exec_path): """Link emulator to types""" diff --git a/lib/cdist/exec/remote.py b/lib/cdist/exec/remote.py index 69dc5dda..0fb93e10 100644 --- a/lib/cdist/exec/remote.py +++ b/lib/cdist/exec/remote.py @@ -139,32 +139,8 @@ class Remote(object): Return the output as a string. """ - command = self._exec.split() - command.append(self.target_host) - # export target_host for use in __remote_{exec,copy} scripts - os_environ = os.environ.copy() - os_environ['__target_host'] = self.target_host - - self.log.debug("Remote run script: %s", command) - - # can't pass environment to remote side, so prepend command with - # variable declarations - if env: - self.log.debug("Remote run script env: %s", env) - command.extend(["%s=%s" % item for item in env.items()]) - - command.extend(["/bin/sh", "-e"]) + command = ["/bin/sh", "-e"] command.append(script) - try: - if return_output: - return subprocess.check_output(command, env=os_environ).decode() - else: - subprocess.check_call(command, env=os_environ) - except subprocess.CalledProcessError as error: - script_content = self.run(["cat", script], return_output=True) - self.log.error("Code that raised the error:\n%s", script_content) - raise RemoteScriptError(script, command, script_content) - except EnvironmentError as error: - raise cdist.Error(" ".join(command) + ": " + error.args[1]) + self.run(command, env, return_output)