This commit is contained in:
f3flight 2016-08-05 14:11:41 +00:00
parent fe262558e8
commit c71a5cc62a
3 changed files with 44 additions and 31 deletions

View File

@ -47,6 +47,9 @@ def parse_args():
help=('Path to a json file retrieved via'
' "fuel node --json". Useful to speed up'
' initialization, skips "fuel node" call.'))
parser.add_argument('--fuel-ip', help='fuel ip address')
parser.add_argument('--fuel-user', help='fuel username')
parser.add_argument('--fuel-pass', help='fuel password')
parser.add_argument('-o', '--dest-file',
help=('Output filename for the archive in tar.gz'
' format for command outputs and collected'
@ -119,9 +122,13 @@ def parse_args():
' admin interface speed. If speed detection'
' fails, a default value will be used. See'
' "logs_speed_default" in conf.py.'))
parser.add_argument('--fuel-ip', help='fuel ip address')
parser.add_argument('--fuel-user', help='fuel username')
parser.add_argument('--fuel-pass', help='fuel password')
parser.add_argument('--logs-coeff', type=float, metavar='RATIO',
help=('Estimated logs compression ratio - this value'
' is used during free space check. Set to a'
' lower value (default - 1.05) to collect logs'
' of a total size larger than locally available'
'. Values lower than 0.3 are not recommended'
' and may result in filling up local disk.'))
parser.add_argument('--fuel-proxy',
help='use os system proxy variables for fuelclient',
action='store_true')
@ -189,7 +196,7 @@ def main(argv=None):
args = parser.parse_args(argv[1:])
if args.version:
print(version)
exit(0)
sys.exit(0)
loglevels = [logging.WARNING, logging.INFO, logging.DEBUG]
if args.quiet and not args.log_file:
args.verbose = 0
@ -236,6 +243,8 @@ def main(argv=None):
conf['logs_speed_limit'] = True
if args.logs_speed:
conf['logs_speed'] = abs(args.logs_speed)
if args.logs_coeff:
conf['logs_size_coefficient'] = args.logs_coeff
if conf['shell_mode']:
filter = conf['hard_filter']
# config cleanup for shell mode
@ -281,6 +290,19 @@ def main(argv=None):
NodeManager,
kwargs={'conf': conf, 'extended': args.extended,
'nodes_json': args.nodes_json})
if args.only_logs or args.logs:
size = pretty_run(args.quiet, 'Calculating logs size',
nm.calculate_log_size, args=(args.maxthreads,))
if size == 0:
logger.warning('Size zero - no logs to collect.')
else:
print('Total logs size to collect: %dMB.' % (size / 1000))
enough = pretty_run(args.quiet, 'Checking free space',
nm.is_enough_space)
if not enough:
logger.error('Not enough space for logs in "%s", exiting.' %
nm.conf['archive_dir'])
return 2
if not args.only_logs:
if nm.has(Node.pkey):
pretty_run(args.quiet, 'Uploading files', nm.put_files)
@ -293,24 +315,12 @@ def main(argv=None):
if not args.no_archive and nm.has(*Node.conf_archive_general):
pretty_run(args.quiet, 'Creating outputs and files archive',
nm.create_archive_general, args=(60,))
if args.only_logs or args.logs:
size = pretty_run(args.quiet, 'Calculating logs size',
nm.calculate_log_size, args=(args.maxthreads,))
if size == 0:
logger.warning('Size zero - no logs to collect.')
return
enough = pretty_run(args.quiet, 'Checking free space',
nm.is_enough_space)
if enough:
print('Total logs size to collect: %dMB.' % (nm.alogsize / 1000))
msg = 'Collecting and packing logs'
pretty_run(args.quiet, msg, nm.get_logs,
args=(conf['compress_timeout'],),
kwargs={'maxthreads': args.logs_maxthreads,
'fake': args.fake_logs})
else:
logger.warning(('Not enough space for logs in "%s", skipping'
'log collection.') % nm.conf['archive_dir'])
if (args.only_logs or args.logs) and enough:
msg = 'Collecting and packing logs'
pretty_run(args.quiet, msg, nm.get_logs,
args=(conf['compress_timeout'],),
kwargs={'maxthreads': args.logs_maxthreads,
'fake': args.fake_logs})
logger.info("Nodes:\n%s" % nm)
if not args.quiet:
print('Run complete. Node information:')
@ -327,7 +337,6 @@ def main(argv=None):
if all([not args.no_archive, nm.has(*Node.conf_archive_general),
not args.quiet]):
print('Archives available in "%s".' % nm.conf['archive_dir'])
return 0
if __name__ == '__main__':
exit(main(sys.argv))
sys.exit(main(sys.argv))

View File

@ -64,6 +64,7 @@ def load_conf(filename):
conf['logs_speed_limit'] = False # enable speed limiting of log transfers
conf['logs_speed_default'] = 100 # Mbit/s, used when autodetect fails
conf['logs_speed'] = 0 # To manually specify max bandwidth in Mbit/s
conf['logs_size_coefficient'] = 1.05 # estimated logs compression ratio
'''Shell mode - only run what was specified via command line.
Skip actionable conf fields (see timmy/nodes.py -> Node.conf_actionable);
Skip rqfile import;

View File

@ -859,7 +859,7 @@ class NodeManager(object):
self.alogsize = total_size / 1024
return self.alogsize
def is_enough_space(self, coefficient=1.2):
def is_enough_space(self):
tools.mdir(self.conf['outdir'])
outs, errs, code = tools.free_space(self.conf['outdir'], timeout=1)
if code != 0:
@ -871,13 +871,16 @@ class NodeManager(object):
self.logger.error("can't get free space\nouts: %s" %
outs)
return False
coeff = self.conf['logs_size_coefficient']
self.logger.info('logsize: %s Kb * %s, free space: %s Kb' %
(self.alogsize, coefficient, fs))
if (self.alogsize*coefficient > fs):
self.logger.error('Not enough space on device, logsize: %s Kb * %s'
', free space: %s Kb' % (self.alogsize,
coefficient,
fs))
(self.alogsize, coeff, fs))
if (self.alogsize*coeff > fs):
self.logger.error('Not enough space in "%s", logsize: %s Kb * %s, '
'available: %s Kb. Decrease logs_size_coefficien'
't config parameter (--logs-coeff CLI parameter)'
' or free up space.' % (self.conf['outdir'],
self.alogsize, coeff,
fs))
return False
else:
return True