From 09450b6bd5fce1105d1dacffd8dc85429db72321 Mon Sep 17 00:00:00 2001 From: f3flight Date: Tue, 2 Aug 2016 11:10:41 +0000 Subject: [PATCH] Implement multiple rq file support, add global logs_days parameter --- rq/neutron.yaml | 7 +++++++ rq/nova.yaml | 13 +++++++++++++ timmy/cli.py | 3 ++- timmy/conf.py | 4 ++-- timmy/env.py | 2 +- timmy/nodes.py | 34 ++++++++++++++++++++++++---------- 6 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 rq/neutron.yaml create mode 100644 rq/nova.yaml diff --git a/rq/neutron.yaml b/rq/neutron.yaml new file mode 100644 index 0000000..5a0ffe4 --- /dev/null +++ b/rq/neutron.yaml @@ -0,0 +1,7 @@ +files: + __default: + - '/etc/neutron' +logs: + __default: + path: '/var/log' + include: 'neutron' diff --git a/rq/nova.yaml b/rq/nova.yaml new file mode 100644 index 0000000..ae858fb --- /dev/null +++ b/rq/nova.yaml @@ -0,0 +1,13 @@ +files: + __default: + - '/etc/nova' + - '/etc/libvirt' +scripts: + controller: + - nova-list + - nova-service-list + - nova-usage-list +logs: + __default: + path: '/var/log' + include: '(nova|libvirt|qemu)' diff --git a/timmy/cli.py b/timmy/cli.py index 577c810..cbe41ad 100755 --- a/timmy/cli.py +++ b/timmy/cli.py @@ -98,7 +98,7 @@ def parse_args(): ' these parameters. Values except path can be' ' skipped by passing empty strings. Example: -L' ' "/var/mylogs/" "" "exclude-string"')) - parser.add_argument('--rqfile', metavar='PATH', + parser.add_argument('--rqfile', metavar='PATH', action='append', help=('Path to an rqfile in yaml format, overrides' ' default.')) parser.add_argument('-l', '--logs', @@ -206,6 +206,7 @@ def main(argv=None): conf['rqfile'] = args.rqfile if args.days: conf['logs'][0]['start'] = args.days + conf['logs_days'] = args.days if args.logs_no_default: conf['logs'] = [] args.logs = True diff --git a/timmy/conf.py b/timmy/conf.py index d4fe8af..a5f8d63 100644 --- a/timmy/conf.py +++ b/timmy/conf.py @@ -61,8 +61,8 @@ def load_conf(filename): conf['files'] = [] conf['filelists'] = [] conf['logs'] = [{'path': '/var/log', - 'exclude': '\.[^12]\.gz$|\.\d{2,}\.gz$', - 'start': '30'}] + 'exclude': '\.[^12]\.gz$|\.\d{2,}\.gz$'}] + conf['logs_days'] = 30 '''Shell mode - only run what was specified via command line. Skip actionable conf fields (see timmy/nodes.py -> Node.conf_actionable); Skip rqfile import; diff --git a/timmy/env.py b/timmy/env.py index 6b2317c..2c9bb8b 100644 --- a/timmy/env.py +++ b/timmy/env.py @@ -16,7 +16,7 @@ # under the License. project_name = 'timmy' -version = '1.11.1' +version = '1.12.0' if __name__ == '__main__': exit(0) diff --git a/timmy/nodes.py b/timmy/nodes.py index 629b3d5..ca51579 100644 --- a/timmy/nodes.py +++ b/timmy/nodes.py @@ -325,9 +325,12 @@ class Node(object): re.search(item['exclude'], string))) for item in self.logs: - start_str = '' - if 'start' in item: - start = item['start'] + start_str = None + if 'start' in item or hasattr(self,'logs_days'): + if hasattr(self, 'logs_days') and 'start' not in item: + start = self.logs_days + else: + start = item['start'] if any([type(start) is str and re.match(r'-?\d+', start), type(start) is int]): days = abs(int(str(start))) @@ -535,7 +538,11 @@ class NodeManager(object): dst[k] = {} if d in el[k]: if k == attr: - dst[k] = el[k][d] + if k in Node.conf_appendable: + dst[k] = w_list(dst[k]) + dst[k] += w_list(el[k][d]) + else: + dst[k] = w_list(el[k][d]) elif k.startswith(p) or k.startswith(once_p): dst[k][d] = {attr: el[k][d]} else: @@ -554,13 +561,20 @@ class NodeManager(object): else: dst[k][attr] = el[k] + def merge_rq(rqfile, dst): + src = tools.load_yaml_file(rqfile) + p = Node.conf_match_prefix + once_p = Node.conf_once_prefix + p + d = Node.conf_default_key + for attr in src: + r_sub(attr, src, attr, d, p, once_p, dst) + dst = self.conf - src = tools.load_yaml_file(self.conf['rqfile']) - p = Node.conf_match_prefix - once_p = Node.conf_once_prefix + p - d = Node.conf_default_key - for attr in src: - r_sub(attr, src, attr, d, p, once_p, dst) + if type(self.conf['rqfile']) is list: + for rqfile in self.conf['rqfile']: + merge_rq(rqfile, dst) + else: + merge_rq(self.conf['rqfile'], dst) def fuel_init(self): if not self.conf['fuel_ip']: