Fix parsing list of dicts

Instead of getting {input_name: [{key:value}] it was returning:
{input_name: [{input_name: {key: value}}]

Closes-bug: 1549318

Change-Id: I1af92e88c96e367f7f49f01fcad8b8a5ba1295e2
This commit is contained in:
Łukasz Oleś 2016-02-24 14:27:55 +01:00
parent 3de536b399
commit 6ebaf3b010
2 changed files with 20 additions and 11 deletions

View File

@ -335,19 +335,21 @@ def parse_inputs(inputs):
def parse_list_input(r_input, args):
connections = []
assignments = {}
assignments = []
for arg in args:
if isinstance(arg, dict):
n_connections, n_assign = parse_dict_input(
r_input, arg)
connections.extend(n_connections)
if n_assign:
add_assignment(assignments, r_input, n_assign)
assignments.append(n_assign[r_input])
elif is_connection(arg):
c = parse_connection(r_input, arg)
connections.append(c)
else:
add_assignment(assignments, r_input, arg)
assignments.append(arg)
if assignments:
assignments = {r_input: assignments}
return connections, assignments
@ -386,13 +388,6 @@ def parse_computable_input(r_input, arg):
return computable, connections
def add_assignment(assignments, r_input, arg):
try:
assignments[r_input].append(arg)
except KeyError:
assignments[r_input] = [arg]
def is_connection(arg):
if isinstance(arg, basestring) and '::' in arg:
return True
@ -422,6 +417,9 @@ def dump_back_to_file(data):
if val.endswith('\n...\n'):
# yaml dumps in that way, when we operate on single value
val = val[:-5]
if val.endswith('\n'):
# yaml dumps in that way, when we operate on single value
val = val[:-1]
return val
VR_ENV.globals['dump_back'] = dump_back_to_file

View File

@ -189,10 +189,21 @@ def test_parse_dict_input():
'events': None,
'parent': 'node1',
'parent_input': 'ip'}]
connections, assigments = cr.parse_dict_input('env', {'host': 'node1::ip'})
connections, _ = cr.parse_dict_input('env', {'host': 'node1::ip'})
assert correct_connections == connections
def test_parse_list_of_dicts1():
_, assigments, _ = cr.parse_inputs({'map': [{'a': 1, 'b': 3},
{'a': 2, 'b': 4}]})
assert assigments == {'map': [{'a': 1, 'b': 3}, {'a': 2, 'b': 4}]}
def test_parse_simple_list():
_, assigments, _ = cr.parse_inputs({'map': [1, 2, 3]})
assert assigments == {'map': [1, 2, 3]}
def test_parse_computable_input():
comp, conn = cr.parse_computable_input('cmd', {'computable': {
'func': 'echo 1',