Skip to content

Commit

Permalink
Merge pull request ceph#35564 from rhcs-dashboard/wip-45957-fixUiApiE…
Browse files Browse the repository at this point in the history
…ndpoints

mgr/dashboard: fix ui api endpoints
  • Loading branch information
callithea authored Jul 2, 2020
2 parents e4673f4 + d1a5300 commit 44908df
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/pybind/mgr/dashboard/controllers/cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cherrypy
import cephfs

from . import ApiController, RESTController, UiApiController
from . import ApiController, ControllerDoc, RESTController, UiApiController
from .. import mgr
from ..exceptions import DashboardException
from ..security import Scope
Expand Down Expand Up @@ -467,6 +467,7 @@ def get(self):


@UiApiController('/cephfs', Scope.CEPHFS)
@ControllerDoc("Dashboard UI helper function; not part of the public API", "CephFSUi")
class CephFsUi(CephFS):
RESOURCE_ID = 'fs_id'

Expand Down
4 changes: 3 additions & 1 deletion src/pybind/mgr/dashboard/controllers/crush_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from cherrypy import NotFound

from . import ApiController, RESTController, Endpoint, ReadPermission, UiApiController
from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, \
UiApiController
from ..security import Scope
from ..services.ceph_service import CephService
from .. import mgr
Expand Down Expand Up @@ -35,6 +36,7 @@ def delete(self, name):


@UiApiController('/crush_rule', Scope.POOL)
@ControllerDoc("Dashboard UI helper function; not part of the public API", "CrushRuleUi")
class CrushRuleUi(CrushRule):
@Endpoint()
@ReadPermission
Expand Down
15 changes: 8 additions & 7 deletions src/pybind/mgr/dashboard/controllers/docs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from typing import Any, Dict, Union

import logging
import cherrypy
Expand Down Expand Up @@ -31,7 +32,7 @@ def _gen_tags(cls, all_endpoints):
if endpoint.is_api or all_endpoints:
list_of_ctrl.add(endpoint.ctrl)

tag_map = {}
tag_map: Dict[str, str] = {}
for ctrl in list_of_ctrl:
tag_name = ctrl.__name__
tag_descr = ""
Expand Down Expand Up @@ -183,7 +184,7 @@ def _gen_schema_for_content(cls, params):

@classmethod
def _gen_responses(cls, method, resp_object=None):
resp = {
resp: Dict[str, Dict[str, Union[str, Any]]] = {
'400': {
"description": "Operation exception. Please check the "
"response body for details."
Expand Down Expand Up @@ -252,7 +253,7 @@ def _gen_params(cls, params, location):
return parameters

@classmethod
def _gen_paths(cls, all_endpoints, base_url):
def _gen_paths(cls, all_endpoints):
method_order = ['get', 'post', 'put', 'delete']
paths = {}
for path, endpoints in sorted(list(ENDPOINT_MAP.items()),
Expand Down Expand Up @@ -308,7 +309,7 @@ def _gen_paths(cls, all_endpoints, base_url):
methods[method.lower()]['security'] = [{'jwt': []}]

if not skip:
paths[path[len(base_url):]] = methods
paths[path] = methods

return paths

Expand All @@ -320,7 +321,7 @@ def _gen_spec(self, all_endpoints=False, base_url=""):
host = host[host.index(':')+3:]
logger.debug("Host: %s", host)

paths = self._gen_paths(all_endpoints, base_url)
paths = self._gen_paths(all_endpoints)

if not base_url:
base_url = "/"
Expand Down Expand Up @@ -363,11 +364,11 @@ def _gen_spec(self, all_endpoints=False, base_url=""):

@Endpoint(path="api.json")
def api_json(self):
return self._gen_spec(False, "/api")
return self._gen_spec(False, "/")

@Endpoint(path="api-all.json")
def api_all_json(self):
return self._gen_spec(True, "/api")
return self._gen_spec(True, "/")

def _swagger_ui_page(self, all_endpoints=False, token=None):
base = cherrypy.request.base
Expand Down
4 changes: 3 additions & 1 deletion src/pybind/mgr/dashboard/controllers/erasure_code_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from cherrypy import NotFound

from . import ApiController, RESTController, Endpoint, ReadPermission, UiApiController
from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, \
UiApiController
from ..security import Scope
from ..services.ceph_service import CephService
from .. import mgr
Expand Down Expand Up @@ -36,6 +37,7 @@ def delete(self, name):


@UiApiController('/erasure_code_profile', Scope.POOL)
@ControllerDoc("Dashboard UI helper function; not part of the public API", "ErasureCodeProfileUi")
class ErasureCodeProfileUi(ErasureCodeProfile):
@Endpoint()
@ReadPermission
Expand Down
19 changes: 10 additions & 9 deletions src/pybind/mgr/dashboard/controllers/pool.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from typing import Any, cast, Dict, Iterable, List, Optional, Union

import time
import cherrypy

from . import ApiController, RESTController, Endpoint, ReadPermission, Task, UiApiController
from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, Task, \
UiApiController
from .. import mgr
from ..security import Scope
from ..services.ceph_service import CephService
Expand All @@ -27,7 +29,7 @@ def _serialize_pool(pool, attrs):

crush_rules = {r['rule_id']: r["rule_name"] for r in mgr.get('osd_map_crush')['rules']}

res = {}
res: Dict[Union[int, str], Union[str, List[Any]]] = {}
for attr in attrs:
if attr not in pool:
continue
Expand Down Expand Up @@ -60,16 +62,14 @@ def list(self, attrs=None, stats=False):
return self._pool_list(attrs, stats)

@classmethod
def _get(cls, pool_name, attrs=None, stats=False):
# type: (str, str, bool) -> dict
def _get(cls, pool_name: str, attrs: Optional[str] = None, stats: bool = False) -> dict:
pools = cls._pool_list(attrs, stats)
pool = [p for p in pools if p['pool_name'] == pool_name]
if not pool:
raise cherrypy.NotFound('No such pool')
return pool[0]

def get(self, pool_name, attrs=None, stats=False):
# type: (str, str, bool) -> dict
def get(self, pool_name: str, attrs: Optional[str] = None, stats: bool = False) -> dict:
pool = self._get(pool_name, attrs, stats)
pool['configuration'] = RbdConfiguration(pool_name).list()
return pool
Expand Down Expand Up @@ -114,7 +114,7 @@ def set_app(what, app):
yes_i_really_mean_it=True)
if update_existing:
original_app_metadata = set(
current_pool.get('application_metadata'))
cast(Iterable[Any], current_pool.get('application_metadata')))
else:
original_app_metadata = set()

Expand Down Expand Up @@ -207,6 +207,7 @@ def configuration(self, pool_name):


@UiApiController('/pool', Scope.POOL)
@ControllerDoc("Dashboard UI helper function; not part of the public API", "PoolUi")
class PoolUi(Pool):
@Endpoint()
@ReadPermission
Expand All @@ -230,8 +231,8 @@ def get_config_option_enum(conf_name):
if o['name'] == conf_name][0]

profiles = CephService.get_erasure_code_profiles()
used_rules = {}
used_profiles = {}
used_rules: Dict[str, List[str]] = {}
used_profiles: Dict[str, List[str]] = {}
pool_names = []
for p in self._pool_list():
name = p['pool_name']
Expand Down
7 changes: 6 additions & 1 deletion src/pybind/mgr/dashboard/tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ def test_type_to_str(self):
self.assertEqual(Docs()._type_to_str(str), "string")

def test_gen_paths(self):
outcome = Docs()._gen_paths(False, "")['/api/doctest//decorated_func/{parameter}']['get']
outcome = Docs()._gen_paths(False)['/api/doctest//decorated_func/{parameter}']['get']
self.assertIn('tags', outcome)
self.assertIn('summary', outcome)
self.assertIn('parameters', outcome)
self.assertIn('responses', outcome)

def test_gen_paths_all(self):
paths = Docs()._gen_paths(False)
for key in paths:
self.assertTrue(any(base in key.split('/')[1] for base in ['api', 'ui-api']))

def test_gen_tags(self):
outcome = Docs()._gen_tags(False)[0]
self.assertEqual({'description': 'Group description', 'name': 'FooGroup'}, outcome)

0 comments on commit 44908df

Please sign in to comment.