I'm replacing a fully integrated Celery > Salt coupling, based on salt.client.LocalClient(), to a REST API based setup. All is working, except ...
I need to programmatically establish the failure of a cmd.run invoked over the Salt REST API.
The working CLI example
Command returning ok:
$ salt srv101 cmd.run "ls /root/"
srv101:
snap
$ echo $?
0
Command returning error:
$ salt srv101 cmd.run "ls /NOroot/"
srv101:
ls: cannot access '/NOroot/': No such file or directory
ERROR: Minions returned with non-zero exit code
$ echo $?
1
REST example (either output OR retcode)
Call that returns the ok:
$ curl -L -sSi localhost:7000/run -H "Accept: application/x-yaml" -d username='root' -d password='SORRY;)' -d eauth=pam -d client='local' -d tgt='srv101' -d fun='cmd.run' -d arg='ls /root/'
HTTP/1.1 200 OK
Server: TornadoServer/4.5.3
Content-Type: application/x-yaml
Date: Wed, 20 Jan 2021 21:24:31 GMT
Content-Length: 33
return:
- {srv101: snap}
Call that returns erroneous output but without error code:
$ curl -L -sSi localhost:7000/run -H "Accept: application/x-yaml" -d username='root' -d password='SORRY;)' -d eauth=pam -d client='local' -d tgt='srv101' -d fun='cmd.run' -d arg='ls /NOroot/'
HTTP/1.1 200 OK
Server: TornadoServer/4.5.3
Content-Type: application/x-yaml
Date: Wed, 20 Jan 2021 21:24:43 GMT
Content-Length: 88
return:
- {srv101: 'ls: cannot access ''/NOroot/'': No such file or directory'}
I can see the output, which is erronious, thus correct. But how to detect this without parsing all variations on output or running cmd.retcode the secondtime (which potentially can have a changed situation when executing the second time).
Thanks! :)