Skip to content
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-sapi Runner Always Returns "Please specify a Salt function to execute." #189

Closed
lacmcg opened this issue Oct 29, 2020 · 2 comments · Fixed by #190
Closed

salt-sapi Runner Always Returns "Please specify a Salt function to execute." #189

lacmcg opened this issue Oct 29, 2020 · 2 comments · Fixed by #190
Labels
bug Something isn't working salt-sapi
Milestone

Comments

@lacmcg
Copy link

lacmcg commented Oct 29, 2020

Describe the bug
Executing a simple test.ping from salt-sapi always returns "Please specify a Salt function to execute." when executing via the examples provided at https://salt-sproxy.readthedocs.io/en/latest/salt_api.html

Steps To Reproduce
General -

Master config:

external_auth:
  pam:
    '*':
      - '.*'
      - '@runner'
      - '@wheel'
      - '@jobs'

pillar_roots:
  base:
    - /srv/salt/pillar

file_roots:
  base:
  - /srv/salt/
  - /usr/local/lib/python3.6/site-packages/salt_sproxy

runner_dirs:
- /usr/local/lib/python3.6/site-packages/salt_sproxy/_runners

roster: netbox
netbox:
  url: http://localhost:8000
  token: [snip]

rest_cherrypy:
  port: 8080
  disable_ssl: True

top.sls

base:
  'lach-lab':
    - nxapi-test

nxapi-test.sls

proxy:
  proxytype: napalm
  driver: nxos
  username: admin
  password: ''
  host: {{opts.id}}
  optional_args:
    port: 20000

Execute a POST with the payload as follows:

{
    "eauth": "pam",
    "username": "lach",
    "password": "examplepassword",
    "client": "sproxy", 
    "fun": "test.ping", 
    "tgt": "lach-lab"
}

Result

[root@SYD-SALT ~]#  salt-run state.event pretty=True
salt/run/20201029112247657037/new       {
    "_stamp": "2020-10-29T11:22:48.383437",
    "fun": "runner.proxy.execute",
    "fun_args": [
        {
            "failhard": false,
            "function": "test.ping",
            "roster": "netbox",
            "show_jid": false,
            "static": true,
            "tgt": "lach-lab",
            "tgt_type": "glob"
        }
    ],
    "jid": "20201029112247657037",
    "user": "lach"
}
salt/run/20201029112247657037/ret       {
    "_stamp": "2020-10-29T11:22:48.639441",
    "fun": "runner.proxy.execute",
    "fun_args": [
        {
            "failhard": false,
            "function": "test.ping",
            "roster": "netbox",
            "show_jid": false,
            "static": true,
            "tgt": "lach-lab",
            "tgt_type": "glob"
        }
    ],
    "jid": "20201029112247657037",
    "return": "Please specify a Salt function to execute.",
    "success": true,
    "user": "lach"
}

salt-sapi debug:

[DEBUG   ] New kwargs:
[DEBUG   ] {'eauth': 'pam', 'username': 'lach', 'password': 'examplepassword', 'client': 'sproxy', 'function': 'test.ping', 'tgt': 'lach-lab', 'tgt_type': 'glob', 'static': True, 'roster': 'netbox', 'show_jid': False, 'failhard': False}
[DEBUG   ] LazyLoaded proxy.execute
[DEBUG   ] MasterEvent PUB socket URI: /var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: /var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/master', 'SYD-SALT_master', 'tcp://127.0.0.1:4506', 'clear')
[DEBUG   ] Connecting the Minion to the Master URI (for the return server): tcp://127.0.0.1:4506
[DEBUG   ] Trying to connect to: tcp://127.0.0.1:4506
[DEBUG   ] Closing AsyncZeroMQReqChannel instance
[DEBUG   ] Closing IPCMessageSubscriber instance
[INFO    ] 172.30.69.13 - - [29/Oct/2020:07:22:48] "POST /run HTTP/1.1" 200 58 "" ""

Expected behavior
A response similar to when executing the same function via the CLI.

salt/run/20201029112618391026/ret       {
    "_stamp": "2020-10-29T11:26:23.945759",
    "fun": "runner.proxy.execute",
    "fun_args": [
        "lach-lab",
        "test.ping",
        {
            "args": [],
            "batch_size": 4,
            "batch_wait": 0,
            "default_grains": {},
...
            "tgt_type": "glob",
            "timeout": 60,
            "use_existing_proxy": false,
            "verbose": false
        }
    ],
    "jid": "20201029112618391026",
    "return": "",
    "success": true,
    "user": "lach"
}

Versions Report
Print the output from salt-sproxy -V inside the backticks below:

[root@SYD-SALT _runners]# salt-sproxy -V
Salt Version:
           Salt: 3002
    Salt SProxy: 2020.10.0

Dependency Versions:
        Ansible: Not Installed
           cffi: 1.14.3
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.10.1
     junos-eznc: 2.5.3
       jxmlease: Not Installed
        libgit2: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
         NAPALM: 3.2.0
       ncclient: 0.6.9
        Netmiko: 3.3.2
       paramiko: 2.7.2
      pycparser: 2.20
       pycrypto: Not Installed
   pycryptodome: Not Installed
         pyeapi: 0.8.3
         pygit2: Not Installed
       PyNetBox: 5.1.0
          PyNSO: Not Installed
         Python: 3.6.8 (default, Apr 16 2020, 01:36:27)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 19.0.0
            scp: 0.13.3
          smmap: Not Installed
        textfsm: 1.1.0
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.3

System Versions:
           dist: centos 8 Core
         locale: UTF-8
        machine: x86_64
        release: 4.18.0-193.19.1.el8_2.x86_64
         system: Linux
        version: CentOS Linux 8 Core

Additional context
I've tried setting up an environment from scratch to see if I'm missing something, or if the version of Python3 makes any difference, however no such luck. It seems the variablesalt_function in salt_sproxy/_runners/proxy.py always evaluates to False in my case. Executing salt-sproxy '*' test.ping from the CLI works fine for any number of my test devices. I hope I'm just missing something obvious :-)

@lacmcg lacmcg added bug Something isn't working pending triage labels Oct 29, 2020
@mirceaulinic
Copy link
Owner

Thanks for the detailed report @lacmcg. You're correct, the issue is with salt_function. I have patched this in #190, would you be able to give it a try and confirm?

@mirceaulinic mirceaulinic added this to the 2020.10.1 milestone Oct 29, 2020
@lacmcg
Copy link
Author

lacmcg commented Oct 29, 2020

Thanks for the detailed report @lacmcg. You're correct, the issue is with salt_function. I have patched this in #190, would you be able to give it a try and confirm?

Thanks for the quick reply! That's more like it 👍

[root@SYD-SALT salt_sproxy]# salt-run state.event pretty=True
salt/run/20201029115253877016/new       {
    "_stamp": "2020-10-29T11:52:54.600015",
    "fun": "runner.proxy.execute",
    "fun_args": [
        {
            "failhard": false,
            "roster": "netbox",
            "salt_function": "test.ping",
            "show_jid": false,
            "static": true,
            "tgt": "lach-lab",
            "tgt_type": "glob"
        }
    ],
    "jid": "20201029115253877016",
    "user": "lach"
}
20201029115254754934    {
    "_stamp": "2020-10-29T11:52:54.757022",
    "minions": [
        "lach-lab"
    ]
}
proxy/runner/20201029115254759748/new   {
    "_stamp": "2020-10-29T11:52:54.761646",
    "arg": [],
    "fun": "test.ping",
    "jid": "20201029115254759748",
    "minions": [
        "lach-lab"
    ],
    "tgt": "lach-lab",
    "tgt_type": "glob",
    "user": "root"
}
proxy/runner/20201029115254759748/ret/lach-lab  {
    "_stamp": "2020-10-29T11:52:59.260434",
    "fun": "test.ping",
    "fun_args": [],
    "id": "lach-lab",
    "jid": "20201029115254759748",
    "retcode": 0,
    "return": true,
    "success": true
}
salt/run/20201029115253877016/ret       {
    "_stamp": "2020-10-29T11:52:59.299957",
    "fun": "runner.proxy.execute",
    "fun_args": [
        {
            "failhard": false,
            "roster": "netbox",
            "salt_function": "test.ping",
            "show_jid": false,
            "static": true,
            "tgt": "lach-lab",
            "tgt_type": "glob"
        }
    ],
    "jid": "20201029115253877016",
    "return": {
        "lach-lab": true
    },
    "success": true,
    "user": "lach"
}

Excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working salt-sapi
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants