Skip to content

Commit

Permalink
mgr/dashboard: Fix duplicate params error
Browse files Browse the repository at this point in the history
* Remove params, if they use the `{name:regex}` syntax.
* Fixes http://tracker.ceph.com/issues/23823

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
  • Loading branch information
sebastian-philipp committed May 2, 2018
1 parent 94210c6 commit 5b5558f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/pybind/mgr/dashboard/controllers/__init__.py
Expand Up @@ -391,8 +391,13 @@ def _parse_function_args(cls, func):

# filter out controller path params
for idx, step in enumerate(cls._cp_path_.split('/')):
param = None
if step[0] == ':':
param = step[1:]
if step[0] == '{' and step[-1] == '}' and ':' in step[1:-1]:
param, _, _regex = step[1:-1].partition(':')

if param:
if param not in cargs:
raise Exception("function '{}' does not have the"
" positional argument '{}' in the {} "
Expand Down
18 changes: 16 additions & 2 deletions src/pybind/mgr/dashboard/tests/test_tools.py
Expand Up @@ -9,7 +9,7 @@

from ..services.exception import handle_rados_error
from .helper import ControllerTestCase
from ..controllers import RESTController, ApiController
from ..controllers import RESTController, ApiController, BaseController
from ..tools import is_valid_ipv6_address, dict_contains_path


Expand Down Expand Up @@ -45,6 +45,13 @@ def list(self, key, method):
return {'detail': (key, [method])}


@ApiController('rgw/proxy/{path:.*}')
class GenerateControllerRoutesController(BaseController):
@cherrypy.expose
def __call__(self, path, **params):
pass


@ApiController('fooargs')
class FooArgs(RESTController):
def set(self, code, name=None, opt1=None, opt2=None):
Expand All @@ -68,7 +75,8 @@ class RESTControllerTest(ControllerTestCase):

@classmethod
def setup_server(cls):
cls.setup_controllers([FooResource, FooResourceDetail, FooArgs])
cls.setup_controllers(
[FooResource, FooResourceDetail, FooArgs, GenerateControllerRoutesController])

def test_empty(self):
self._delete("/foo")
Expand Down Expand Up @@ -148,6 +156,12 @@ def test_create_form(self):
self.getPage('/fooargs', headers=[('Accept', 'text/html')])
self.assertIn('my_arg_name', self.body.decode('utf-8'))

def test_generate_controller_routes(self):
# We just need to add this controller in setup_server():
# noinspection PyStatementEffect
# pylint: disable=pointless-statement
GenerateControllerRoutesController


class TestFunctions(unittest.TestCase):

Expand Down

0 comments on commit 5b5558f

Please sign in to comment.