From 2130934db8652037a49350dc5c5281f130b0840a Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Tue, 5 Jul 2022 13:22:42 +0200 Subject: [PATCH] mgr/dashboard: cleanups Signed-off-by: Pere Diaz Bou (cherry picked from commit 23615b3e1b0d479595929d6483856afce67502d2) (cherry picked from commit c685773a691afe25666166af28fc250b285b6e1b) Resolves: rhbz#2125432 --- src/pybind/mgr/dashboard/controllers/rbd.py | 6 ++++-- src/pybind/mgr/dashboard/services/rbd.py | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index ac49d077c7ae4..58a7ab7710dd8 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -79,7 +79,9 @@ class Rbd(RESTController): ALLOW_DISABLE_FEATURES = {"exclusive-lock", "object-map", "fast-diff", "deep-flatten", "journaling"} - def _rbd_list(self, pool_name=None, offset=0, limit=5, search='', sort=''): + DEFAULT_LIMIT = 5 + + def _rbd_list(self, pool_name=None, offset=0, limit=DEFAULT_LIMIT, search='', sort=''): if pool_name: pools = [pool_name] else: @@ -109,7 +111,7 @@ class Rbd(RESTController): }, responses={200: RBD_SCHEMA}) @RESTController.MethodMap(version=APIVersion(2, 0)) # type: ignore - def list(self, pool_name=None, offset: int = 0, limit: int = 5, + def list(self, pool_name=None, offset: int = 0, limit: int = DEFAULT_LIMIT, search: str = '', sort: str = ''): return self._rbd_list(pool_name, offset=offset, limit=limit, search=search, sort=sort) diff --git a/src/pybind/mgr/dashboard/services/rbd.py b/src/pybind/mgr/dashboard/services/rbd.py index 7d8ea04d1e46c..2384d42e9bc25 100644 --- a/src/pybind/mgr/dashboard/services/rbd.py +++ b/src/pybind/mgr/dashboard/services/rbd.py @@ -13,7 +13,7 @@ from ..plugins.ttl_cache import ttl_cache from .ceph_service import CephService try: - from typing import List + from typing import List, Optional except ImportError: pass # For typing only @@ -409,7 +409,7 @@ class RbdService(object): errno=errno.ENOENT) @classmethod - def _rbd_pool_image_refs(cls, pool_names: List[str], namespace=None): + def _rbd_pool_image_refs(cls, pool_names: List[str], namespace: Optional[str] = None): joint_refs = [] rbd_inst = rbd.RBD() for pool in pool_names: @@ -430,14 +430,14 @@ class RbdService(object): return joint_refs @classmethod - def rbd_pool_list(cls, pool_names: List[str], namespace=None, offset=0, limit=0, - search='', sort=''): + def rbd_pool_list(cls, pool_names: List[str], namespace: Optional[str] = None, offset: int = 0, + limit: int = 5, search: str = '', sort: str = ''): offset = int(offset) limit = int(limit) # let's use -1 to denotate we want ALL images for now. Iscsi currently gathers # all images therefore, we need this. if limit < -1: - return [] + raise DashboardException(msg=f'Wrong limit value {limit}', code=400) refs = cls._rbd_pool_image_refs(pool_names, namespace) image_refs = [] -- 2.39.5