You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Return errors in salt-api calls; add API-centric support for new exit codes #20301
I have setup salt-api (cherrypy) and a salt-master on the same machine and i have a few minions connected to the master.
If i then issue a command to be executed to the api that do not match any targets i get back from requests the following:
>>>r<Response [200]>>>>r.textu'{"return": [{}]}'
But i get a string output on stdout from salt-api saying No minions matched the target. No command was sent, no jid was assigned. so clearly the error is recognized somewhere but the error is not handled by the root endpoint.
@Grokzen this behavior matches Salt's CLI and Python API (empty results); the CLI additionally checks that return is empty and reports that message on stderr if so. What would you prefer to see via the REST API?
Well i am not sure exactly what the best solution would be but i would say that it do not conform with error handling in the cli right now.
Look at this example:
salt-master:~ # salt foobar test.ping --out=json
No minions matched the target. No command was sent, no jid was assigned.
salt-master:~ # echo $?
2
salt-master:~ # salt '*' test.ping
salt-minion:
True
salt-master:~ # echo $?
0
If i from the cli target a minion that do not exists i get back a empty response and that error on stdout that no minions matched the target. But when i look at the exit codes i still get 2 from the call that seemed to be ok.
If we translate this to how it works now in the api when my target matches no minions i get back OK and 200 code that would be like getting back 0 status code on the cli.
I have also looked at if a http error code would be good for this but i do not think so because i can't find any that makes sense in this case.
But it might be good enough at the same time as is and i would have to assume that if the return block is empty then no targets was matched even if that is a big assumption on what the problem really is.
Hm. Thanks for pointing that out. The retcode thing is fairly new. It looks like we started hiding the empty return as well. Though this is a separate issue, it's problematic at the Python API level because it's printing to stderr when it shouldn't:
We can't approach this at the HTTP status code level because you can send more than one command in a request, each of which may have a different result:
changed the title [-]salt-api (cherrypy) can't handle wrong minion targets[/-][+]Return errors in salt-api calls; add API-centric support for new exit codes[/+]on Feb 4, 2015
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
I think this can be closed now that #41356 is in. We can't change the HTTP status code for the root (/) endpoint since it can handle multiple function calls and is more RPC-like, but now the return code info can be returned from the API directly.
Edit: Oh, and feel free to comment, reopen, or file a follow-up issue for more specific things than just surfacing the retcode.
Activity
jfindlay commentedon Feb 2, 2015
@Grokzen, thanks for reporting.
whiteinge commentedon Feb 2, 2015
@Grokzen this behavior matches Salt's CLI and Python API (empty results); the CLI additionally checks that return is empty and reports that message on stderr if so. What would you prefer to see via the REST API?
Grokzen commentedon Feb 2, 2015
Well i am not sure exactly what the best solution would be but i would say that it do not conform with error handling in the cli right now.
Look at this example:
If i from the cli target a minion that do not exists i get back a empty response and that error on stdout that no minions matched the target. But when i look at the exit codes i still get 2 from the call that seemed to be ok.
If we translate this to how it works now in the api when my target matches no minions i get back OK and 200 code that would be like getting back 0 status code on the cli.
I have also looked at if a http error code would be good for this but i do not think so because i can't find any that makes sense in this case.
But it might be good enough at the same time as is and i would have to assume that if the return block is empty then no targets was matched even if that is a big assumption on what the problem really is.
whiteinge commentedon Feb 2, 2015
Hm. Thanks for pointing that out. The retcode thing is fairly new. It looks like we started hiding the empty return as well. Though this is a separate issue, it's problematic at the Python API level because it's printing to stderr when it shouldn't:
We can't approach this at the HTTP status code level because you can send more than one command in a request, each of which may have a different result:
We could add an
errorskey to the return (same level as thereturnkey):whiteinge commentedon Feb 2, 2015
Relevant CLI exit code commentary.
Grokzen commentedon Feb 3, 2015
@whiteinge It sounds like a good improvment. It would make it easy to understand and track down what the cause of the problem is.
[-]salt-api (cherrypy) can't handle wrong minion targets[/-][+]Return errors in salt-api calls; add API-centric support for new exit codes[/+]whiteinge commentedon Feb 4, 2015
Cool. Classifying it as such. We'll try to make this change coincide with the proposal in #18510 too.
Thanks for filing this!
inthecloud247 commentedon Feb 13, 2015
+1
stale commentedon Oct 15, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
whiteinge commentedon Oct 16, 2017
I think this can be closed now that #41356 is in. We can't change the HTTP status code for the root (
/) endpoint since it can handle multiple function calls and is more RPC-like, but now the return code info can be returned from the API directly.Edit: Oh, and feel free to comment, reopen, or file a follow-up issue for more specific things than just surfacing the retcode.