Skip to content

Commit

Permalink
saltnado: account for when lowstate is a list
Browse files Browse the repository at this point in the history
lowstate isn't necessarily a single dict, it can be a list of dicts.
_get_lowstate wasn't accounting for that properly.
  • Loading branch information
mattp- committed Oct 19, 2018
1 parent 6e611ce commit c5fd88f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
25 changes: 13 additions & 12 deletions salt/netapi/rest_tornado/saltnado.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,23 +563,24 @@ def _get_lowstate(self):
data = self.deserialize(self.request.body)
self.request_payload = copy(data)

if data and 'arg' in data:
if not isinstance(data['arg'], list):
data['arg'] = [data['arg']]

# Run name=value args through parse_input
_arg, _kwarg = salt.utils.args.parse_input(data.pop('arg', []), condition=False)
data['arg'] = _arg
if 'kwarg' in data and isinstance(data['kwarg'], dict):
data['kwarg'].update(_kwarg)
else:
data['kwarg'] = _kwarg

if not isinstance(data, list):
lowstate = [data]
else:
lowstate = data

for chunk in lowstate:
if chunk and 'arg' in chunk:
if not isinstance(chunk['arg'], list):
chunk['arg'] = [chunk['arg']]

# Run name=value args through parse_input
_arg, _kwarg = salt.utils.args.parse_input(chunk.pop('arg', []), condition=False)
chunk['arg'] = _arg
if 'kwarg' in chunk and isinstance(chunk['kwarg'], dict):
chunk['kwarg'].update(_kwarg)
else:
chunk['kwarg'] = _kwarg

return lowstate

def set_default_headers(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/netapi/test_rest_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def test_deserialize(self):
"client": "local",
"tgt": "*",
"fun": "test.fib",
"arg": [10]
"arg": [10],
"kwarg": {},
},
{
"client": "runner",
Expand Down

0 comments on commit c5fd88f

Please sign in to comment.