Commit f05cde25 authored by Antoine Millet's avatar Antoine Millet

Rewrote external command execution

parent 62e4e1ce
......@@ -41,7 +41,7 @@ from cloudcontrol.common.client.plugins import Base as BasePlugin, rpc_handler
from import JobsManager, JobsStore
from cloudcontrol.common.helpers.logger import patch_logging; patch_logging()
from cloudcontrol.node.utils import EvPopen
from cloudcontrol.node.utils import execute
from cloudcontrol.node.exc import RemoteExecutionError
from import tags
from import NodeJobsManagerInterface, ScriptJob
......@@ -279,43 +279,19 @@ class Handler(BasePlugin):
def execute_command(self, command, stdin=None):
"""Execute an arbitrary shell command on the host.
command = ['/bin/sh', '-c', command]
rcode, output = execute(self.main, command, stdin)
:param string command: shell command to run
:param string stdin: string to use as stdin on command
logger.debug('Executing command %s', command)
remote_command = EvPopen(self.main, command, close_fds=True,
shell=True, stdout=PIPE, stdin=PIPE,
except Exception:
logger.exception('Error while starting subprocess for executing '
' command %s', command)
stdout, _ = remote_command.communicate(stdin)
except Exception:
logger.exception('Error while communicating with subprocess for'
' command %s', command)
if remote_command.returncode != 0:
if rcode != 0:
# 127 means command not found, 126 means not executable
if remote_command.returncode == 127:
raise RemoteExecutionError('Command not found: %s' % stdout)
elif remote_command.returncode == 126:
if rcode == 127:
raise RemoteExecutionError('Command not found: %s' % output)
elif rcode == 126:
raise RemoteExecutionError('Command is not executable')
raise RemoteExecutionError('Child exited with non zero status %s' % rcode)
raise RemoteExecutionError('Child exited with non zero status %s' %
return stdout
return output
def node_shutdown(self, reboot=True, gracefull=True):
This diff is collapsed.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment