@@ -134,7 +134,8 @@ def receive_event_node(self, sub_id):
134
134
135
135
def _find_container (self , field , node ):
136
136
"""
137
- Return the first found dict containing a field of a given name
137
+ Return the first found dict containing a field of a given name,
138
+ recursing through all of the node's ancestors if not found.
138
139
"""
139
140
for item in node :
140
141
if isinstance (node [item ], dict ):
@@ -143,24 +144,24 @@ def _find_container(self, field, node):
143
144
return base_object
144
145
elif field == item :
145
146
return node
147
+ if 'parent' in node :
148
+ parent = self ._api .node .get (node ['parent' ])
149
+ return self ._find_container (field , parent )
146
150
return None
147
151
148
- # pylint: disable=too-many-arguments
149
- def _is_allowed (self , rules , key , node , parent ):
152
+ def _is_allowed (self , rules , key , node ):
150
153
"""
151
154
Check whether the value of a specific node attribute matches
152
155
a filtering rule. As the specified attribute might not be present
153
156
in the node being created, we fall back to checking the value in its
154
- parent node in such cases .
157
+ ancestor nodes .
155
158
156
159
Returns True if the rule allows the current value, False otherwise.
157
160
"""
158
161
159
- # Find the node (or parent node) attribute corresponding to the
162
+ # Find the node (or ancestor node) attribute corresponding to the
160
163
# rule we're applying
161
164
base = self ._find_container (key , node )
162
- if not base and parent :
163
- base = self ._find_container (key , parent )
164
165
if not base :
165
166
return True
166
167
@@ -294,7 +295,7 @@ def _is_tree_branch_allowed(self, node, rules):
294
295
295
296
return True
296
297
297
- def should_create_node (self , rules , node , parent = None ):
298
+ def should_create_node (self , rules , node ):
298
299
"""
299
300
Check whether a node should be created based on configured rules.
300
301
Those can be specified in the job, platform or runtime configuration
@@ -356,11 +357,9 @@ def should_create_node(self, rules, node, parent=None):
356
357
# Process the tree and branch rules first as they need specific processing
357
358
# for handling tree/branch combinations
358
359
359
- # Find the node (or parent node) attribute containing the "tree" (and therefore
360
+ # Find the node (or ancestor node) attribute containing the "tree" (and therefore
360
361
# "branch") value
361
362
ref_base = self ._find_container ("tree" , node )
362
- if not ref_base and parent :
363
- ref_base = self ._find_container ("tree" , parent )
364
363
if ref_base and not self ._is_tree_branch_allowed (ref_base , rules ):
365
364
return False
366
365
@@ -390,7 +389,7 @@ def should_create_node(self, rules, node, parent=None):
390
389
f"({ rule_major } .{ rule_minor } )" )
391
390
return False
392
391
393
- elif not self ._is_allowed (rules , key , node , parent ):
392
+ elif not self ._is_allowed (rules , key , node ):
394
393
return False
395
394
396
395
return True
@@ -440,6 +439,7 @@ def _is_job_filtered(self, node):
440
439
441
440
return False
442
441
442
+ # pylint: disable=too-many-arguments
443
443
def create_job_node (self , job_config , input_node ,
444
444
runtime = None , platform = None , retry_counter = 0 ):
445
445
"""Create a new job node based on input and configuration"""
@@ -471,7 +471,7 @@ def create_job_node(self, job_config, input_node,
471
471
f"for node { input_node ['id' ]} " )
472
472
return None
473
473
474
- if not self .should_create_node (job_config .rules , job_node , input_node ):
474
+ if not self .should_create_node (job_config .rules , job_node ):
475
475
print (f"Not creating node due to job rules for { job_config .name } "
476
476
f"evaluating node { input_node ['id' ]} " )
477
477
return None
@@ -489,7 +489,7 @@ def create_job_node(self, job_config, input_node,
489
489
# in case of kubernetes: cluster name
490
490
if runtime :
491
491
job_node ['data' ]['runtime' ] = runtime .config .name
492
- if not self .should_create_node (runtime .config .rules , job_node , input_node ):
492
+ if not self .should_create_node (runtime .config .rules , job_node ):
493
493
print (f"Not creating node { input_node ['id' ]} due to runtime rules "
494
494
f"for { runtime .config .name } " )
495
495
return None
@@ -502,7 +502,7 @@ def create_job_node(self, job_config, input_node,
502
502
f"for node { input_node ['id' ]} " )
503
503
return None
504
504
job_node ['data' ]['platform' ] = platform .name
505
- if not self .should_create_node (platform .rules , job_node , input_node ):
505
+ if not self .should_create_node (platform .rules , job_node ):
506
506
print (f"Not creating node { input_node ['id' ]} due to platform rules "
507
507
f"for { platform .name } " )
508
508
return None
0 commit comments