diff --git a/timmy/cli.py b/timmy/cli.py index 1737085..daa4c53 100755 --- a/timmy/cli.py +++ b/timmy/cli.py @@ -92,8 +92,13 @@ def main(argv=None): level=loglevel, format='%(asctime)s %(levelname)s %(message)s') conf = load_conf(args.conf) - if args.command or args.file or conf['shell_mode']: + if args.command or args.file: conf['shell_mode'] = True + if conf['shell_mode']: + # set clean to True if not defined in config + if conf['clean'] is None: + conf['clean'] = True + filter = conf['hard_filter'] # config cleanup for shell mode for k in Node.conf_actionable: conf[k] = [] if k in Node.conf_appendable else None @@ -104,8 +109,6 @@ def main(argv=None): conf[Node.ckey] = [{'stdout': args.command}] if args.file: conf[Node.fkey] = args.file - if conf['shell_mode']: - filter = conf['hard_filter'] else: filter = conf['soft_filter'] if args.role: diff --git a/timmy/conf.py b/timmy/conf.py index 7ae3b93..01ba8c3 100644 --- a/timmy/conf.py +++ b/timmy/conf.py @@ -41,6 +41,9 @@ def load_conf(filename): place specified by conf['outdir'], archive will also be created and put in a place specified by conf['archives'].''' conf['shell_mode'] = False + '''Clean - erase previous results in outdir and archives dir, if any. + Enabled by default for shell mode. Set to True or False to override.''' + conf['clean'] = None if filename: conf_extra = load_yaml_file(filename) conf.update(**conf_extra) diff --git a/timmy/nodes.py b/timmy/nodes.py index 179ceaa..e153751 100644 --- a/timmy/nodes.py +++ b/timmy/nodes.py @@ -22,6 +22,7 @@ main module import flock import json import os +import shutil import logging import sys import re @@ -222,8 +223,9 @@ class Node(object): logging.info('get_files: node: %s, IP: %s' % (self.id, self.ip)) sn = 'node-%s' % self.id cl = 'cluster-%s' % self.cluster - ddir = os.path.join(odir, Node.fkey, cl, sn) - tools.mdir(ddir) + if self.files or self.filelists: + ddir = os.path.join(odir, Node.fkey, cl, sn) + tools.mdir(ddir) if self.shell_mode: for file in self.files: outs, errs, code = tools.get_file_scp(ip=self.ip, @@ -244,11 +246,12 @@ class Node(object): logging.error('could not read file: %s' % fname) data += '\n'.join(self.files) logging.debug('node: %s, data:\n%s' % (self.id, data)) - outs, errs, code = tools.get_files_rsync(ip=self.ip, - data=data, - ssh_opts=self.ssh_opts, - dpath=ddir, - timeout=self.timeout) + if data: + o, e, c = tools.get_files_rsync(ip=self.ip, + data=data, + ssh_opts=self.ssh_opts, + dpath=ddir, + timeout=self.timeout) check_code(code) def logs_populate(self, timeout=5): @@ -305,12 +308,15 @@ class NodeManager(object): def __init__(self, conf, extended=False, filename=None): self.conf = conf - self.rqdir = conf['rqdir'].rstrip('/') + if conf['clean']: + shutil.rmtree(conf['outdir'], ignore_errors=True) + shutil.rmtree(conf['archives'], ignore_errors=True) if not conf['shell_mode']: + self.rqdir = conf['rqdir'] + if (not os.path.exists(self.rqdir)): + logging.error("directory %s doesn't exist" % (self.rqdir)) + sys.exit(1) self.import_rq() - if (not os.path.exists(self.rqdir)): - logging.error("directory %s doesn't exist" % (self.rqdir)) - sys.exit(1) if (conf['fuelip'] is None) or (conf['fuelip'] == ""): logging.error('looks like fuelip is not set(%s)' % conf['fuelip']) sys.exit(7)