fix: #55, flake8, utf8 decode parameter added
This commit is contained in:
parent
4d0f285c4e
commit
66e405dfaf
@ -16,7 +16,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
project_name = 'timmy'
|
project_name = 'timmy'
|
||||||
version = '1.15.2'
|
version = '1.15.3'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -260,7 +260,7 @@ class Node(object):
|
|||||||
return mapcmds, mapscr
|
return mapcmds, mapscr
|
||||||
|
|
||||||
def exec_simple_cmd(self, cmd, timeout=15, infile=None, outfile=None,
|
def exec_simple_cmd(self, cmd, timeout=15, infile=None, outfile=None,
|
||||||
fake=False, ok_codes=None, input=None):
|
fake=False, ok_codes=None, input=None, decode=True):
|
||||||
self.logger.info('node:%s(%s), exec: %s' % (self.id, self.ip, cmd))
|
self.logger.info('node:%s(%s), exec: %s' % (self.id, self.ip, cmd))
|
||||||
if not fake:
|
if not fake:
|
||||||
outs, errs, code = tools.ssh_node(ip=self.ip,
|
outs, errs, code = tools.ssh_node(ip=self.ip,
|
||||||
@ -270,6 +270,7 @@ class Node(object):
|
|||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
outputfile=outfile,
|
outputfile=outfile,
|
||||||
ok_codes=ok_codes,
|
ok_codes=ok_codes,
|
||||||
|
decode=decode,
|
||||||
input=input,
|
input=input,
|
||||||
prefix=self.prefix)
|
prefix=self.prefix)
|
||||||
self.check_code(code, 'exec_simple_cmd', cmd, errs, ok_codes)
|
self.check_code(code, 'exec_simple_cmd', cmd, errs, ok_codes)
|
||||||
@ -957,7 +958,8 @@ class NodeManager(object):
|
|||||||
'timeout': timeout,
|
'timeout': timeout,
|
||||||
'outfile': node.archivelogsfile,
|
'outfile': node.archivelogsfile,
|
||||||
'input': input,
|
'input': input,
|
||||||
'ok_codes': [0, 1]}
|
'ok_codes': [0, 1],
|
||||||
|
'decode': False}
|
||||||
run_items.append(tools.RunItem(target=node.exec_simple_cmd,
|
run_items.append(tools.RunItem(target=node.exec_simple_cmd,
|
||||||
args=args))
|
args=args))
|
||||||
tools.run_batch(run_items, maxthreads)
|
tools.run_batch(run_items, maxthreads)
|
||||||
|
@ -196,7 +196,7 @@ def mdir(directory):
|
|||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
|
|
||||||
def launch_cmd(cmd, timeout, input=None, ok_codes=None):
|
def launch_cmd(cmd, timeout, input=None, ok_codes=None, decode=True):
|
||||||
def _timeout_terminate(pid):
|
def _timeout_terminate(pid):
|
||||||
try:
|
try:
|
||||||
os.kill(pid, 15)
|
os.kill(pid, 15)
|
||||||
@ -217,8 +217,10 @@ def launch_cmd(cmd, timeout, input=None, ok_codes=None):
|
|||||||
timeout_killer = threading.Timer(timeout, _timeout_terminate, [p.pid])
|
timeout_killer = threading.Timer(timeout, _timeout_terminate, [p.pid])
|
||||||
timeout_killer.start()
|
timeout_killer.start()
|
||||||
outs, errs = p.communicate(input=input)
|
outs, errs = p.communicate(input=input)
|
||||||
|
errs = errs.rstrip('\n')
|
||||||
|
if decode:
|
||||||
outs = outs.decode('utf-8')
|
outs = outs.decode('utf-8')
|
||||||
errs = errs.decode('utf-8').rstrip('\n')
|
errs = errs.decode('utf-8')
|
||||||
finally:
|
finally:
|
||||||
if timeout_killer:
|
if timeout_killer:
|
||||||
timeout_killer.cancel()
|
timeout_killer.cancel()
|
||||||
@ -233,7 +235,7 @@ def launch_cmd(cmd, timeout, input=None, ok_codes=None):
|
|||||||
|
|
||||||
def ssh_node(ip, command='', ssh_opts=None, env_vars=None, timeout=15,
|
def ssh_node(ip, command='', ssh_opts=None, env_vars=None, timeout=15,
|
||||||
filename=None, inputfile=None, outputfile=None,
|
filename=None, inputfile=None, outputfile=None,
|
||||||
ok_codes=None, input=None, prefix=None):
|
ok_codes=None, input=None, prefix=None, decode=True):
|
||||||
if not ssh_opts:
|
if not ssh_opts:
|
||||||
ssh_opts = ''
|
ssh_opts = ''
|
||||||
if not env_vars:
|
if not env_vars:
|
||||||
@ -264,7 +266,8 @@ def ssh_node(ip, command='', ssh_opts=None, env_vars=None, timeout=15,
|
|||||||
cmd = ("input=\"$(cat | xxd -p)\"; trap 'kill $pid' 15; " +
|
cmd = ("input=\"$(cat | xxd -p)\"; trap 'kill $pid' 15; " +
|
||||||
"trap 'kill $pid' 2; echo -n \"$input\" | xxd -r -p | " + cmd +
|
"trap 'kill $pid' 2; echo -n \"$input\" | xxd -r -p | " + cmd +
|
||||||
' &:; pid=$!; wait $!')
|
' &:; pid=$!; wait $!')
|
||||||
return launch_cmd(cmd, timeout, input=input, ok_codes=ok_codes)
|
return launch_cmd(cmd, timeout, input=input,
|
||||||
|
ok_codes=ok_codes, decode=decode)
|
||||||
|
|
||||||
|
|
||||||
def get_files_rsync(ip, data, ssh_opts, dpath, timeout=15):
|
def get_files_rsync(ip, data, ssh_opts, dpath, timeout=15):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user