diff --git a/src/watchmaker/managers/base.py b/src/watchmaker/managers/base.py index e4e293d7e..ad62b33ed 100644 --- a/src/watchmaker/managers/base.py +++ b/src/watchmaker/managers/base.py @@ -222,7 +222,7 @@ def _pipe_logger(pipe, logger, prefix_msg='', return_output=False): return ret or None - def call_process(self, cmd, stdout=False): + def call_process(self, cmd, stdout=False, raise_error=True): """ Execute a shell command. @@ -234,6 +234,11 @@ def call_process(self, cmd, stdout=False): Switch to control whether to return stdout. (*Default*: ``False``) + raise_error: (:obj:`bool`) + Switch to control whether to raise if the command return code + is non-zero. + (*Default*: ``True``) + Returns: :obj:`None` or :obj:`bytes`: ``None`` unless ``stdout`` is ``True``. In that case, the @@ -275,7 +280,7 @@ def call_process(self, cmd, stdout=False): returncode = process.wait() - if returncode != 0: + if raise_error and returncode != 0: msg = 'Command failed! Exit code={0}, cmd={1}'.format( process.returncode, cmd) self.log.critical(msg) diff --git a/src/watchmaker/workers/salt.py b/src/watchmaker/workers/salt.py index 3a502c045..b2b54d892 100644 --- a/src/watchmaker/workers/salt.py +++ b/src/watchmaker/workers/salt.py @@ -6,11 +6,13 @@ import codecs import json import os +import re import shutil import yaml from watchmaker import static +from watchmaker.exceptions import WatchmakerException from watchmaker.managers.base import LinuxManager, ManagerBase, WindowsManager @@ -138,7 +140,7 @@ def _prepare_for_install(self): self.salt_state_args = [ '--log-file', self.salt_debug_logfile, '--log-file-level', 'debug', - '--state-output', 'mixed_id' + '--state_verbose', 'false' ] for salt_dir in [ @@ -240,7 +242,7 @@ def _set_grain(self, grain, value): ] self.run_salt(cmd) - def run_salt(self, command, stdout=False): + def run_salt(self, command, **kwargs): """ Execute salt command. @@ -250,10 +252,6 @@ def run_salt(self, command, stdout=False): Watchmaker will always begin the command with the options ``--local``, ``--retcode-passthrough``, and ``--no-color``, so do not specify those options in the command. - - stdout: (:obj:`bool`) - Switch to control whether to return stdout. - (*Default*: ``False``) """ cmd = [ self.salt_call, @@ -265,9 +263,8 @@ def run_salt(self, command, stdout=False): cmd.extend(command) else: cmd.append(command) - ret = self.call_process(cmd, stdout=stdout) - if stdout: - return ret + + return self.call_process(cmd, **kwargs) def service_status(self, service): """ @@ -435,7 +432,14 @@ def process_states(self, states): ) cmd.extend(['state.sls', states]) - ret = self.run_salt(cmd, stdout=True) + ret = self.run_salt(cmd, stdout=True, raise_error=False) + + if ret['retcode'] != 0: + raise WatchmakerException( + 'Salt states failed to apply!{0}{1}' + .format(os.linesep, ret['stdout']) + ) + self.log.info('Salt states all applied successfully!')