Salt-api - Syntax error when calling runner function with multiple periods in name
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description of Issue
In order to better describe the scope of a module and work around the limitation of being unable to next modules within sub-directories, many of our runners and execution modules contain periods in the name to better define the scope. Namely:
cloud.firewall.routing.py with virtualname = 'cloud.firewall.routing'
When calling these modules from the Salt-API we receive a error 400 'Bad Request' stating that the syntax is incorrect. This can be confirmed by changing the module name to simply 'cloud' and it executes fine.
The command executes fine from the salt command line salt-run cloud.firewall.routing.create_static_route <args>
Steps to Reproduce Issue
Posting the following to the root URL of the Salt API after authenticated:
{
"client": "runner",
"fun": "cloud.firewall.routing.create_static_route",
[...]
}
The following POST creates the below results:
body>
<h2>400 Bad Request</h2>
<p>Bad request syntax or unsupported method</p>
<pre id="traceback">Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 860, in hypermedia_handler
ret = cherrypy.serving.request._hypermedia_inner_handler(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/cherrypy/_cpdispatch.py", line 60, in __call__
return self.callable(*self.args, **self.kwargs)
File "/usr/lib/python3.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 1300, in POST
token=cherrypy.session.get('token')))
File "/usr/lib/python3.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 1194, in exec_lowstate
ret = self.api.run(chunk)
File "/usr/lib/python3.6/site-packages/salt/netapi/__init__.py", line 85, in run
return l_fun(*f_call.get('args', ()), **f_call.get('kwargs', {}))
File "/usr/lib/python3.6/site-packages/salt/netapi/__init__.py", line 165, in runner
return runner.cmd_sync(kwargs, timeout=timeout, full_return=full_return)
File "/usr/lib/python3.6/site-packages/salt/runner.py", line 147, in cmd_sync
return mixins.SyncClientMixin.cmd_sync(self, reformatted_low, timeout, full_return)
File "/usr/lib/python3.6/site-packages/salt/client/mixins.py", line 166, in cmd_sync
job = self.master_call(**low)
File "/usr/lib/python3.6/site-packages/salt/client/mixins.py", line 146, in master_call
salt.utils.error.raise_error(**ret['error'])
File "/usr/lib/python3.6/site-packages/salt/utils/error.py", line 33, in raise_error
raise ex(message)
salt.exceptions.SaltInvocationError: A command invocation error occurred: Check syntax.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/cherrypy/_cprequest.py", line 670, in respond
response.body = self.handler()
File "/usr/lib/python3.6/site-packages/cherrypy/lib/encoding.py", line 217, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 867, in hypermedia_handler
raise cherrypy.HTTPError(400)
cherrypy._cperror.HTTPError: (400, None)
</pre>
<div id="powered_by">
<span>
Powered by <a href="http://www.cherrypy.org">CherryPy 5.6.0</a>
</span>
</div>
</body>
This is calling a runner function defined as follows:
/srv/salt/extensions/runners/cloud.firewall.routing.py:
__virtualname__ = 'cloud.firewall.routing'
def __virtual__:
if HAS_DEPS:
return __virtualname__
else:
return (False, 'Dependencies missing')
Versions Report
Salt Version:
Salt: 3000.2
Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 2.11.1
libgit2: Not Installed
M2Crypto: 0.35.2
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.6.2
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: 3.9.7
pygit2: Not Installed
Python: 3.6.8 (default, Apr 2 2020, 13:34:55)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 15.3.0
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.1.4
System Versions:
dist: centos 7.8.2003 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-1062.18.1.el7.x86_64
system: Linux
version: CentOS Linux 7.8.2003 Core
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in salt/netapi/rest_cherrypy/app.py at POST and exec_lowstate, then follow the runner call through salt/netapi/init.py. Reproduce the authenticated POST using the dotted function name and verify that the Salt API accepts cloud.firewall.routing.create_static_route instead of returning HTTP 400.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100