some code reviews and checks
This commit is contained in:
parent
c7d07c66e8
commit
0d0acc7c81
18
timmy/cli.py
18
timmy/cli.py
@ -77,7 +77,7 @@ def main(argv=None):
|
|||||||
n = nodes.Nodes(conf=config,
|
n = nodes.Nodes(conf=config,
|
||||||
extended=args.extended,
|
extended=args.extended,
|
||||||
cluster=args.cluster,
|
cluster=args.cluster,
|
||||||
destdir=config.archives)
|
)
|
||||||
# nodes.print_nodes()
|
# nodes.print_nodes()
|
||||||
if not args.only_logs:
|
if not args.only_logs:
|
||||||
n.get_node_file_list()
|
n.get_node_file_list()
|
||||||
@ -89,21 +89,15 @@ def main(argv=None):
|
|||||||
if args.only_logs or args.getlogs:
|
if args.only_logs or args.getlogs:
|
||||||
lf = '/tmp/timmy-logs.lock'
|
lf = '/tmp/timmy-logs.lock'
|
||||||
lock = flock.FLock(lf)
|
lock = flock.FLock(lf)
|
||||||
if not lock.lock():
|
if lock.lock():
|
||||||
logging.warning('Unable to obtain lock %s, skipping "logs"-part' % lf)
|
|
||||||
return 1
|
|
||||||
n.get_node_file_list()
|
n.get_node_file_list()
|
||||||
# n.set_template_for_find()
|
|
||||||
n.calculate_log_size()
|
n.calculate_log_size()
|
||||||
if n.is_enough_space():
|
if n.is_enough_space(config.archives):
|
||||||
# n.get_log_files(config.outdir)
|
|
||||||
n.create_log_archives(config.archives,
|
n.create_log_archives(config.archives,
|
||||||
config.compress_timeout)
|
config.compress_timeout)
|
||||||
# n.add_logs_archive(config.outdir, nodes.lkey,
|
lock.unlock()
|
||||||
# config.logs_archive, 120)
|
else:
|
||||||
# n.compress_archive(config.logs_archive, config.compress_timeout)
|
logging.warning('Unable to obtain lock %s, skipping "logs"-part' % lf)
|
||||||
# n.compress_logs(config.compress_timeout)
|
|
||||||
|
|
||||||
n.print_nodes()
|
n.print_nodes()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ class Node(object):
|
|||||||
class Nodes(object):
|
class Nodes(object):
|
||||||
"""Class nodes """
|
"""Class nodes """
|
||||||
|
|
||||||
def __init__(self, cluster, extended, conf, destdir, filename=None):
|
def __init__(self, cluster, extended, conf, filename=None):
|
||||||
import_subprocess()
|
import_subprocess()
|
||||||
self.dirname = conf.rqdir.rstrip('/')
|
self.dirname = conf.rqdir.rstrip('/')
|
||||||
if (not os.path.exists(self.dirname)):
|
if (not os.path.exists(self.dirname)):
|
||||||
@ -340,7 +340,6 @@ class Nodes(object):
|
|||||||
self.sshvars = conf.ssh['vars']
|
self.sshvars = conf.ssh['vars']
|
||||||
self.timeout = conf.timeout
|
self.timeout = conf.timeout
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
self.destdir = destdir
|
|
||||||
self.get_version()
|
self.get_version()
|
||||||
self.cluster = cluster
|
self.cluster = cluster
|
||||||
self.extended = extended
|
self.extended = extended
|
||||||
@ -543,12 +542,17 @@ class Nodes(object):
|
|||||||
logging.info('Full log size on nodes(with fuel): %s bytes' % lsize)
|
logging.info('Full log size on nodes(with fuel): %s bytes' % lsize)
|
||||||
self.alogsize = lsize / 1024
|
self.alogsize = lsize / 1024
|
||||||
|
|
||||||
def is_enough_space(self, coefficient=1.2):
|
def is_enough_space(self, directory, coefficient=1.2):
|
||||||
outs, errs, code = free_space(self.destdir, timeout=1)
|
mdir(directory)
|
||||||
|
outs, errs, code = free_space(directory, timeout=1)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
logging.error("Can't get free space: %s" % errs)
|
logging.error("Can't get free space: %s" % errs)
|
||||||
return False
|
return False
|
||||||
|
try:
|
||||||
fs = int(outs.rstrip('\n'))
|
fs = int(outs.rstrip('\n'))
|
||||||
|
except:
|
||||||
|
logging.error("is_enough_space: can't get free space\nouts: %s" % outs)
|
||||||
|
return False
|
||||||
logging.info('logsize: %s Kb, free space: %s Kb' % (self.alogsize, fs))
|
logging.info('logsize: %s Kb, free space: %s Kb' % (self.alogsize, fs))
|
||||||
if (self.alogsize*coefficient > fs):
|
if (self.alogsize*coefficient > fs):
|
||||||
logging.error('Not enough space on device')
|
logging.error('Not enough space on device')
|
||||||
@ -603,7 +607,10 @@ class Nodes(object):
|
|||||||
for t in threads:
|
for t in threads:
|
||||||
t.join()
|
t.join()
|
||||||
for tfile in txtfl:
|
for tfile in txtfl:
|
||||||
|
try:
|
||||||
os.remove(tfile)
|
os.remove(tfile)
|
||||||
|
except:
|
||||||
|
logging.error("create_log_archives: can't delete file %s" % tfile)
|
||||||
|
|
||||||
def add_logs_archive(self, directory, key, outfile, timeout):
|
def add_logs_archive(self, directory, key, outfile, timeout):
|
||||||
cmd = ("tar --append --file=%s --directory %s %s" %
|
cmd = ("tar --append --file=%s --directory %s %s" %
|
||||||
|
Loading…
x
Reference in New Issue
Block a user