From 39c5a34a3fa0da0c3ce0f2aad552e59c35838b36 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Fri, 9 Oct 2015 12:39:27 +0300 Subject: [PATCH] Refactor shell handler to use transports --- solar/solar/core/handlers/shell.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/solar/solar/core/handlers/shell.py b/solar/solar/core/handlers/shell.py index 84cbe737..2bbe1e6f 100644 --- a/solar/solar/core/handlers/shell.py +++ b/solar/solar/core/handlers/shell.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from fabric import api as fabric_api +from solar.core.log import log +from solar import errors from solar.core.handlers.base import TempFileHandler @@ -21,4 +22,19 @@ from solar.core.handlers.base import TempFileHandler class Shell(TempFileHandler): def action(self, resource, action_name): action_file = self._compile_action_file(resource, action_name) - fabric_api.local('bash {}'.format(action_file)) + log.debug('action_file: %s', action_file) + + self.transport_sync.copy(resource, action_file, '/tmp/action.sh') + self.transport_sync.sync_all() + cmd = self.transport_run.run( + resource, + 'bash', '/tmp/action.sh', + use_sudo=True, + warn_only=True + ) + + if cmd.return_code: + raise errors.SolarError( + 'Bash execution for {} failed with {}'.format( + resource.name, cmd.return_code)) + return cmd