Skip to content

Return value for Salt API calls #39452

Closed
Closed

Description

@sumeetisp

Description of Issue/Question

I am using salt API to run commands like cloud.list_locations using runner client. The output is perfectly accurate. My concern is with return value.
When I run the cloud.list_locations I get a list of locations with no other detail. Along with the output I want to know the return value the API call gives so that I can use it to determine whether the call was successful or not. I can then use it to update other integrated applications.

So doest salt API call give a return value? If yes how to access it?

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

Activity

  1. whiteinge commented on Feb 16, 2017

    @whiteinge
    Contributor

    The exit code is not currently exposed by Salt's public-facing API methods. It is a newer addition and still unfinished and undocumented (see #18510), although it is still useful in it's current state and this is a recurring ask. We'll get it added.

  2. added
    Core
    Feature
    on Feb 16, 2017
  3. added this to the Approved milestone on Feb 16, 2017
  4. self-assigned this
    on Feb 16, 2017
  5. whiteinge commented on Feb 18, 2017

    @whiteinge
    Contributor

    PR above adds an initial implementation of how to expose this info.

  6. mchugh19 commented on Feb 18, 2017

    @mchugh19
    Contributor

    Also looks like a start to resolve #37043

  7. whiteinge commented on Feb 18, 2017

    @whiteinge
    Contributor

    Thanks for cross-linking those issues! This turned out to be much easier than I first thought. I tested this addition from salt-api and the extra return output Just Worked (TM). We might want a convenience in salt-api somewhere to avoid having to pass the extra kwarg all the time.

  8. rbjorklin commented on Apr 3, 2017

    @rbjorklin
    Contributor

    @whiteinge Have your additions been merged into 2016.11 or will they be released with the upcomming 2017.xx release?

  9. whiteinge commented on Apr 3, 2017

    @whiteinge
    Contributor

    2017.xx (Nitrogen). Thanks for asking -- I forgot to add this to the upcoming release notes.

  10. mchugh19 commented on Apr 6, 2017

    @mchugh19
    Contributor

    @whiteinge Can you give an example salt-api call to trigger the full_return=True functionality? In adding the bits from #39492 and then sending JSON like:

    {"client":"runner","fun":"salt.cmd","arg":"test.ping","kwarg":{"full_return": "True"}}
    

    salt-api sends back
    {"return": ["Exception occurred in runner salt.cmd: Traceback (most recent call last):\n File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 395, in _low\n data['return'] = self.functions[fun](*args, **kwargs)\n File "/usr/lib/python2.7/dist-packages/salt/runners/salt.py", line 67, in cmd\n utils=utils(opts)).get(fun)(*args, **kws)\nTypeError: ping() takes no arguments (1 given)\n"]}

    While sending JSON for cmd.run, doesn't show the full_return functionality at all:

    {"client":"local","tgt":"*","expr_form":"glob","fun":"cmd.run","arg":"sleep 5; ls -la","kwarg":{"full_return": "True"}}
    
    {"return": [{"minion1": "total 20\n... root 4096 Mar 25 07:51 .ssh"}]}
    
  11. whiteinge commented on Apr 6, 2017

    @whiteinge
    Contributor

    The arg and kwarg values are sent to the module that is being invoked but this addition is a kwarg on the class itself so it should be top-level:

    {
      "client": "local",
      "tgt": "*",
      "expr_form": "glob",
      "fun": "cmd.run",
      "arg": "sleep 5; ls -la",
      "full_return": "True"
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CoreFeature

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions