From 82371a55972c56acd88c487fa472b872229d94b8 Mon Sep 17 00:00:00 2001 From: f3flight Date: Thu, 9 Jun 2016 21:12:47 +0000 Subject: [PATCH] Implement negative filtering, fix Fuel filtered by normal filters --- config.yaml | 2 ++ timmy/nodes.py | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/config.yaml b/config.yaml index afb8c37..610d0df 100644 --- a/config.yaml +++ b/config.yaml @@ -16,6 +16,8 @@ rqfile: './rq.yaml' soft_filter: status: ['ready'] online: True + # no_id: [0] # skip Fuel + # no_roles: ['fuel'] # another way to skip Fuel timeout: 15 compress_timeout: 3600 logs: diff --git a/timmy/nodes.py b/timmy/nodes.py index e51231c..6d85899 100644 --- a/timmy/nodes.py +++ b/timmy/nodes.py @@ -548,16 +548,27 @@ class NodeManager(object): def filter(self, node, node_filter): f = node_filter - # soft-skip Fuel node for shell mode, otherwise always include - if node.id == 0: - return False if self.conf['shell_mode'] else True + # soft-skip Fuel node for shell mode + if node.id == 0 and self.conf['shell_mode']: + return False else: - fnames = [k for k in f if hasattr(node, k) and f[k]] + elems = [] + for k in f: + if k.startswith('no_') and hasattr(node, k[3:]): + elems.append({'node_k': k[3:], 'k': k, 'negative': True}) + elif hasattr(node, k) and f[k]: + elems.append({'node_k': k, 'k': k, 'negative': False}) checks = [] - for fn in fnames: - node_v = w_list(getattr(node, fn)) - filter_v = w_list(f[fn]) - checks.append(not set(node_v).isdisjoint(filter_v)) + for el in elems: + node_v = w_list(getattr(node, el['node_k'])) + filter_v = w_list(f[el['k']]) + if el['negative']: + checks.append(set(node_v).isdisjoint(filter_v)) + elif node.id != 0: + '''Do not apply normal (positive) filters to Fuel node + , Fuel node will only be filtered by negative filters + such as no_id = [0] or no_roles = ['fuel']''' + checks.append(not set(node_v).isdisjoint(filter_v)) return all(checks) @run_with_lock