fix: #55, flake8, utf8 decode parameter added

This commit is contained in:
adobdin 2016-08-10 10:18:29 +00:00
parent 4d0f285c4e
commit 66e405dfaf
4 changed files with 18 additions and 12 deletions

View File

@ -38,9 +38,9 @@ setup(name=pname,
author_email='dobdin@gmail.com',
license='Apache2',
url='https://github.com/adobdin/timmy',
description = ('Mirantis OpenStack Ansible-like tool for parallel node '
'operations: two-way data transfer, log collection, '
'remote command execution'),
description=('Mirantis OpenStack Ansible-like tool for parallel node '
'operations: two-way data transfer, log collection, '
'remote command execution'),
long_description=open('README.md').read(),
packages=[pname],
install_requires=['pyyaml'],

View File

@ -16,7 +16,8 @@
# under the License.
project_name = 'timmy'
version = '1.15.2'
version = '1.15.3'
if __name__ == '__main__':
import sys
sys.exit(0)

View File

@ -260,7 +260,7 @@ class Node(object):
return mapcmds, mapscr
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))
if not fake:
outs, errs, code = tools.ssh_node(ip=self.ip,
@ -270,6 +270,7 @@ class Node(object):
timeout=timeout,
outputfile=outfile,
ok_codes=ok_codes,
decode=decode,
input=input,
prefix=self.prefix)
self.check_code(code, 'exec_simple_cmd', cmd, errs, ok_codes)
@ -885,7 +886,7 @@ class NodeManager(object):
't config parameter (--logs-coeff CLI parameter)'
' or free up space.' % (self.conf['outdir'],
self.alogsize, coeff,
fs))
fs))
return False
else:
return True
@ -957,7 +958,8 @@ class NodeManager(object):
'timeout': timeout,
'outfile': node.archivelogsfile,
'input': input,
'ok_codes': [0, 1]}
'ok_codes': [0, 1],
'decode': False}
run_items.append(tools.RunItem(target=node.exec_simple_cmd,
args=args))
tools.run_batch(run_items, maxthreads)

View File

@ -196,7 +196,7 @@ def mdir(directory):
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):
try:
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.start()
outs, errs = p.communicate(input=input)
outs = outs.decode('utf-8')
errs = errs.decode('utf-8').rstrip('\n')
errs = errs.rstrip('\n')
if decode:
outs = outs.decode('utf-8')
errs = errs.decode('utf-8')
finally:
if timeout_killer:
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,
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:
ssh_opts = ''
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; " +
"trap 'kill $pid' 2; echo -n \"$input\" | xxd -r -p | " + cmd +
' &:; 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):