Inconsistent API result structure between local and local_batch #52762
Labels
Bug
broken, incorrect, or confusing behavior
Regression
The issue is a bug that breaks functionality known to work in previous releases.
Salt-API
severity-medium
3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone
Description of Issue/Question
Calling the same function from the API might result in having a
retcode
field or not depending on whether thelocal
orlocal_batch
client is using, eg.:Running a
state.apply
with afile.absent
in it, via thelocal
client:master:~ # curl -X POST http://localhost:9080/run --data @request.json -H "Content-Type: application/json"
Note how, in each minion, the result is a mapping from an identifier string to an object.
Same call via the
local_batch
client:master:~ # curl -X POST http://localhost:9080/run --data @request.json -H "Content-Type: application/json"
Note how the result also contains "special" key,
retcode
, which maps to a single number.This makes it difficult to write exact parsers for the JSON structure, as we experienced in the salt-netapi-client project, where such a structure is translated into a
Map<String, ApplyResult>
object - mapping fails whenretcode
is found as it maps to a number and not an object.Part of the reason why this is challenging is due to the fact
retcode
is not added to some "external" structure (in the example above: in the "return" map), but together with legitimate minion results. For other calls, such ascmd.run_all
, this even conflicts with an existing returned keyretcode
:It is also challenging because
retcode
is only added:retcode
alreadyCode responsible for this behavior is located in
batch.py
was added by #38668, specifically it is located in these lines:https://github.com/saltstack/salt/blob/develop/salt/cli/batch.py#L310-L311
Setup
In
/etc/salt/master.d/api.conf
:Sample request:
Steps to Reproduce Issue
To run the request:
curl -X POST http://localhost:9080/run --data @request.json -H "Content-Type: application/json"
Versions Report
Tested on salt 2018.3.0 (Oxygen) and 2019.2
The text was updated successfully, but these errors were encountered: