Implement negative filtering, fix Fuel filtered by normal filters

This commit is contained in:
f3flight 2016-06-09 21:12:47 +00:00
parent d3f29c09ff
commit 82371a5597
2 changed files with 21 additions and 8 deletions

View File

@ -16,6 +16,8 @@ rqfile: './rq.yaml'
soft_filter: soft_filter:
status: ['ready'] status: ['ready']
online: True online: True
# no_id: [0] # skip Fuel
# no_roles: ['fuel'] # another way to skip Fuel
timeout: 15 timeout: 15
compress_timeout: 3600 compress_timeout: 3600
logs: logs:

View File

@ -548,16 +548,27 @@ class NodeManager(object):
def filter(self, node, node_filter): def filter(self, node, node_filter):
f = node_filter f = node_filter
# soft-skip Fuel node for shell mode, otherwise always include # soft-skip Fuel node for shell mode
if node.id == 0: if node.id == 0 and self.conf['shell_mode']:
return False if self.conf['shell_mode'] else True return False
else: 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 = [] checks = []
for fn in fnames: for el in elems:
node_v = w_list(getattr(node, fn)) node_v = w_list(getattr(node, el['node_k']))
filter_v = w_list(f[fn]) filter_v = w_list(f[el['k']])
checks.append(not set(node_v).isdisjoint(filter_v)) 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) return all(checks)
@run_with_lock @run_with_lock