Repository navigation
Closed
Labels
Corerelates to code central or existential to SaltP1Priority 1bugbroken, incorrect, or confusing behaviorseverity-medium3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone
Description
Based on this stackoverflow question.
Problem
Command:
salt --out json '*' test.ping
Output (for 2 minions):
{
"monkey": true
}
{
"elephant": true
}
This output is not valid JSON which cannot contain more than one top-level objects (begins with { and ends with }).
The problem is that instead of using JSON output directly, one has to create a special parser to recognize the beginning and the end of multiple JSON objects, split the objects, feed them one by one to the parser. Or, in short, the output is unusable.
Test
load_json.py:
import sys
import json
data = json.load(sys.stdin)
print str(data)
For example, capturing the output above and feeding it into standard JSON parser in Python does not work:
salt --out json '*' test.ping | python load_json.py
Traceback (most recent call last):
File "load_json.py", line 4, in <module>
data = json.load(sys.stdin)
File "/usr/lib64/python2.7/json/__init__.py", line 290, in load
**kw)
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 369, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 4 column 1 - line 7 column 1 (char 23 - 48)
Versions
salt --versions
Salt: 2015.5.2
Python: 2.7.10 (default, May 27 2015, 18:11:38)
Jinja2: 2.7.3
M2Crypto: 0.21.1
msgpack-python: 0.4.6
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.11
ioflo: Not Installed
PyZMQ: 14.4.1
RAET: Not Installed
ZMQ: 4.0.5
Mako: 1.0.1
Metadata
Metadata
Assignees
Labels
Corerelates to code central or existential to SaltP1Priority 1bugbroken, incorrect, or confusing behaviorseverity-medium3rd level, incorrect or bad functionality, confusing and lacks a work around
Activity
[-]Incorrect JSON output with multiple results[/-][+]Multiple results should generate valid JSON output[/+]uvsmtid commentedon Jul 5, 2015
#25154 is a similar issue to make sure all features together provide valid output.
#14725 is a similar issue specific to salt-cloud.
uvsmtid commentedon Jul 5, 2015
AFAIK, multiple results are independently generated by multiple minions (and each run of function on specific minion actually produces valid output).
What could be done on the
saltcommand side (run on the master) is to consolidate data from all minions into internal in-memory object and render it into JSON or any other format after (rather than sending JSON to STDOUT without consolidation). To avoid scalability issues, at least it should appear as if it is done so.Or, particularly in this case, there is a hack to wrap individual output into JSON array:
The problem is that, in order to avoid parsing by user, it still can only be done on master at least to inject commas
,. And this will only work for JSON, and will only look proper when results are of the same type (conceptually, array contains objects of the same type, semantic, structure, etc.).uvsmtid commentedon Jul 13, 2015
I guess this issue is supposed to be fixed by providing
--staticoption and this explanation in documentation.At the moment (
2015.5.2) my tests fail due to fixed issue #24776 which I'll try as soon as native Fedora package is updated.Related #24363.
uvsmtid commentedon Jul 16, 2015
The issue can be considered fixed in
2015.5.3.Test
Without
--static:With
--static:Results
--staticoutput for multiple minions is definitely a valid JSON.rhel5_minionabove) should be included in the--staticoutput with resultfalse, but this is a separate topic. This comment on another issue indicates direction:... I think the pattern is swinging in the direction of "minions which didn't return are treated as an error"
rallytime commentedon Sep 9, 2015
@uvsmtid Thanks very much for this excellent analysis and for the pull request. Since you've stated above that this is considered to be fixed by you in 2015.5.3, I am going to go ahead and close this issue. Thanks again!