New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salt-api request causes exception #48141

Closed
zerthimon opened this Issue Jun 14, 2018 · 7 comments

Comments

Projects
None yet
4 participants
@zerthimon
Contributor

zerthimon commented Jun 14, 2018

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/netapi/rest_cherrypy/app.py", line 858, in hypermedia_handler
    ret = cherrypy.serving.request._hypermedia_inner_handler(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/netapi/rest_cherrypy/app.py", line 1286, in POST
    token=cherrypy.session.get('token')))
  File "/usr/lib/python2.7/dist-packages/salt/netapi/rest_cherrypy/app.py", line 1182, in exec_lowstate
    for i in ret:
  File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 562, in cmd_batch
    salt.utils.versions.warn_until(
UnboundLocalError: local variable 'salt' referenced before assignment
Salt Version:
           Salt: 2018.3.1
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.2.2
       dateutil: 2.4.2
      docker-py: 3.3.0
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-1061-aws
         system: Linux
        version: Ubuntu 16.04 xenial
@zerthimon

This comment has been minimized.

Contributor

zerthimon commented Jun 14, 2018

Seems to happen only for "batch" jobs.

@garethgreenaway

This comment has been minimized.

Member

garethgreenaway commented Jun 18, 2018

@zerthimon Can you provide information about how your calling the Salt API? Any reactors you're using, etc.? That will help us be able to reproduce the issue and hopefully fix it. Thanks!

@zerthimon

This comment has been minimized.

Contributor

zerthimon commented Jun 19, 2018

@garethgreenaway I'm using jenkins salt plugin https://github.com/jenkinsci/saltstack-plugin with batch option configured. @mchugh19 can you provide more info please ?

@mchugh19

This comment has been minimized.

Contributor

mchugh19 commented Jun 19, 2018

The jenkins plugin generates a JSON that looks something like:
{"client":"local_batch","batch":"100%","tgt":"*","expr_form":"glob","fun":"cmd.run","arg":["ls -la"],"kwarg":{}}

@garethgreenaway

This comment has been minimized.

Member

garethgreenaway commented Jun 20, 2018

@mchugh19 Great. Thanks! Is there something on the Salt end, a reactor perhaps that handles this JSON being sent along to the API?

@mchugh19

This comment has been minimized.

Contributor

mchugh19 commented Jun 20, 2018

Sorry, I thought there was more context than there was.

The Jenkins plugin takes some input fields and converts them into json, submits to the salt-api, and then (optionally) checks the result. So that json string pasted above could be written as:

#!/bin/sh

port=8000
server=localhost

JSON='{"client":"local_batch","batch":"100%","tgt":"*","expr_form":"glob","fun":"cmd.run","arg":["ls -la"],"kwarg":{}}'

RESPONSE=`curl -ik http://${server}:${port}/login -H 'Content-Type: application/json' -d '{"eauth":"pam","password":"jenkins","username":"jenkins"}' 2>/dev/null`
TOKEN=$(echo $RESPONSE |
    sed -e 's/[{}]/''/g' |
    sed -e 's/[{}]/''/g' | sed -e 's/"return"://g' |
    awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' |
    grep token | cut -d: -f 2 | cut -d'"' -f 2 )

RESPONSE=`curl -k http://${server}:${port}/ -H 'Accept: application/json' -H "X-Auth-Token: $TOKEN" -H 'Content-Type: application/json' -d "$JSON" 2>/dev/null`
echo $RESPONSE

In salt 2017 that returns

{"return": [{"master": "total 24
drwx------ 4 root root 4096 Oct 4 2017 .
drwxr-xr-x 25 root root 4096 Jun 20 17:26 ..
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwxr-xr-x 3 root root 4096 Oct 4 2017 .jenkins
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
drwx------ 2 root root 4096 Aug 12 2017 .ssh"}, {"minion1": "total 20
drwx------ 3 root root 4096 Aug 12 2017 .
drwxr-xr-x 24 root root 4096 Jun 20 17:27 ..
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
drwx------ 2 root root 4096 Aug 12 2017 .ssh"}]}

With salt-api 2018.3.1 (Oxygen), it returns:

{"status": 500, "return": "An unexpected error occurred"}
@garethgreenaway

This comment has been minimized.

Member

garethgreenaway commented Jun 20, 2018

@mchugh19 Perfect! With this I am able to reproduce the error. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment