Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

salt-api run state will return immediately return null #148

Open
justlooks opened this issue Mar 27, 2014 · 6 comments
Open

salt-api run state will return immediately return null #148

justlooks opened this issue Mar 27, 2014 · 6 comments
Labels

Comments

@justlooks
Copy link

if i do the following request,it will return null immediately ,if salt state do lot's of stuff,it will cause problem because salt-api return ,but salt job still not finish,another question is how can i judge if the action is success or failed?

# curl -k http://myip:8888/run  -d client=local -d tgt='CH22' -d fun='state.sls' -d arg='testme' -d username='xxxx' -d password='xxxx' -d eauth='pam'

{"return": [{}]}
@whiteinge
Copy link
Contributor

You can increase the timeout by adding -d timeout=300 to the call.

The result of the job can be referenced after the fact via the jobs runner, just like at Salt's CLI.

# curl -k http://myip:8888/run  -d client=runner -d fun='jobs.list_jobs' -d username='xxxx' -d password='xxxx' -d eauth='pam'
# curl -k http://myip:8888/run  -d client=runner -d fun='jobs.lookup_jid' -d jid=XXX -d username='xxxx' -d password='xxxx' -d eauth='pam'

There's an open issue (#139) to get the JID in the output so you don't have to go looking for it if there's a timeout. For right now, you can specify a long timeout like above or you can run the job asynchronously with the local_async client and get the JID that way.

@justlooks
Copy link
Author

i try set the timeout to a big value,but it seems no use, and i use
version salt-api-0.8.3-1.el5

curl -k http://192.168.10.231:8888 -H

"X-Auth-Token:d4e31ff29001f749d03fc89105568f69b2d2307b" -d client='local'
-d tgt='saltslave2' -d fun='state.sls' -d arg='tomcat.newinstance' -d
timeout=3000
{"return": [{}]}

curl -k http://192.168.10.231:8888/run -d client=runner -d

fun='jobs.list_jobs' -d username='salt' -d password='salt' -d eauth='pam'
{"status": 500, "return": "Traceback (most recent call last):\n File
"/usr/lib/python2.6/site-packages/saltapi/netapi/rest_cherrypy/app.py",
line 255, in hypermedia_handler\n ret =
cherrypy.serving.request._hypermedia_inner_handler(_args, *_kwargs)\n File
"/usr/lib/python2.6/site-packages/cherrypy/_cpdispatch.py", line 34, in
call\n return self.callable(_self.args, *_self.kwargs)\n File
"/usr/lib/python2.6/site-packages/saltapi/netapi/rest_cherrypy/app.py",
line 976, in POST\n 'return': list(self.exec_lowstate()),\n File
"/usr/lib/python2.6/site-packages/saltapi/netapi/rest_cherrypy/app.py",
line 918, in exec_lowstate\n yield self.api.run(chunk)\n File
"/usr/lib/python2.6/site-packages/saltapi/init.py", line 62, in
run\n ret = l_fun(_f_call.get('args', ()), *_f_call.get('kwargs',
{}))\n File "/usr/lib/python2.6/site-packages/saltapi/init.py", line
95, in runner_sync\n return runner.low(fun, kwargs)\n File
"/usr/lib/python2.6/site-packages/salt/runner.py", line 139, in low\n
ret = l_fun(_f_call.get('args', ()), *_f_call.get('kwargs', {}))\n File
"/usr/lib/python2.6/site-packages/salt/runners/jobs.py", line 137, in
list_jobs\n salt.output.display_output(ret, 'yaml', opts)\n File
"/usr/lib/python2.6/site-packages/salt/output/init.py", line 53, in
display_output\n raise exc\nIOError: [Errno 5] Input/output error\n"}

On Fri, Mar 28, 2014 at 1:36 AM, Seth House [email protected]:

You can increase the timeout by adding -d timeout=300 to the call.

The result of the job can be referenced after the fact via the jobs
runner, just like at Salt's CLI.

curl -k http://myip:8888/run -d client=runner -d fun='jobs.list_jobs' -d username='xxxx' -d password='xxxx' -d eauth='pam'

curl -k http://myip:8888/run -d client=runner -d fun='jobs.lookup_jid' -d jid=XXX -d username='xxxx' -d password='xxxx' -d eauth='pam'

There's an open issue (#139#139)
to get the JID in the output so you don't have to go looking for it if
there's a timeout. For right now, you can specify a long timeout like above
or you can run the job asynchronously with the local_async client and get
the JID that way.

Reply to this email directly or view it on GitHubhttps://github.com//issues/148#issuecomment-38835742
.

@whiteinge
Copy link
Contributor

Regarding the timeout: do you still get the empty return immediately when using the timeout arg or does it at least wait that long before returning?

Regarding the IOError: interesting. I have seen this before though not in little while. Can you post your rest_cherrypy config settings? How did you start the salt-api daemon and what OS are you running?

@whiteinge whiteinge added the bug label Mar 28, 2014
@justlooks
Copy link
Author

time curl -k http://192.168.10.124:8888 -H

"X-Auth-Token:69f9839713a7712336e13e726bffebd7d81b2a46" -d client='local'
-d tgt='saltslave2' -d fun='state.sls' -d arg='tomcat.newinstance' -d
timeout=3000
{"return": [{}]}
real 0m0.119s
user 0m0.001s
sys 0m0.003s

time curl -k http://192.168.10.124:8888 -H

"X-Auth-Token:69f9839713a7712336e13e726bffebd7d81b2a46" -d client='local'
-d tgt='saltslave2' -d fun='state.sls' -d arg='tomcat.newinstance'
{"return": [{}]}
real 0m0.120s
user 0m0.002s
sys 0m0.002s

cat /etc/redhat-release

Red Hat Enterprise Linux Server release 5.5 (Tikanga)

rpm -qa|grep salt

salt-2014.1.0-1.el5
salt-api-0.8.3-1.el5
salt-minion-2014.1.0-1.el5
salt-master-2014.1.0-1.el5

cat /etc/salt/master.d/saltapi.conf

rest_cherrypy:
port: 8888
host: 0.0.0.0
debug: True
disable_ssl: True

curl -k http://192.168.10.124:8888/login -H "Accept: application/x-yaml"

-d username='salt' -d password='salt' -d
eauth='pam' return:

  • eauth: pam
    expire: 1396095221.878418
    perms:
    • .*
    • '@runner'
    • '@wheel'
      start: 1396052021.878418
      token: 9d2a467553801a33ad107da9bfed0f2e5da77697
      user: salt

service salt-api start

Starting salt-api daemon: [ERROR ] Not loading 'rest_wsgi'. 'port' not
specified in config
[26/Mar/2014:11:12:22] ENGINE Listening for SIGHUP.
[26/Mar/2014:11:12:22] ENGINE Listening for SIGTERM.
[26/Mar/2014:11:12:22] ENGINE Listening for SIGUSR1.
[26/Mar/2014:11:12:22] ENGINE Bus STARTING
CherryPy Checker:
'log_file' is obsolete. Use 'log.error_file' instead.
section: [saltopts]
[26/Mar/2014:11:12:22] ENGINE Started monitor thread '_TimeoutMonitor'.
[26/Mar/2014:11:12:22] ENGINE Started monitor thread 'Autoreloader'.
[26/Mar/2014:11:12:22] ENGINE Serving on 0.0.0.0:8888
[26/Mar/2014:11:12:22] ENGINE Bus STARTED
[26/Mar/2014:11:14:52] ENGINE Started monitor thread 'Session cleanup'.
192.168.10.124 - - [26/Mar/2014:11:14:52] "POST /login HTTP/1.1" 200 184 ""
"curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b
zlib/1.2.3 libidn/0.6.5"
192.168.10.124 - - [26/Mar/2014:11:15:45] "GET /minions HTTP/1.1" 200 60901
"" "curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b
zlib/1.2.3 libidn/0.6.5"
192.168.10.124 - - [26/Mar/2014:11:15:59] "GET /minions HTTP/1.1" 200 60901
"" "curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b
zlib/1.2.3 libidn/0.6.5"
192.168.2.166 - - [26/Mar/2014:15:03:15] "POST /login HTTP/1.1" 200 196 ""
"cabin-clent"
192.168.2.166 - - [26/Mar/2014:15:03:15] "POST /login HTTP/1.1" 200 195 ""
"cabin-clent"
192.168.2.166 - - [26/Mar/2014:15:03:15] "GET /minions HTTP/1.1" 200 54310
"" "cabin-clent"
192.168.2.166 - - [26/Mar/2014:15:03:16] "POST / HTTP/1.1" 200 42676 ""
"cabin-clent"

On Fri, Mar 28, 2014 at 11:14 PM, Seth House [email protected]:

Regarding the timeout: do you still get the empty return immediately when
using the timeout arg or does it at least wait that long before returning?

Regarding the IOError: interesting. I have seen this before though not in
little while. Can you post your rest_cherrypy config settings? How did
you start the salt-api daemon and what OS are you running?

Reply to this email directly or view it on GitHubhttps://github.com//issues/148#issuecomment-38929951
.

@whiteinge
Copy link
Contributor

Great stuff. Thanks for posting all that. I'll grab a RHEL vm and try to duplicate your setup.

I'd like to get you at least semi-working while I look into this. It looks like the service script that came in that RPM isn't passing the -d flag when starting salt-api since there should not be any output to the terminal. That may be the source of the IOError. Can you edit that service file to add the -d flag or start salt-api manually with salt-api -d?

@justlooks
Copy link
Author

yes, i try run salt-api as daemon, the following command is ok

curl -k http://192.168.10.124:8888/run -d client=runner -d

fun='jobs.list_jobs'

here is what i modify on /etc/init.d/salt-api ,i do not know if it will
cause problem on DEBIAN and suse linux ,i have no envionment for both two

 48 SERVICE=salt-api
 49 PROCESS=salt-api
 50 CONFIG_ARGS=""     =>  CONFIG_ARGS="-d"

On Sat, Mar 29, 2014 at 11:55 AM, Seth House [email protected]:

Great stuff. Thanks for posting all that. I'll grab a RHEL vm and try to
duplicate your setup.

I'd like to get you at least semi-working while I look into this. It looks
like the service script that came in that RPM isn't passing the -d flag
when starting salt-api since there should not be any output to the
terminal. That may be the source of the IOError. Can you edit that
service file to add the -d flag or start salt-api manually with salt-api
-d?

Reply to this email directly or view it on GitHubhttps://github.com//issues/148#issuecomment-38986128
.

@justlooks justlooks assigned basepi and cro and unassigned basepi and cro May 14, 2014
pengyao added a commit to pengyao/salt that referenced this issue Jun 5, 2014
Timeout is unicode type in salt rest api by POST data.
The issue in salt-api: vmware-archive/salt-api#148
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants