Merge "Allow to modify computable inputs in Composer files"
This commit is contained in:
commit
37e2f39388
@ -236,7 +236,7 @@ def update_resources(template_resources):
|
||||
|
||||
def update_inputs(child, inputs):
|
||||
child = load_resource(child)
|
||||
connections, assignments = parse_inputs(inputs)
|
||||
connections, assignments, computable = parse_inputs(inputs)
|
||||
parents = defaultdict(lambda: defaultdict(dict))
|
||||
for c in connections:
|
||||
mapping = {c['parent_input']: c['child_input']}
|
||||
@ -253,6 +253,9 @@ def update_inputs(child, inputs):
|
||||
|
||||
child.update(assignments)
|
||||
|
||||
for comp in computable:
|
||||
child.input_computable_change(**comp)
|
||||
|
||||
|
||||
def extend_events(template_events):
|
||||
events = []
|
||||
@ -295,22 +298,28 @@ def parse_events(template_events):
|
||||
def parse_inputs(inputs):
|
||||
connections = []
|
||||
assignments = {}
|
||||
computable = []
|
||||
for r_input, arg in inputs.items():
|
||||
if isinstance(arg, list):
|
||||
c, a = parse_list_input(r_input, arg)
|
||||
connections.extend(c)
|
||||
assignments.update(a)
|
||||
elif isinstance(arg, dict):
|
||||
c, a = parse_dict_input(r_input, arg)
|
||||
connections.extend(c)
|
||||
assignments.update(a)
|
||||
if 'computable' in arg:
|
||||
comp, conn = parse_computable_input(r_input, arg)
|
||||
computable.append(comp)
|
||||
connections.extend(conn)
|
||||
else:
|
||||
c, a = parse_dict_input(r_input, arg)
|
||||
connections.extend(c)
|
||||
assignments.update(a)
|
||||
else:
|
||||
if is_connection(arg):
|
||||
c = parse_connection(r_input, arg)
|
||||
connections.append(c)
|
||||
else:
|
||||
assignments[r_input] = arg
|
||||
return connections, assignments
|
||||
return connections, assignments, computable
|
||||
|
||||
|
||||
def parse_list_input(r_input, args):
|
||||
@ -347,6 +356,25 @@ def parse_dict_input(r_input, args):
|
||||
return connections, assignments
|
||||
|
||||
|
||||
def parse_computable_input(r_input, arg):
|
||||
computable = {'name': r_input}
|
||||
connections = []
|
||||
data = arg['computable']
|
||||
func = data.get('func', None)
|
||||
d_type = data.get('type', None)
|
||||
lang = data.get('lang', None)
|
||||
if func:
|
||||
computable['func'] = func
|
||||
if d_type:
|
||||
computable['type'] = d_type
|
||||
if lang:
|
||||
computable['lang'] = lang
|
||||
for c in data.get('connections', []):
|
||||
c = parse_connection(r_input, c)
|
||||
connections.append(c)
|
||||
return computable, connections
|
||||
|
||||
|
||||
def add_assignment(assignments, r_input, arg):
|
||||
try:
|
||||
assignments[r_input].append(arg)
|
||||
|
@ -191,6 +191,22 @@ def test_parse_dict_input():
|
||||
assert correct_connections == connections
|
||||
|
||||
|
||||
def test_parse_computable_input():
|
||||
comp, conn = cr.parse_computable_input('cmd', {'computable': {
|
||||
'func': 'echo 1',
|
||||
'type': 'full',
|
||||
'lang': 'jinja',
|
||||
'connections': ['N::ip']}})
|
||||
assert comp == {'lang': 'jinja',
|
||||
'type': 'full',
|
||||
'name': 'cmd',
|
||||
'func': 'echo 1'}
|
||||
assert conn == [{'child_input': 'cmd',
|
||||
'parent_input': 'ip',
|
||||
'parent': 'N',
|
||||
'events': None}]
|
||||
|
||||
|
||||
def test_parse_connection_disable_events():
|
||||
correct_connection = {'child_input': 'ip',
|
||||
'parent': 'node1',
|
||||
@ -205,7 +221,7 @@ def test_parse_list_of_connected_dicts():
|
||||
inputs = {'list': [
|
||||
{'key': 'emitter1::key'},
|
||||
{'key': 'emitter2::key'}]}
|
||||
connections, assignments = cr.parse_inputs(inputs)
|
||||
connections, assignments, _ = cr.parse_inputs(inputs)
|
||||
assert assignments == {}
|
||||
assert connections == [
|
||||
{'child_input': 'list:key', 'parent_input': 'key',
|
||||
|
Loading…
x
Reference in New Issue
Block a user