def check_stderr(self, command, verbose=False): ret = self.check_call(command, verbose) if ret['stderr']: raise DevopsCalledProcessError(command, ret['exit_code'], stdout=ret['stdout_str'], stderr=ret['stderr_str']) return ret
def _execute_check_retcode(self, command): result = self.ssh_manager.execute(ip=self.admin_ip, cmd=command) if result['exit_code'] != 0: raise DevopsCalledProcessError(command=command, returncode=result['exit_code'], output=result['stderr']) return ''.join(result['stdout'])
def check_call(self, command, verbose=False, excpected=0): ret = self.execute(command, verbose) if ret['exit_code'] != excpected: raise DevopsCalledProcessError( command, ret['exit_code'], expected=excpected, stdout=ret['stdout_str'], stderr=ret['stderr_str']) return ret
def execute_together(cls, remotes, command): futures = {} errors = {} for remote in remotes: chan, _, _, _ = remote.execute_async(command) futures[remote] = chan for remote, chan in futures.items(): ret = chan.recv_exit_status() chan.close() if ret != 0: errors[remote.host] = ret if errors: raise DevopsCalledProcessError(command, errors)
def execute_together(cls, remotes, command): futures = {} errors = {} for remote in remotes: cmd = "%s\n" % command if remote.sudo_mode: cmd = 'sudo -S bash -c "%s"' % cmd.replace('"', '\\"') chan = remote._ssh.get_transport().open_session() chan.exec_command(cmd) futures[remote] = chan for remote, chan in futures.items(): ret = chan.recv_exit_status() if ret != 0: errors[remote.host] = ret if errors: raise DevopsCalledProcessError(command, errors)
def check_call(self, command, verbose=False): ret = self.execute(command, verbose) if ret['exit_code'] != 0: raise DevopsCalledProcessError(command, ret['exit_code'], ret['stdout'] + ret['stderr']) return ret
def test2(self): raise DevopsCalledProcessError('asdf', 1)
def test(self): raise DevopsCalledProcessError('asdf', 1, ['a', 'b'] + ['b', 'c'])