From 0c3f9480a5673ab6eb3a0e60b0fae9665dbfe700 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Wed, 30 Sep 2020 16:14:10 +0200 Subject: [PATCH] mgr/dashboard: Add isort to rearrange imports * Add 'isort' tox environment. * Apply 'isort' fixes. Signed-off-by: Volker Theile --- src/pybind/mgr/dashboard/__init__.py | 1 + src/pybind/mgr/dashboard/awsauth.py | 13 ++++--- .../mgr/dashboard/cherrypy_backports.py | 4 +-- .../mgr/dashboard/ci/check_grafana_uids.py | 1 - .../mgr/dashboard/controllers/__init__.py | 9 +++-- src/pybind/mgr/dashboard/controllers/auth.py | 6 ++-- .../mgr/dashboard/controllers/cephfs.py | 11 +++--- .../controllers/cluster_configuration.py | 5 ++- .../mgr/dashboard/controllers/crush_rule.py | 7 ++-- src/pybind/mgr/dashboard/controllers/docs.py | 8 +++-- .../controllers/erasure_code_profile.py | 6 ++-- .../dashboard/controllers/frontend_logging.py | 3 +- .../mgr/dashboard/controllers/grafana.py | 6 ++-- .../mgr/dashboard/controllers/health.py | 3 +- src/pybind/mgr/dashboard/controllers/home.py | 9 ++--- src/pybind/mgr/dashboard/controllers/host.py | 14 ++++---- src/pybind/mgr/dashboard/controllers/iscsi.py | 17 ++++----- src/pybind/mgr/dashboard/controllers/logs.py | 3 +- .../mgr/dashboard/controllers/mgr_modules.py | 3 +- .../mgr/dashboard/controllers/monitor.py | 2 +- .../mgr/dashboard/controllers/nfsganesha.py | 9 +++-- .../mgr/dashboard/controllers/orchestrator.py | 6 ++-- src/pybind/mgr/dashboard/controllers/osd.py | 15 ++++---- .../dashboard/controllers/perf_counters.py | 2 +- src/pybind/mgr/dashboard/controllers/pool.py | 11 +++--- .../mgr/dashboard/controllers/prometheus.py | 7 ++-- src/pybind/mgr/dashboard/controllers/rbd.py | 13 +++---- .../dashboard/controllers/rbd_mirroring.py | 13 +++---- src/pybind/mgr/dashboard/controllers/rgw.py | 9 ++--- src/pybind/mgr/dashboard/controllers/role.py | 11 +++--- src/pybind/mgr/dashboard/controllers/saml2.py | 2 +- .../mgr/dashboard/controllers/service.py | 13 +++---- .../mgr/dashboard/controllers/settings.py | 6 ++-- .../mgr/dashboard/controllers/summary.py | 6 ++-- src/pybind/mgr/dashboard/controllers/task.py | 4 +-- .../mgr/dashboard/controllers/telemetry.py | 2 +- src/pybind/mgr/dashboard/controllers/user.py | 11 +++--- src/pybind/mgr/dashboard/grafana.py | 2 +- src/pybind/mgr/dashboard/module.py | 36 +++++++++---------- src/pybind/mgr/dashboard/plugins/__init__.py | 2 +- src/pybind/mgr/dashboard/plugins/debug.py | 2 +- .../mgr/dashboard/plugins/feature_toggles.py | 23 ++++++------ .../mgr/dashboard/plugins/interfaces.py | 3 +- src/pybind/mgr/dashboard/plugins/lru_cache.py | 2 +- src/pybind/mgr/dashboard/plugins/pluggy.py | 2 ++ src/pybind/mgr/dashboard/plugins/plugin.py | 2 +- src/pybind/mgr/dashboard/plugins/ttl_cache.py | 2 +- .../mgr/dashboard/requirements-lint.txt | 3 +- src/pybind/mgr/dashboard/rest_client.py | 3 ++ .../mgr/dashboard/services/access_control.py | 28 +++++++-------- src/pybind/mgr/dashboard/services/auth.py | 6 ++-- .../mgr/dashboard/services/ceph_service.py | 6 ++-- src/pybind/mgr/dashboard/services/cephfs.py | 7 ++-- .../mgr/dashboard/services/exception.py | 10 +++--- src/pybind/mgr/dashboard/services/ganesha.py | 10 +++--- .../mgr/dashboard/services/iscsi_cli.py | 7 ++-- .../mgr/dashboard/services/iscsi_client.py | 5 ++- .../mgr/dashboard/services/iscsi_config.py | 2 +- .../mgr/dashboard/services/orchestrator.py | 12 +++---- src/pybind/mgr/dashboard/services/progress.py | 5 ++- src/pybind/mgr/dashboard/services/rbd.py | 1 - .../mgr/dashboard/services/rgw_client.py | 16 ++++----- src/pybind/mgr/dashboard/services/sso.py | 8 ++--- .../mgr/dashboard/services/tcmu_service.py | 3 +- src/pybind/mgr/dashboard/settings.py | 2 +- src/pybind/mgr/dashboard/tests/__init__.py | 10 ++---- src/pybind/mgr/dashboard/tests/helper.py | 2 +- .../dashboard/tests/test_access_control.py | 10 +++--- .../mgr/dashboard/tests/test_api_auditing.py | 10 +++--- .../mgr/dashboard/tests/test_ceph_service.py | 1 + src/pybind/mgr/dashboard/tests/test_cephfs.py | 3 +- .../mgr/dashboard/tests/test_controllers.py | 3 +- src/pybind/mgr/dashboard/tests/test_docs.py | 4 +-- .../tests/test_erasure_code_profile.py | 2 +- .../mgr/dashboard/tests/test_exceptions.py | 10 +++--- .../dashboard/tests/test_feature_toggles.py | 3 +- .../mgr/dashboard/tests/test_ganesha.py | 7 ++-- .../mgr/dashboard/tests/test_grafana.py | 2 +- src/pybind/mgr/dashboard/tests/test_home.py | 3 +- src/pybind/mgr/dashboard/tests/test_host.py | 4 +-- src/pybind/mgr/dashboard/tests/test_iscsi.py | 10 +++--- .../mgr/dashboard/tests/test_notification.py | 1 - .../mgr/dashboard/tests/test_orchestrator.py | 7 ++-- src/pybind/mgr/dashboard/tests/test_osd.py | 9 +++-- src/pybind/mgr/dashboard/tests/test_pool.py | 3 +- .../mgr/dashboard/tests/test_prometheus.py | 4 +-- .../mgr/dashboard/tests/test_rbd_mirroring.py | 9 +++-- .../mgr/dashboard/tests/test_rbd_service.py | 3 +- .../mgr/dashboard/tests/test_rest_client.py | 2 ++ .../mgr/dashboard/tests/test_rest_tasks.py | 2 +- src/pybind/mgr/dashboard/tests/test_rgw.py | 2 +- .../mgr/dashboard/tests/test_settings.py | 3 +- src/pybind/mgr/dashboard/tests/test_sso.py | 5 +-- src/pybind/mgr/dashboard/tests/test_task.py | 4 +-- src/pybind/mgr/dashboard/tests/test_tools.py | 10 +++--- src/pybind/mgr/dashboard/tools.py | 17 ++++----- src/pybind/mgr/dashboard/tox.ini | 9 ++++- 97 files changed, 324 insertions(+), 331 deletions(-) diff --git a/src/pybind/mgr/dashboard/__init__.py b/src/pybind/mgr/dashboard/__init__.py index b05da375c8a..feefda94816 100644 --- a/src/pybind/mgr/dashboard/__init__.py +++ b/src/pybind/mgr/dashboard/__init__.py @@ -6,6 +6,7 @@ ceph dashboard module from __future__ import absolute_import import os + import cherrypy if 'COVERAGE_ENABLED' in os.environ: diff --git a/src/pybind/mgr/dashboard/awsauth.py b/src/pybind/mgr/dashboard/awsauth.py index 5cbb6f297d7..911052e4c91 100644 --- a/src/pybind/mgr/dashboard/awsauth.py +++ b/src/pybind/mgr/dashboard/awsauth.py @@ -32,21 +32,20 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hmac - +from email.utils import formatdate from hashlib import sha1 as sha +from requests.auth import AuthBase + py3k = False try: - from urlparse import urlparse, unquote from base64 import encodestring + + from urlparse import unquote, urlparse except ImportError: py3k = True - from urllib.parse import urlparse, unquote from base64 import encodebytes as encodestring - -from email.utils import formatdate - -from requests.auth import AuthBase + from urllib.parse import unquote, urlparse class S3Auth(AuthBase): diff --git a/src/pybind/mgr/dashboard/cherrypy_backports.py b/src/pybind/mgr/dashboard/cherrypy_backports.py index 94c44fe13d4..4d2a2cb05c3 100644 --- a/src/pybind/mgr/dashboard/cherrypy_backports.py +++ b/src/pybind/mgr/dashboard/cherrypy_backports.py @@ -43,8 +43,7 @@ def patch_http_connection_init(v): # It was fixed in 3.7.0. Exact lower bound version is probably earlier, # but 3.5.0 is what this monkey patch is tested on. if StrictVersion("3.5.0") <= v < StrictVersion("3.7.0"): - from cherrypy.wsgiserver.wsgiserver2 import \ - HTTPConnection, CP_fileobject + from cherrypy.wsgiserver.wsgiserver2 import CP_fileobject, HTTPConnection def fixed_init(hc_self, server, sock, makefile=CP_fileobject): hc_self.server = server @@ -156,6 +155,7 @@ def patch_request_unique_id(v): if v < StrictVersion('11.1.0'): import uuid from functools import update_wrapper + from cherrypy._cprequest import Request class LazyUUID4(object): diff --git a/src/pybind/mgr/dashboard/ci/check_grafana_uids.py b/src/pybind/mgr/dashboard/ci/check_grafana_uids.py index ab27ab66399..f82ddbbc8ba 100644 --- a/src/pybind/mgr/dashboard/ci/check_grafana_uids.py +++ b/src/pybind/mgr/dashboard/ci/check_grafana_uids.py @@ -17,7 +17,6 @@ import codecs import copy import json import os - from html.parser import HTMLParser diff --git a/src/pybind/mgr/dashboard/controllers/__init__.py b/src/pybind/mgr/dashboard/controllers/__init__.py index 6a45c2f9c9c..b77ea759eb4 100644 --- a/src/pybind/mgr/dashboard/controllers/__init__.py +++ b/src/pybind/mgr/dashboard/controllers/__init__.py @@ -12,17 +12,16 @@ import pkgutil import re import sys import urllib - from functools import wraps # pylint: disable=wrong-import-position import cherrypy -from ..security import Scope, Permission -from ..tools import getargspec, TaskManager, get_request_body_params -from ..exceptions import ScopeNotValid, PermissionNotValid -from ..services.auth import AuthManager, JwtManager +from ..exceptions import PermissionNotValid, ScopeNotValid from ..plugins import PLUGIN_MANAGER +from ..security import Permission, Scope +from ..services.auth import AuthManager, JwtManager +from ..tools import TaskManager, get_request_body_params, getargspec try: from typing import Any, List, Optional diff --git a/src/pybind/mgr/dashboard/controllers/auth.py b/src/pybind/mgr/dashboard/controllers/auth.py index ee638a61718..7ce5f3ff107 100644 --- a/src/pybind/mgr/dashboard/controllers/auth.py +++ b/src/pybind/mgr/dashboard/controllers/auth.py @@ -2,14 +2,13 @@ from __future__ import absolute_import import logging + import cherrypy -from . import ApiController, RESTController, \ - allow_empty_body, ControllerDoc, EndpointDoc from .. import mgr from ..exceptions import DashboardException from ..services.auth import AuthManager, JwtManager - +from . import ApiController, ControllerDoc, EndpointDoc, RESTController, allow_empty_body logger = logging.getLogger('controllers.auth') @@ -29,6 +28,7 @@ class Auth(RESTController): """ Provide authenticates and returns JWT token. """ + def create(self, username, password): user_data = AuthManager.authenticate(username, password) user_perms, pwd_expiration_date, pwd_update_required = None, None, None diff --git a/src/pybind/mgr/dashboard/controllers/cephfs.py b/src/pybind/mgr/dashboard/controllers/cephfs.py index 272feda0b82..842d911fa8b 100644 --- a/src/pybind/mgr/dashboard/controllers/cephfs.py +++ b/src/pybind/mgr/dashboard/controllers/cephfs.py @@ -1,19 +1,18 @@ # -*- coding: utf-8 -*- -from collections import defaultdict - import os +from collections import defaultdict -import cherrypy import cephfs +import cherrypy -from . import ApiController, ControllerDoc, RESTController, UiApiController, \ - allow_empty_body, EndpointDoc from .. import mgr from ..exceptions import DashboardException from ..security import Scope -from ..services.cephfs import CephFS as CephFS_ from ..services.ceph_service import CephService +from ..services.cephfs import CephFS as CephFS_ from ..tools import ViewCache +from . import ApiController, ControllerDoc, EndpointDoc, RESTController, \ + UiApiController, allow_empty_body GET_QUOTAS_SCHEMA = { 'max_bytes': (int, ''), diff --git a/src/pybind/mgr/dashboard/controllers/cluster_configuration.py b/src/pybind/mgr/dashboard/controllers/cluster_configuration.py index 382e18eb01a..e57ce48c4f5 100644 --- a/src/pybind/mgr/dashboard/controllers/cluster_configuration.py +++ b/src/pybind/mgr/dashboard/controllers/cluster_configuration.py @@ -3,12 +3,11 @@ from __future__ import absolute_import import cherrypy -from . import ApiController, RESTController, ControllerDoc, EndpointDoc from .. import mgr +from ..exceptions import DashboardException from ..security import Scope from ..services.ceph_service import CephService -from ..exceptions import DashboardException - +from . import ApiController, ControllerDoc, EndpointDoc, RESTController FILTER_SCHEMA = [{ "name": (str, 'Name of the config option'), diff --git a/src/pybind/mgr/dashboard/controllers/crush_rule.py b/src/pybind/mgr/dashboard/controllers/crush_rule.py index fe62f090f61..ea5096cca0f 100644 --- a/src/pybind/mgr/dashboard/controllers/crush_rule.py +++ b/src/pybind/mgr/dashboard/controllers/crush_rule.py @@ -3,12 +3,11 @@ from __future__ import absolute_import from cherrypy import NotFound -from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, \ - UiApiController, EndpointDoc +from .. import mgr from ..security import Scope from ..services.ceph_service import CephService -from .. import mgr - +from . import ApiController, ControllerDoc, Endpoint, EndpointDoc, \ + ReadPermission, RESTController, UiApiController LIST_SCHEMA = { "rule_id": (int, 'Rule ID'), diff --git a/src/pybind/mgr/dashboard/controllers/docs.py b/src/pybind/mgr/dashboard/controllers/docs.py index 9aaeaa0c1b6..a5371219934 100644 --- a/src/pybind/mgr/dashboard/controllers/docs.py +++ b/src/pybind/mgr/dashboard/controllers/docs.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from typing import Any, Dict, Union import logging +from typing import Any, Dict, Union + import cherrypy -from . import Controller, BaseController, Endpoint, ENDPOINT_MAP, \ - allow_empty_body from .. import mgr +from . import ENDPOINT_MAP, BaseController, Controller, Endpoint, allow_empty_body NO_DESCRIPTION_AVAILABLE = "*No description available*" @@ -456,7 +456,9 @@ class Docs(BaseController): if __name__ == "__main__": import sys + import yaml + from . import generate_routes def fix_null_descr(obj): diff --git a/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py b/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py index e9dc01e7e8a..53b1f14ef5e 100644 --- a/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py +++ b/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py @@ -3,11 +3,11 @@ from __future__ import absolute_import from cherrypy import NotFound -from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, \ - UiApiController, EndpointDoc +from .. import mgr from ..security import Scope from ..services.ceph_service import CephService -from .. import mgr +from . import ApiController, ControllerDoc, Endpoint, EndpointDoc, \ + ReadPermission, RESTController, UiApiController LIST_CODE__SCHEMA = { "crush-failure-domain": (str, ''), diff --git a/src/pybind/mgr/dashboard/controllers/frontend_logging.py b/src/pybind/mgr/dashboard/controllers/frontend_logging.py index 910e39b6ae5..421e36c02e7 100644 --- a/src/pybind/mgr/dashboard/controllers/frontend_logging.py +++ b/src/pybind/mgr/dashboard/controllers/frontend_logging.py @@ -2,8 +2,7 @@ from __future__ import absolute_import import logging -from . import UiApiController, BaseController, Endpoint - +from . import BaseController, Endpoint, UiApiController logger = logging.getLogger('frontend.error') diff --git a/src/pybind/mgr/dashboard/controllers/grafana.py b/src/pybind/mgr/dashboard/controllers/grafana.py index 9639d0260f1..68e6f831798 100644 --- a/src/pybind/mgr/dashboard/controllers/grafana.py +++ b/src/pybind/mgr/dashboard/controllers/grafana.py @@ -1,14 +1,12 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from . import (ApiController, BaseController, Endpoint, ReadPermission, - UpdatePermission) -from . import ControllerDoc, EndpointDoc from ..exceptions import DashboardException from ..grafana import GrafanaRestClient, push_local_dashboards from ..security import Scope from ..settings import Settings - +from . import ApiController, BaseController, ControllerDoc, Endpoint, \ + EndpointDoc, ReadPermission, UpdatePermission URL_SCHEMA = { "instance": (str, "grafana instance") diff --git a/src/pybind/mgr/dashboard/controllers/health.py b/src/pybind/mgr/dashboard/controllers/health.py index b8f91ca8f51..0ae0a5bf08b 100644 --- a/src/pybind/mgr/dashboard/controllers/health.py +++ b/src/pybind/mgr/dashboard/controllers/health.py @@ -3,8 +3,6 @@ from __future__ import absolute_import import json -from . import ApiController, Endpoint, BaseController, ControllerDoc, EndpointDoc - from .. import mgr from ..rest_client import RequestException from ..security import Permission, Scope @@ -12,6 +10,7 @@ from ..services.ceph_service import CephService from ..services.iscsi_cli import IscsiGatewaysConfig from ..services.iscsi_client import IscsiClient from ..tools import partial_dict +from . import ApiController, BaseController, ControllerDoc, Endpoint, EndpointDoc from .host import get_hosts HEALTH_MINIMAL_SCHEMA = ({ diff --git a/src/pybind/mgr/dashboard/controllers/home.py b/src/pybind/mgr/dashboard/controllers/home.py index 6dcac57c872..705d7c456c8 100644 --- a/src/pybind/mgr/dashboard/controllers/home.py +++ b/src/pybind/mgr/dashboard/controllers/home.py @@ -1,20 +1,21 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import os -import re import json import logging +import os +import re + try: from functools import lru_cache except ImportError: from ..plugins.lru_cache import lru_cache + import cherrypy from cherrypy.lib.static import serve_file -from . import Controller, UiApiController, BaseController, Proxy, Endpoint from .. import mgr - +from . import BaseController, Controller, Endpoint, Proxy, UiApiController logger = logging.getLogger("controllers.home") diff --git a/src/pybind/mgr/dashboard/controllers/host.py b/src/pybind/mgr/dashboard/controllers/host.py index 86889ae15f7..abae3284b35 100644 --- a/src/pybind/mgr/dashboard/controllers/host.py +++ b/src/pybind/mgr/dashboard/controllers/host.py @@ -2,22 +2,22 @@ from __future__ import absolute_import import copy - -from typing import List, Dict +from typing import Dict, List import cherrypy - from mgr_util import merge_dicts from orchestrator import HostSpec -from . import ApiController, RESTController, Task, Endpoint, ReadPermission, \ - UiApiController, BaseController, allow_empty_body, ControllerDoc, EndpointDoc -from .orchestrator import raise_if_no_orchestrator + from .. import mgr from ..exceptions import DashboardException from ..security import Scope -from ..services.orchestrator import OrchClient, OrchFeature from ..services.ceph_service import CephService from ..services.exception import handle_orchestrator_error +from ..services.orchestrator import OrchClient, OrchFeature +from . import ApiController, BaseController, ControllerDoc, Endpoint, \ + EndpointDoc, ReadPermission, RESTController, Task, UiApiController, \ + allow_empty_body +from .orchestrator import raise_if_no_orchestrator LIST_HOST_SCHEMA = { "hostname": (str, "Hostname"), diff --git a/src/pybind/mgr/dashboard/controllers/iscsi.py b/src/pybind/mgr/dashboard/controllers/iscsi.py index ce81768072a..687daa91966 100644 --- a/src/pybind/mgr/dashboard/controllers/iscsi.py +++ b/src/pybind/mgr/dashboard/controllers/iscsi.py @@ -4,26 +4,27 @@ # pylint: disable=too-many-lines from __future__ import absolute_import -from copy import deepcopy -import re import json -import cherrypy +import re +from copy import deepcopy +import cherrypy import rados import rbd -from . import ApiController, UiApiController, RESTController, BaseController, Endpoint,\ - ReadPermission, UpdatePermission, Task, ControllerDoc, EndpointDoc from .. import mgr +from ..exceptions import DashboardException from ..rest_client import RequestException from ..security import Scope -from ..services.iscsi_client import IscsiClient from ..services.iscsi_cli import IscsiGatewaysConfig +from ..services.iscsi_client import IscsiClient from ..services.iscsi_config import IscsiGatewayDoesNotExist from ..services.rbd import format_bitmask from ..services.tcmu_service import TcmuService -from ..exceptions import DashboardException -from ..tools import str_to_bool, TaskManager +from ..tools import TaskManager, str_to_bool +from . import ApiController, BaseController, ControllerDoc, Endpoint, \ + EndpointDoc, ReadPermission, RESTController, Task, UiApiController, \ + UpdatePermission try: from typing import Any, Dict, List, no_type_check diff --git a/src/pybind/mgr/dashboard/controllers/logs.py b/src/pybind/mgr/dashboard/controllers/logs.py index 63f7bfdb414..1676f29e020 100644 --- a/src/pybind/mgr/dashboard/controllers/logs.py +++ b/src/pybind/mgr/dashboard/controllers/logs.py @@ -3,11 +3,10 @@ from __future__ import absolute_import import collections -from . import ApiController, Endpoint, BaseController, ReadPermission, ControllerDoc, EndpointDoc from ..security import Scope from ..services.ceph_service import CephService from ..tools import NotificationQueue - +from . import ApiController, BaseController, ControllerDoc, Endpoint, EndpointDoc, ReadPermission LOG_BUFFER_SIZE = 30 diff --git a/src/pybind/mgr/dashboard/controllers/mgr_modules.py b/src/pybind/mgr/dashboard/controllers/mgr_modules.py index da31044f24b..574be466646 100644 --- a/src/pybind/mgr/dashboard/controllers/mgr_modules.py +++ b/src/pybind/mgr/dashboard/controllers/mgr_modules.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from . import ApiController, RESTController, \ - allow_empty_body, ControllerDoc, EndpointDoc from .. import mgr from ..security import Scope from ..services.ceph_service import CephService from ..services.exception import handle_send_command_error from ..tools import find_object_in_list, str_to_bool +from . import ApiController, ControllerDoc, EndpointDoc, RESTController, allow_empty_body MGR_MODULE_SCHEMA = ([{ "name": (str, "Module Name"), diff --git a/src/pybind/mgr/dashboard/controllers/monitor.py b/src/pybind/mgr/dashboard/controllers/monitor.py index 5b5a44fec74..b61fcd4f393 100644 --- a/src/pybind/mgr/dashboard/controllers/monitor.py +++ b/src/pybind/mgr/dashboard/controllers/monitor.py @@ -3,9 +3,9 @@ from __future__ import absolute_import import json -from . import ApiController, Endpoint, BaseController, ReadPermission, ControllerDoc, EndpointDoc from .. import mgr from ..security import Scope +from . import ApiController, BaseController, ControllerDoc, Endpoint, EndpointDoc, ReadPermission MONITOR_SCHEMA = { "mon_status": ({ diff --git a/src/pybind/mgr/dashboard/controllers/nfsganesha.py b/src/pybind/mgr/dashboard/controllers/nfsganesha.py index 16b35e7f271..fae04e5e1b8 100644 --- a/src/pybind/mgr/dashboard/controllers/nfsganesha.py +++ b/src/pybind/mgr/dashboard/controllers/nfsganesha.py @@ -1,21 +1,20 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from functools import partial import logging +from functools import partial -import cherrypy import cephfs +import cherrypy -from . import ApiController, RESTController, UiApiController, BaseController, \ - Endpoint, Task, ReadPermission, ControllerDoc, EndpointDoc from ..security import Scope from ..services.cephfs import CephFS from ..services.cephx import CephX from ..services.exception import serialize_dashboard_exception from ..services.ganesha import Ganesha, GaneshaConf, NFSException from ..services.rgw_client import RgwClient - +from . import ApiController, BaseController, ControllerDoc, Endpoint, \ + EndpointDoc, ReadPermission, RESTController, Task, UiApiController logger = logging.getLogger('controllers.ganesha') diff --git a/src/pybind/mgr/dashboard/controllers/orchestrator.py b/src/pybind/mgr/dashboard/controllers/orchestrator.py index 445fb7235a7..6b2d9bb4c13 100644 --- a/src/pybind/mgr/dashboard/controllers/orchestrator.py +++ b/src/pybind/mgr/dashboard/controllers/orchestrator.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import os.path +import os.path import time from functools import wraps -from . import ApiController, Endpoint, ReadPermission, UpdatePermission, ControllerDoc, EndpointDoc -from . import RESTController, Task from .. import mgr from ..exceptions import DashboardException from ..security import Scope from ..services.exception import handle_orchestrator_error from ..services.orchestrator import OrchClient, OrchFeature from ..tools import TaskManager, str_to_bool +from . import ApiController, ControllerDoc, Endpoint, EndpointDoc, \ + ReadPermission, RESTController, Task, UpdatePermission STATUS_SCHEMA = { "available": (bool, "Orchestrator status"), diff --git a/src/pybind/mgr/dashboard/controllers/osd.py b/src/pybind/mgr/dashboard/controllers/osd.py index a6127da9ebf..91d1126fa40 100644 --- a/src/pybind/mgr/dashboard/controllers/osd.py +++ b/src/pybind/mgr/dashboard/controllers/osd.py @@ -1,26 +1,25 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import + import json import logging import time +from typing import Any, Dict, List, Union from ceph.deployment.drive_group import DriveGroupSpec, DriveGroupValidationError # type: ignore from mgr_util import get_most_recent_rate -from . import ApiController, RESTController, Endpoint, Task -from . import CreatePermission, ReadPermission, UpdatePermission, DeletePermission, \ - allow_empty_body, ControllerDoc, EndpointDoc -from .orchestrator import raise_if_no_orchestrator from .. import mgr from ..exceptions import DashboardException from ..security import Scope from ..services.ceph_service import CephService, SendCommandError -from ..services.exception import handle_send_command_error, handle_orchestrator_error +from ..services.exception import handle_orchestrator_error, handle_send_command_error from ..services.orchestrator import OrchClient, OrchFeature from ..tools import str_to_bool - -from typing import Any, Dict, List, Union # pylint: disable=C0411 - +from . import ApiController, ControllerDoc, CreatePermission, \ + DeletePermission, Endpoint, EndpointDoc, ReadPermission, RESTController, \ + Task, UpdatePermission, allow_empty_body +from .orchestrator import raise_if_no_orchestrator logger = logging.getLogger('controllers.osd') diff --git a/src/pybind/mgr/dashboard/controllers/perf_counters.py b/src/pybind/mgr/dashboard/controllers/perf_counters.py index 30d62358e37..96aa08590ac 100644 --- a/src/pybind/mgr/dashboard/controllers/perf_counters.py +++ b/src/pybind/mgr/dashboard/controllers/perf_counters.py @@ -3,10 +3,10 @@ from __future__ import absolute_import import cherrypy -from . import ApiController, RESTController, EndpointDoc, ControllerDoc from .. import mgr from ..security import Scope from ..services.ceph_service import CephService +from . import ApiController, ControllerDoc, EndpointDoc, RESTController PERF_SCHEMA = { "mon.a": ({ diff --git a/src/pybind/mgr/dashboard/controllers/pool.py b/src/pybind/mgr/dashboard/controllers/pool.py index 8e3294bfbbc..32ec6c198f8 100644 --- a/src/pybind/mgr/dashboard/controllers/pool.py +++ b/src/pybind/mgr/dashboard/controllers/pool.py @@ -1,18 +1,19 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from typing import Any, cast, Dict, Iterable, List, Optional, Union import time +from typing import Any, Dict, Iterable, List, Optional, Union, cast + import cherrypy -from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, Task, \ - UiApiController, EndpointDoc from .. import mgr from ..security import Scope from ..services.ceph_service import CephService -from ..services.rbd import RbdConfiguration from ..services.exception import handle_send_command_error -from ..tools import str_to_bool, TaskManager +from ..services.rbd import RbdConfiguration +from ..tools import TaskManager, str_to_bool +from . import ApiController, ControllerDoc, Endpoint, EndpointDoc, \ + ReadPermission, RESTController, Task, UiApiController POOL_SCHEMA = ([{ "pool": (int, "pool id"), diff --git a/src/pybind/mgr/dashboard/controllers/prometheus.py b/src/pybind/mgr/dashboard/controllers/prometheus.py index c13e6bd64dc..a1e793913ae 100644 --- a/src/pybind/mgr/dashboard/controllers/prometheus.py +++ b/src/pybind/mgr/dashboard/controllers/prometheus.py @@ -1,14 +1,15 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from datetime import datetime import json +from datetime import datetime + import requests -from . import Controller, ApiController, BaseController, RESTController, Endpoint, ControllerDoc +from ..exceptions import DashboardException from ..security import Scope from ..settings import Settings -from ..exceptions import DashboardException +from . import ApiController, BaseController, Controller, ControllerDoc, Endpoint, RESTController @Controller('/api/prometheus_receiver', secure=False) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index 97e1f81fab3..bd72e80bc9b 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -5,22 +5,23 @@ from __future__ import absolute_import import logging import math -from functools import partial from datetime import datetime +from functools import partial import rbd -from . import ApiController, RESTController, Task, UpdatePermission, \ - DeletePermission, CreatePermission, allow_empty_body, ControllerDoc, EndpointDoc from .. import mgr from ..exceptions import DashboardException from ..security import Scope from ..services.ceph_service import CephService +from ..services.exception import handle_rados_error, handle_rbd_error, serialize_dashboard_exception from ..services.rbd import RbdConfiguration, RbdService, RbdSnapshotService, \ - format_bitmask, format_features, parse_image_spec, rbd_call, rbd_image_call + format_bitmask, format_features, parse_image_spec, rbd_call, \ + rbd_image_call from ..tools import ViewCache, str_to_bool -from ..services.exception import handle_rados_error, handle_rbd_error, \ - serialize_dashboard_exception +from . import ApiController, ControllerDoc, CreatePermission, \ + DeletePermission, EndpointDoc, RESTController, Task, UpdatePermission, \ + allow_empty_body logger = logging.getLogger(__name__) diff --git a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py index 8056de489f1..0c41d71375c 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py @@ -2,25 +2,22 @@ from __future__ import absolute_import import json -import re import logging - +import re from functools import partial import cherrypy - import rbd -from . import ApiController, Endpoint, Task, BaseController, ReadPermission, \ - UpdatePermission, RESTController, allow_empty_body, ControllerDoc, EndpointDoc - from .. import mgr from ..security import Scope from ..services.ceph_service import CephService +from ..services.exception import handle_rados_error, handle_rbd_error, serialize_dashboard_exception from ..services.rbd import rbd_call from ..tools import ViewCache -from ..services.exception import handle_rados_error, handle_rbd_error, \ - serialize_dashboard_exception +from . import ApiController, BaseController, ControllerDoc, Endpoint, \ + EndpointDoc, ReadPermission, RESTController, Task, UpdatePermission, \ + allow_empty_body try: from typing import no_type_check diff --git a/src/pybind/mgr/dashboard/controllers/rgw.py b/src/pybind/mgr/dashboard/controllers/rgw.py index d3fcb9163c1..e00a77b3cbf 100644 --- a/src/pybind/mgr/dashboard/controllers/rgw.py +++ b/src/pybind/mgr/dashboard/controllers/rgw.py @@ -1,19 +1,20 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import logging import json +import logging import cherrypy -from . import ApiController, BaseController, RESTController, Endpoint, \ - ReadPermission, allow_empty_body, ControllerDoc, EndpointDoc + from ..exceptions import DashboardException from ..rest_client import RequestException -from ..security import Scope, Permission +from ..security import Permission, Scope from ..services.auth import AuthManager, JwtManager from ..services.ceph_service import CephService from ..services.rgw_client import RgwClient from ..tools import json_str_to_object, str_to_bool +from . import ApiController, BaseController, ControllerDoc, Endpoint, \ + EndpointDoc, ReadPermission, RESTController, allow_empty_body try: from typing import Any, List diff --git a/src/pybind/mgr/dashboard/controllers/role.py b/src/pybind/mgr/dashboard/controllers/role.py index cfa28fa5c41..32404237c4a 100644 --- a/src/pybind/mgr/dashboard/controllers/role.py +++ b/src/pybind/mgr/dashboard/controllers/role.py @@ -3,13 +3,14 @@ from __future__ import absolute_import import cherrypy -from . import ApiController, RESTController, UiApiController,\ - CreatePermission, ControllerDoc, EndpointDoc from .. import mgr -from ..exceptions import RoleDoesNotExist, DashboardException,\ - RoleIsAssociatedWithUser, RoleAlreadyExists -from ..security import Scope as SecurityScope, Permission +from ..exceptions import DashboardException, RoleAlreadyExists, \ + RoleDoesNotExist, RoleIsAssociatedWithUser +from ..security import Permission +from ..security import Scope as SecurityScope from ..services.access_control import SYSTEM_ROLES +from . import ApiController, ControllerDoc, CreatePermission, EndpointDoc, \ + RESTController, UiApiController ROLE_SCHEMA = [{ "name": (str, "Role Name"), diff --git a/src/pybind/mgr/dashboard/controllers/saml2.py b/src/pybind/mgr/dashboard/controllers/saml2.py index 4bafc6933ac..f53c7f0e1f6 100644 --- a/src/pybind/mgr/dashboard/controllers/saml2.py +++ b/src/pybind/mgr/dashboard/controllers/saml2.py @@ -16,7 +16,7 @@ from .. import mgr from ..exceptions import UserDoesNotExist from ..services.auth import JwtManager from ..tools import prepare_url_prefix -from . import Controller, Endpoint, BaseController +from . import BaseController, Controller, Endpoint @Controller('/auth/saml2', secure=False) diff --git a/src/pybind/mgr/dashboard/controllers/service.py b/src/pybind/mgr/dashboard/controllers/service.py index 4ea435f1c8f..b62e7d68a33 100644 --- a/src/pybind/mgr/dashboard/controllers/service.py +++ b/src/pybind/mgr/dashboard/controllers/service.py @@ -1,14 +1,15 @@ -from typing import List, Optional, Dict -import cherrypy +from typing import Dict, List, Optional +import cherrypy from ceph.deployment.service_spec import ServiceSpec -from . import ApiController, ControllerDoc, RESTController, Task, Endpoint, ReadPermission, \ - CreatePermission, DeletePermission -from .orchestrator import raise_if_no_orchestrator + from ..exceptions import DashboardException from ..security import Scope -from ..services.orchestrator import OrchClient, OrchFeature from ..services.exception import handle_orchestrator_error +from ..services.orchestrator import OrchClient, OrchFeature +from . import ApiController, ControllerDoc, CreatePermission, \ + DeletePermission, Endpoint, ReadPermission, RESTController, Task +from .orchestrator import raise_if_no_orchestrator def service_task(name, metadata, wait_for=2.0): diff --git a/src/pybind/mgr/dashboard/controllers/settings.py b/src/pybind/mgr/dashboard/controllers/settings.py index 417a07c7bab..cb16083ff11 100644 --- a/src/pybind/mgr/dashboard/controllers/settings.py +++ b/src/pybind/mgr/dashboard/controllers/settings.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import + from contextlib import contextmanager import cherrypy -from . import ApiController, RESTController, UiApiController, ControllerDoc, EndpointDoc -from ..settings import Settings as SettingsModule, Options from ..security import Scope +from ..settings import Options +from ..settings import Settings as SettingsModule +from . import ApiController, ControllerDoc, EndpointDoc, RESTController, UiApiController SETTINGS_SCHEMA = [{ "name": (str, 'Settings Name'), diff --git a/src/pybind/mgr/dashboard/controllers/summary.py b/src/pybind/mgr/dashboard/controllers/summary.py index 5febf4a6d83..4e240b9770b 100644 --- a/src/pybind/mgr/dashboard/controllers/summary.py +++ b/src/pybind/mgr/dashboard/controllers/summary.py @@ -3,13 +3,13 @@ from __future__ import absolute_import import json -from . import ApiController, Endpoint, BaseController, ControllerDoc, EndpointDoc from .. import mgr -from ..security import Permission, Scope from ..controllers.rbd_mirroring import get_daemons_and_pools from ..exceptions import ViewCacheNoDataException -from ..tools import TaskManager +from ..security import Permission, Scope from ..services import progress +from ..tools import TaskManager +from . import ApiController, BaseController, ControllerDoc, Endpoint, EndpointDoc SUMMARY_SCHEMA = { "health_status": (str, ""), diff --git a/src/pybind/mgr/dashboard/controllers/task.py b/src/pybind/mgr/dashboard/controllers/task.py index 1668f26af37..16c5017822e 100644 --- a/src/pybind/mgr/dashboard/controllers/task.py +++ b/src/pybind/mgr/dashboard/controllers/task.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from . import ApiController, RESTController, ControllerDoc, EndpointDoc -from ..tools import TaskManager from ..services import progress +from ..tools import TaskManager +from . import ApiController, ControllerDoc, EndpointDoc, RESTController TASK_SCHEMA = { "executing_tasks": (str, "ongoing executing tasks"), diff --git a/src/pybind/mgr/dashboard/controllers/telemetry.py b/src/pybind/mgr/dashboard/controllers/telemetry.py index 34c0a30a142..9e3d3e1cbb0 100644 --- a/src/pybind/mgr/dashboard/controllers/telemetry.py +++ b/src/pybind/mgr/dashboard/controllers/telemetry.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from . import ApiController, RESTController, ControllerDoc, EndpointDoc from .. import mgr from ..exceptions import DashboardException from ..security import Scope +from . import ApiController, ControllerDoc, EndpointDoc, RESTController REPORT_SCHEMA = { "report": ({ diff --git a/src/pybind/mgr/dashboard/controllers/user.py b/src/pybind/mgr/dashboard/controllers/user.py index bba47a8c4d3..4bdea87266e 100644 --- a/src/pybind/mgr/dashboard/controllers/user.py +++ b/src/pybind/mgr/dashboard/controllers/user.py @@ -1,20 +1,19 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from datetime import datetime - import time +from datetime import datetime import cherrypy -from . import BaseController, ApiController, RESTController, Endpoint, \ - allow_empty_body, ControllerDoc, EndpointDoc from .. import mgr -from ..exceptions import DashboardException, UserAlreadyExists, \ - UserDoesNotExist, PasswordPolicyException, PwdExpirationDateNotValid +from ..exceptions import DashboardException, PasswordPolicyException, \ + PwdExpirationDateNotValid, UserAlreadyExists, UserDoesNotExist from ..security import Scope from ..services.access_control import SYSTEM_ROLES, PasswordPolicy from ..services.auth import JwtManager +from . import ApiController, BaseController, ControllerDoc, Endpoint, \ + EndpointDoc, RESTController, allow_empty_body USER_SCHEMA = ([{ "username": (str, 'Username of the user'), diff --git a/src/pybind/mgr/dashboard/grafana.py b/src/pybind/mgr/dashboard/grafana.py index 163df1942e0..2ba28fbeb6f 100644 --- a/src/pybind/mgr/dashboard/grafana.py +++ b/src/pybind/mgr/dashboard/grafana.py @@ -5,12 +5,12 @@ import json import logging import os import time + import requests from .exceptions import GrafanaError from .settings import Settings - logger = logging.getLogger('grafana') diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index eb1b30f7bf1..030ecb68b94 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -13,9 +13,19 @@ import tempfile import threading import time -from mgr_module import MgrModule, MgrStandbyModule, Option, CLIWriteCommand -from mgr_util import get_default_addr, ServerConfigException, verify_tls_files, \ - create_self_signed_cert +from mgr_module import CLIWriteCommand, MgrModule, MgrStandbyModule, Option +from mgr_util import ServerConfigException, create_self_signed_cert, \ + get_default_addr, verify_tls_files + +from . import mgr +from .controllers import generate_routes, json_error_page +from .grafana import push_local_dashboards +from .services.auth import AuthManager, AuthManagerTool, JwtManager +from .services.exception import dashboard_exception_handler +from .services.sso import SSO_COMMANDS, handle_sso_command +from .settings import handle_option_command, options_command_list, options_schema_list +from .tools import NotificationQueue, RequestLoggingTool, TaskManager, \ + prepare_url_prefix, str_to_bool try: import cherrypy @@ -31,21 +41,7 @@ if cherrypy is not None: patch_cherrypy(cherrypy.__version__) # pylint: disable=wrong-import-position -from . import mgr -from .controllers import generate_routes, json_error_page -from .grafana import push_local_dashboards -from .tools import NotificationQueue, RequestLoggingTool, TaskManager, \ - prepare_url_prefix, str_to_bool -from .services.auth import AuthManager, AuthManagerTool, JwtManager -from .services.sso import SSO_COMMANDS, \ - handle_sso_command -from .services.exception import dashboard_exception_handler -from .settings import options_command_list, options_schema_list, \ - handle_option_command - -from .plugins import PLUGIN_MANAGER -from .plugins import feature_toggles, debug # noqa # pylint: disable=unused-import - +from .plugins import PLUGIN_MANAGER, debug, feature_toggles # noqa # pylint: disable=unused-import PLUGIN_MANAGER.hook.init() @@ -355,7 +351,7 @@ class Module(MgrModule, CherryPyConfig): def set_ssl_certificate(self, mgr_id=None, inbuf=None): if inbuf is None: return -errno.EINVAL, '',\ - 'Please specify the certificate file with "-i" option' + 'Please specify the certificate file with "-i" option' if mgr_id is not None: self.set_store('{}/crt'.format(mgr_id), inbuf) else: @@ -367,7 +363,7 @@ class Module(MgrModule, CherryPyConfig): def set_ssl_certificate_key(self, mgr_id=None, inbuf=None): if inbuf is None: return -errno.EINVAL, '',\ - 'Please specify the certificate key file with "-i" option' + 'Please specify the certificate key file with "-i" option' if mgr_id is not None: self.set_store('{}/key'.format(mgr_id), inbuf) else: diff --git a/src/pybind/mgr/dashboard/plugins/__init__.py b/src/pybind/mgr/dashboard/plugins/__init__.py index b8ce811512d..6cd03fa9538 100644 --- a/src/pybind/mgr/dashboard/plugins/__init__.py +++ b/src/pybind/mgr/dashboard/plugins/__init__.py @@ -3,7 +3,7 @@ from __future__ import absolute_import import abc -from .pluggy import HookspecMarker, HookimplMarker, PluginManager +from .pluggy import HookimplMarker, HookspecMarker, PluginManager class Interface(object, metaclass=abc.ABCMeta): diff --git a/src/pybind/mgr/dashboard/plugins/debug.py b/src/pybind/mgr/dashboard/plugins/debug.py index d5719157bc4..bc386cc4451 100644 --- a/src/pybind/mgr/dashboard/plugins/debug.py +++ b/src/pybind/mgr/dashboard/plugins/debug.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from enum import Enum import json +from enum import Enum from . import PLUGIN_MANAGER as PM from . import interfaces as I # noqa: E741,N812 diff --git a/src/pybind/mgr/dashboard/plugins/feature_toggles.py b/src/pybind/mgr/dashboard/plugins/feature_toggles.py index f72afc58c13..97227ca65bd 100644 --- a/src/pybind/mgr/dashboard/plugins/feature_toggles.py +++ b/src/pybind/mgr/dashboard/plugins/feature_toggles.py @@ -2,22 +2,23 @@ from __future__ import absolute_import from enum import Enum + import cherrypy from mgr_module import CLICommand, Option + +from ..controllers.cephfs import CephFS +from ..controllers.iscsi import Iscsi, IscsiTarget +from ..controllers.nfsganesha import NFSGanesha, NFSGaneshaExports, NFSGaneshaService +from ..controllers.rbd import Rbd, RbdSnapshot, RbdTrash +from ..controllers.rbd_mirroring import RbdMirroringPoolMode, \ + RbdMirroringPoolPeer, RbdMirroringSummary +from ..controllers.rgw import Rgw, RgwBucket, RgwDaemon, RgwUser from . import PLUGIN_MANAGER as PM from . import interfaces as I # noqa: E741,N812 from .ttl_cache import ttl_cache -from ..controllers.rbd import Rbd, RbdSnapshot, RbdTrash -from ..controllers.rbd_mirroring import ( - RbdMirroringSummary, RbdMirroringPoolMode, RbdMirroringPoolPeer) -from ..controllers.iscsi import Iscsi, IscsiTarget -from ..controllers.cephfs import CephFS -from ..controllers.rgw import Rgw, RgwDaemon, RgwBucket, RgwUser -from ..controllers.nfsganesha import NFSGanesha, NFSGaneshaService, NFSGaneshaExports - try: - from typing import no_type_check, Set + from typing import Set, no_type_check except ImportError: no_type_check = object() # Just for type checking @@ -132,12 +133,12 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions, 404, "Feature='{}' disabled by option '{}'".format( feature.value, self.OPTION_FMT.format(feature.value), - ) ) + ) @PM.add_hook def get_controllers(self): - from ..controllers import ApiController, RESTController, ControllerDoc, EndpointDoc + from ..controllers import ApiController, ControllerDoc, EndpointDoc, RESTController FEATURES_SCHEMA = { "rbd": (bool, ''), diff --git a/src/pybind/mgr/dashboard/plugins/interfaces.py b/src/pybind/mgr/dashboard/plugins/interfaces.py index f9169a0d89a..f2693eb82e0 100644 --- a/src/pybind/mgr/dashboard/plugins/interfaces.py +++ b/src/pybind/mgr/dashboard/plugins/interfaces.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from . import PLUGIN_MANAGER as PM, Interface, Mixin # pylint: disable=cyclic-import +from . import PLUGIN_MANAGER as PM # pylint: disable=cyclic-import +from . import Interface, Mixin class CanMgr(Mixin): diff --git a/src/pybind/mgr/dashboard/plugins/lru_cache.py b/src/pybind/mgr/dashboard/plugins/lru_cache.py index f5f300171c2..9b29a601244 100644 --- a/src/pybind/mgr/dashboard/plugins/lru_cache.py +++ b/src/pybind/mgr/dashboard/plugins/lru_cache.py @@ -6,8 +6,8 @@ Based on Python 3 functools and backports.functools_lru_cache. """ from __future__ import absolute_import -from functools import wraps from collections import OrderedDict +from functools import wraps from threading import RLock diff --git a/src/pybind/mgr/dashboard/plugins/pluggy.py b/src/pybind/mgr/dashboard/plugins/pluggy.py index 0a1765f1f7f..53a0cf65dcc 100644 --- a/src/pybind/mgr/dashboard/plugins/pluggy.py +++ b/src/pybind/mgr/dashboard/plugins/pluggy.py @@ -48,6 +48,7 @@ except ImportError: class HookspecMarker(object): """ Dummy implementation. No spec validation. """ + def __init__(self, project_name): self.project_name = project_name @@ -77,6 +78,7 @@ class _HookRelay(object): Provides the PluginManager.hook.() syntax and functionality. """ + def __init__(self): from collections import defaultdict self._registry = defaultdict(list) # type: DefaultDict[str, list] diff --git a/src/pybind/mgr/dashboard/plugins/plugin.py b/src/pybind/mgr/dashboard/plugins/plugin.py index ad8342a20d7..847a6187267 100644 --- a/src/pybind/mgr/dashboard/plugins/plugin.py +++ b/src/pybind/mgr/dashboard/plugins/plugin.py @@ -1,4 +1,4 @@ -from mgr_module import Option, Command +from mgr_module import Command, Option from . import PLUGIN_MANAGER as PM from . import interfaces as I # noqa: E741,N812 diff --git a/src/pybind/mgr/dashboard/plugins/ttl_cache.py b/src/pybind/mgr/dashboard/plugins/ttl_cache.py index 4f4f244d2d7..b316151e7e0 100644 --- a/src/pybind/mgr/dashboard/plugins/ttl_cache.py +++ b/src/pybind/mgr/dashboard/plugins/ttl_cache.py @@ -5,8 +5,8 @@ Based on Python 3 functools and backports.functools_lru_cache. """ from __future__ import absolute_import -from functools import wraps from collections import OrderedDict +from functools import wraps from threading import RLock from time import time diff --git a/src/pybind/mgr/dashboard/requirements-lint.txt b/src/pybind/mgr/dashboard/requirements-lint.txt index f01fa54e6eb..a23951620f8 100644 --- a/src/pybind/mgr/dashboard/requirements-lint.txt +++ b/src/pybind/mgr/dashboard/requirements-lint.txt @@ -3,9 +3,8 @@ flake8==3.7.8; python_version >= '3' flake8-colors==0.1.6; python_version >= '3' #TODO: Fix docstring issues: https://tracker.ceph.com/issues/41224 #flake8-docstrings -#flake8-import-order -#flake8-typing-imports; python_version >= '3' #pep8-naming rstcheck==3.3.1; python_version >= '3' autopep8; python_version >= '3' pyfakefs; python_version >= '3' +isort==5.5.3 diff --git a/src/pybind/mgr/dashboard/rest_client.py b/src/pybind/mgr/dashboard/rest_client.py index 7c04f36a0d7..4550c092e8a 100644 --- a/src/pybind/mgr/dashboard/rest_client.py +++ b/src/pybind/mgr/dashboard/rest_client.py @@ -16,8 +16,10 @@ from __future__ import absolute_import import inspect import logging import re + import requests from requests.exceptions import ConnectionError, InvalidURL, Timeout + from .settings import Settings from .tools import build_url @@ -39,6 +41,7 @@ class TimeoutRequestsSession(requests.Session): """ Set timeout argument for all requests if this is not already done. """ + def request(self, *args, **kwargs): if ((args[8] if len(args) > 8 else None) is None) \ and kwargs.get('timeout') is None: diff --git a/src/pybind/mgr/dashboard/services/access_control.py b/src/pybind/mgr/dashboard/services/access_control.py index e55c1455ccd..a4fcd377885 100644 --- a/src/pybind/mgr/dashboard/services/access_control.py +++ b/src/pybind/mgr/dashboard/services/access_control.py @@ -3,29 +3,25 @@ # pylint: disable=too-many-branches, too-many-locals, too-many-statements from __future__ import absolute_import -from string import punctuation, ascii_lowercase, digits, ascii_uppercase - import errno import json import logging +import re import threading import time -import re - from datetime import datetime, timedelta +from string import ascii_lowercase, ascii_uppercase, digits, punctuation import bcrypt - from mgr_module import CLIReadCommand, CLIWriteCommand from .. import mgr -from ..security import Scope, Permission +from ..exceptions import PasswordPolicyException, PermissionNotValid, \ + PwdExpirationDateNotValid, RoleAlreadyExists, RoleDoesNotExist, \ + RoleIsAssociatedWithUser, RoleNotInUser, ScopeNotInRole, ScopeNotValid, \ + UserAlreadyExists, UserDoesNotExist +from ..security import Permission, Scope from ..settings import Settings -from ..exceptions import RoleAlreadyExists, RoleDoesNotExist, ScopeNotValid, \ - PermissionNotValid, RoleIsAssociatedWithUser, \ - UserAlreadyExists, UserDoesNotExist, ScopeNotInRole, \ - RoleNotInUser, PasswordPolicyException, PwdExpirationDateNotValid - logger = logging.getLogger('access_control') @@ -628,7 +624,7 @@ def ac_role_delete_cmd(_, rolename): except RoleDoesNotExist as ex: if rolename in SYSTEM_ROLES: return -errno.EPERM, '', "Cannot delete system role '{}'" \ - .format(rolename) + .format(rolename) return -errno.ENOENT, '', str(ex) except RoleIsAssociatedWithUser as ex: return -errno.EPERM, '', str(ex) @@ -650,15 +646,15 @@ def ac_role_add_scope_perms_cmd(_, rolename, scopename, permissions): except RoleDoesNotExist as ex: if rolename in SYSTEM_ROLES: return -errno.EPERM, '', "Cannot update system role '{}'" \ - .format(rolename) + .format(rolename) return -errno.ENOENT, '', str(ex) except ScopeNotValid as ex: return -errno.EINVAL, '', str(ex) + "\n Possible values: {}" \ .format(Scope.all_scopes()) except PermissionNotValid as ex: return -errno.EINVAL, '', str(ex) + \ - "\n Possible values: {}" \ - .format(Permission.all_permissions()) + "\n Possible values: {}" \ + .format(Permission.all_permissions()) @CLIWriteCommand('dashboard ac-role-del-scope-perms', @@ -675,7 +671,7 @@ def ac_role_del_scope_perms_cmd(_, rolename, scopename): except RoleDoesNotExist as ex: if rolename in SYSTEM_ROLES: return -errno.EPERM, '', "Cannot update system role '{}'" \ - .format(rolename) + .format(rolename) return -errno.ENOENT, '', str(ex) except ScopeNotInRole as ex: return -errno.ENOENT, '', str(ex) diff --git a/src/pybind/mgr/dashboard/services/auth.py b/src/pybind/mgr/dashboard/services/auth.py index d553a01abfa..610484b0e07 100644 --- a/src/pybind/mgr/dashboard/services/auth.py +++ b/src/pybind/mgr/dashboard/services/auth.py @@ -1,23 +1,23 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from base64 import b64encode import json import logging import os import threading import time import uuid +from base64 import b64encode import cherrypy import jwt -from .access_control import LocalAuthenticator, UserDoesNotExist from .. import mgr +from .access_control import LocalAuthenticator, UserDoesNotExist cherrypy.config.update({ 'response.headers.server': 'Ceph-Dashboard' - }) +}) class JwtManager(object): diff --git a/src/pybind/mgr/dashboard/services/ceph_service.py b/src/pybind/mgr/dashboard/services/ceph_service.py index 89582e3f739..2661f9a4b53 100644 --- a/src/pybind/mgr/dashboard/services/ceph_service.py +++ b/src/pybind/mgr/dashboard/services/ceph_service.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import + import json import logging import rados - from mgr_module import CommandResult -from mgr_util import get_time_series_rates, get_most_recent_rate +from mgr_util import get_most_recent_rate, get_time_series_rates from .. import mgr from ..exceptions import DashboardException try: - from typing import Dict, Any, Union + from typing import Any, Dict, Union except ImportError: pass # For typing only diff --git a/src/pybind/mgr/dashboard/services/cephfs.py b/src/pybind/mgr/dashboard/services/cephfs.py index a9d9cb50936..604cf4a77fc 100644 --- a/src/pybind/mgr/dashboard/services/cephfs.py +++ b/src/pybind/mgr/dashboard/services/cephfs.py @@ -1,16 +1,15 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from contextlib import contextmanager -import logging - import datetime +import logging import os +from contextlib import contextmanager + import cephfs from .. import mgr - logger = logging.getLogger('cephfs') diff --git a/src/pybind/mgr/dashboard/services/exception.py b/src/pybind/mgr/dashboard/services/exception.py index 089491aec31..feb084622bc 100644 --- a/src/pybind/mgr/dashboard/services/exception.py +++ b/src/pybind/mgr/dashboard/services/exception.py @@ -2,18 +2,16 @@ from __future__ import absolute_import import json -from contextlib import contextmanager import logging +from contextlib import contextmanager import cherrypy - -from orchestrator import OrchestratorError -import rbd import rados +import rbd +from orchestrator import OrchestratorError +from ..exceptions import DashboardException, ViewCacheNoDataException from ..services.ceph_service import SendCommandError -from ..exceptions import ViewCacheNoDataException, DashboardException - logger = logging.getLogger('exception') diff --git a/src/pybind/mgr/dashboard/services/ganesha.py b/src/pybind/mgr/dashboard/services/ganesha.py index 051e36f4035..633049ba89c 100644 --- a/src/pybind/mgr/dashboard/services/ganesha.py +++ b/src/pybind/mgr/dashboard/services/ganesha.py @@ -6,14 +6,14 @@ import logging import re from orchestrator import OrchestratorError + +from .. import mgr +from ..exceptions import DashboardException +from ..settings import Settings from .cephfs import CephFS from .cephx import CephX from .orchestrator import OrchClient -from .rgw_client import RgwClient, RequestException, NoCredentialsException -from .. import mgr -from ..settings import Settings -from ..exceptions import DashboardException - +from .rgw_client import NoCredentialsException, RequestException, RgwClient logger = logging.getLogger('ganesha') diff --git a/src/pybind/mgr/dashboard/services/iscsi_cli.py b/src/pybind/mgr/dashboard/services/iscsi_cli.py index e894a56caef..2067d1e8d17 100644 --- a/src/pybind/mgr/dashboard/services/iscsi_cli.py +++ b/src/pybind/mgr/dashboard/services/iscsi_cli.py @@ -6,10 +6,11 @@ import json from mgr_module import CLIReadCommand, CLIWriteCommand -from .iscsi_client import IscsiClient -from .iscsi_config import IscsiGatewaysConfig, IscsiGatewayAlreadyExists, InvalidServiceUrl, \ - ManagedByOrchestratorException, IscsiGatewayDoesNotExist from ..rest_client import RequestException +from .iscsi_client import IscsiClient +from .iscsi_config import InvalidServiceUrl, IscsiGatewayAlreadyExists, \ + IscsiGatewayDoesNotExist, IscsiGatewaysConfig, \ + ManagedByOrchestratorException @CLIReadCommand('dashboard iscsi-gateway-list', desc='List iSCSI gateways') diff --git a/src/pybind/mgr/dashboard/services/iscsi_client.py b/src/pybind/mgr/dashboard/services/iscsi_client.py index b5ab88629ae..9cc2600e121 100644 --- a/src/pybind/mgr/dashboard/services/iscsi_client.py +++ b/src/pybind/mgr/dashboard/services/iscsi_client.py @@ -12,10 +12,9 @@ try: except ImportError: from urllib.parse import urlparse -from .iscsi_config import IscsiGatewaysConfig -from ..settings import Settings from ..rest_client import RestClient - +from ..settings import Settings +from .iscsi_config import IscsiGatewaysConfig logger = logging.getLogger('iscsi_client') diff --git a/src/pybind/mgr/dashboard/services/iscsi_config.py b/src/pybind/mgr/dashboard/services/iscsi_config.py index 86bdfc770d2..acc0c09362c 100644 --- a/src/pybind/mgr/dashboard/services/iscsi_config.py +++ b/src/pybind/mgr/dashboard/services/iscsi_config.py @@ -57,8 +57,8 @@ class IscsiGatewaysConfig(object): """ for gateway_name, gateway_config in config['gateways'].items(): if '.' not in gateway_name: - from .iscsi_client import IscsiClient # pylint: disable=cyclic-import from ..rest_client import RequestException + from .iscsi_client import IscsiClient # pylint: disable=cyclic-import try: service_url = gateway_config['service_url'] new_gateway_name = IscsiClient.instance( diff --git a/src/pybind/mgr/dashboard/services/orchestrator.py b/src/pybind/mgr/dashboard/services/orchestrator.py index 7841bf51983..37b7b3b141e 100644 --- a/src/pybind/mgr/dashboard/services/orchestrator.py +++ b/src/pybind/mgr/dashboard/services/orchestrator.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import logging +import logging from functools import wraps -from typing import List, Optional, Dict, Any +from typing import Any, Dict, List, Optional from ceph.deployment.service_spec import ServiceSpec -from orchestrator import InventoryFilter, DeviceLightLoc, Completion -from orchestrator import ServiceDescription, DaemonDescription -from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError -from orchestrator import HostSpec +from orchestrator import Completion, DaemonDescription, DeviceLightLoc, \ + HostSpec, InventoryFilter, OrchestratorClientMixin, OrchestratorError, \ + ServiceDescription, raise_if_exception + from .. import mgr logger = logging.getLogger('orchestrator') diff --git a/src/pybind/mgr/dashboard/services/progress.py b/src/pybind/mgr/dashboard/services/progress.py index d7b9ed973b5..96272beff7c 100644 --- a/src/pybind/mgr/dashboard/services/progress.py +++ b/src/pybind/mgr/dashboard/services/progress.py @@ -9,12 +9,11 @@ using the same structure of dashboard tasks from __future__ import absolute_import -from datetime import datetime import logging +from datetime import datetime -from . import rbd # pylint: disable=no-name-in-module from .. import mgr - +from . import rbd # pylint: disable=no-name-in-module logger = logging.getLogger('progress') diff --git a/src/pybind/mgr/dashboard/services/rbd.py b/src/pybind/mgr/dashboard/services/rbd.py index fa46356f1c2..08363191557 100644 --- a/src/pybind/mgr/dashboard/services/rbd.py +++ b/src/pybind/mgr/dashboard/services/rbd.py @@ -3,7 +3,6 @@ from __future__ import absolute_import import cherrypy - import rbd from .. import mgr diff --git a/src/pybind/mgr/dashboard/services/rgw_client.py b/src/pybind/mgr/dashboard/services/rgw_client.py index 8d6ca85c9ff..28256fc2cc6 100644 --- a/src/pybind/mgr/dashboard/services/rgw_client.py +++ b/src/pybind/mgr/dashboard/services/rgw_client.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import re -import logging import ipaddress -from distutils.util import strtobool +import logging +import re import xml.etree.ElementTree as ET # noqa: N814 +from distutils.util import strtobool + +from .. import mgr from ..awsauth import S3Auth from ..exceptions import DashboardException -from ..settings import Settings, Options -from ..rest_client import RestClient, RequestException -from ..tools import build_url, dict_contains_path, json_str_to_object,\ - partial_dict, dict_get -from .. import mgr +from ..rest_client import RequestException, RestClient +from ..settings import Options, Settings +from ..tools import build_url, dict_contains_path, dict_get, json_str_to_object, partial_dict try: from typing import Dict, List, Optional diff --git a/src/pybind/mgr/dashboard/services/sso.py b/src/pybind/mgr/dashboard/services/sso.py index 7f0bd683085..ac19180bddc 100644 --- a/src/pybind/mgr/dashboard/services/sso.py +++ b/src/pybind/mgr/dashboard/services/sso.py @@ -2,25 +2,23 @@ # pylint: disable=too-many-return-statements,too-many-branches from __future__ import absolute_import -import os import errno import json import logging +import os import threading import warnings - from urllib import parse from .. import mgr from ..tools import prepare_url_prefix - logger = logging.getLogger('sso') try: - from onelogin.saml2.settings import OneLogin_Saml2_Settings as Saml2Settings from onelogin.saml2.errors import OneLogin_Saml2_Error as Saml2Error from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser as Saml2Parser + from onelogin.saml2.settings import OneLogin_Saml2_Settings as Saml2Settings python_saml_imported = True except ImportError: @@ -154,7 +152,7 @@ def handle_sso_command(cmd): Saml2Settings(mgr.SSO_DB.saml2.onelogin_settings) except Saml2Error: return -errno.EPERM, '', 'Single Sign-On is not configured: ' \ - 'use `ceph dashboard sso setup saml2`' + 'use `ceph dashboard sso setup saml2`' mgr.SSO_DB.protocol = 'saml2' mgr.SSO_DB.save() return 0, 'SSO is "enabled" with "SAML2" protocol.', '' diff --git a/src/pybind/mgr/dashboard/services/tcmu_service.py b/src/pybind/mgr/dashboard/services/tcmu_service.py index 183cb29bb37..565e3dce093 100644 --- a/src/pybind/mgr/dashboard/services/tcmu_service.py +++ b/src/pybind/mgr/dashboard/services/tcmu_service.py @@ -1,6 +1,7 @@ from mgr_util import get_most_recent_rate from dashboard.services.ceph_service import CephService + from .. import mgr try: @@ -60,7 +61,7 @@ class TcmuService(object): perf_key = "{}lock_acquired_time".format(perf_key_prefix) lock_acquired_time = (mgr.get_counter( 'tcmu-runner', service_id, perf_key)[perf_key] - or [[0, 0]])[-1][1] / 1000000000 + or [[0, 0]])[-1][1] / 1000000000 if lock_acquired_time > image.get('optimized_since', 0): image['optimized_daemon'] = hostname image['optimized_since'] = lock_acquired_time diff --git a/src/pybind/mgr/dashboard/settings.py b/src/pybind/mgr/dashboard/settings.py index 23e95b1f3d2..c9c34485974 100644 --- a/src/pybind/mgr/dashboard/settings.py +++ b/src/pybind/mgr/dashboard/settings.py @@ -85,7 +85,7 @@ class Options(object): @staticmethod def has_default_value(name): return getattr(Settings, name, None) is None or \ - getattr(Settings, name) == getattr(Options, name)[0] + getattr(Settings, name) == getattr(Options, name)[0] class SettingsMeta(type): diff --git a/src/pybind/mgr/dashboard/tests/__init__.py b/src/pybind/mgr/dashboard/tests/__init__.py index 08d6aef86ab..722f7d86e77 100644 --- a/src/pybind/mgr/dashboard/tests/__init__.py +++ b/src/pybind/mgr/dashboard/tests/__init__.py @@ -10,19 +10,15 @@ import time import cherrypy from cherrypy._cptools import HandlerWrapperTool from cherrypy.test import helper -from pyfakefs import fake_filesystem - from mgr_module import CLICommand +from pyfakefs import fake_filesystem from .. import mgr -from ..controllers import json_error_page, generate_controller_routes +from ..controllers import generate_controller_routes, json_error_page +from ..plugins import PLUGIN_MANAGER, debug, feature_toggles # noqa from ..services.auth import AuthManagerTool from ..services.exception import dashboard_exception_handler -from ..plugins import PLUGIN_MANAGER -from ..plugins import feature_toggles, debug # noqa - - PLUGIN_MANAGER.hook.init() PLUGIN_MANAGER.hook.register_commands() diff --git a/src/pybind/mgr/dashboard/tests/helper.py b/src/pybind/mgr/dashboard/tests/helper.py index 06b83d42a82..e71133a108b 100644 --- a/src/pybind/mgr/dashboard/tests/helper.py +++ b/src/pybind/mgr/dashboard/tests/helper.py @@ -2,7 +2,7 @@ from __future__ import absolute_import try: - from typing import Dict, Any + from typing import Any, Dict except ImportError: pass diff --git a/src/pybind/mgr/dashboard/tests/test_access_control.py b/src/pybind/mgr/dashboard/tests/test_access_control.py index bf831a4ac74..7ace71d6ce6 100644 --- a/src/pybind/mgr/dashboard/tests/test_access_control.py +++ b/src/pybind/mgr/dashboard/tests/test_access_control.py @@ -6,16 +6,14 @@ import errno import json import time import unittest - from datetime import datetime, timedelta -from . import CmdException, CLICommandTestMixin # pylint: disable=no-name-in-module from .. import mgr -from ..security import Scope, Permission -from ..services.access_control import load_access_control_db, \ - password_hash, AccessControlDB, \ - SYSTEM_ROLES, PasswordPolicy +from ..security import Permission, Scope +from ..services.access_control import SYSTEM_ROLES, AccessControlDB, \ + PasswordPolicy, load_access_control_db, password_hash from ..settings import Settings +from . import CLICommandTestMixin, CmdException # pylint: disable=no-name-in-module class AccessControlTest(unittest.TestCase, CLICommandTestMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_api_auditing.py b/src/pybind/mgr/dashboard/tests/test_api_auditing.py index 023ea7992a1..04314b27e0c 100644 --- a/src/pybind/mgr/dashboard/tests/test_api_auditing.py +++ b/src/pybind/mgr/dashboard/tests/test_api_auditing.py @@ -1,18 +1,20 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import re import json +import re + import cherrypy + try: import mock except ImportError: import unittest.mock as mock -from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module -from ..controllers import RESTController, Controller -from ..tools import RequestLoggingTool from .. import mgr +from ..controllers import Controller, RESTController +from ..tools import RequestLoggingTool +from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module # pylint: disable=W0613 diff --git a/src/pybind/mgr/dashboard/tests/test_ceph_service.py b/src/pybind/mgr/dashboard/tests/test_ceph_service.py index 5111e68d492..6c793631fd9 100644 --- a/src/pybind/mgr/dashboard/tests/test_ceph_service.py +++ b/src/pybind/mgr/dashboard/tests/test_ceph_service.py @@ -3,6 +3,7 @@ from __future__ import absolute_import import unittest + try: import mock except ImportError: diff --git a/src/pybind/mgr/dashboard/tests/test_cephfs.py b/src/pybind/mgr/dashboard/tests/test_cephfs.py index 778b0aa2750..f37741e50fd 100644 --- a/src/pybind/mgr/dashboard/tests/test_cephfs.py +++ b/src/pybind/mgr/dashboard/tests/test_cephfs.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- from collections import defaultdict + try: from mock import Mock except ImportError: from unittest.mock import Mock from .. import mgr -from . import ControllerTestCase # pylint: disable=no-name-in-module from ..controllers.cephfs import CephFS +from . import ControllerTestCase # pylint: disable=no-name-in-module class MetaDataMock(object): diff --git a/src/pybind/mgr/dashboard/tests/test_controllers.py b/src/pybind/mgr/dashboard/tests/test_controllers.py index b14878ff2e4..bacef3677d7 100644 --- a/src/pybind/mgr/dashboard/tests/test_controllers.py +++ b/src/pybind/mgr/dashboard/tests/test_controllers.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from ..controllers import ApiController, BaseController, Controller, Endpoint, RESTController from . import ControllerTestCase # pylint: disable=no-name-in-module -from ..controllers import BaseController, RESTController, Controller, \ - ApiController, Endpoint @Controller("/btest/{key}", base_url="/ui", secure=False) diff --git a/src/pybind/mgr/dashboard/tests/test_docs.py b/src/pybind/mgr/dashboard/tests/test_docs.py index ccb777aca5f..db5eefdddec 100644 --- a/src/pybind/mgr/dashboard/tests/test_docs.py +++ b/src/pybind/mgr/dashboard/tests/test_docs.py @@ -1,9 +1,9 @@ # # -*- coding: utf-8 -*- from __future__ import absolute_import -from . import ControllerTestCase # pylint: disable=no-name-in-module -from ..controllers import RESTController, ApiController, Endpoint, EndpointDoc, ControllerDoc +from ..controllers import ApiController, ControllerDoc, Endpoint, EndpointDoc, RESTController from ..controllers.docs import Docs +from . import ControllerTestCase # pylint: disable=no-name-in-module # Dummy controller and endpoint that can be assigned with @EndpointDoc and @GroupDoc diff --git a/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py b/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py index d266735e8f5..8ff1490708f 100644 --- a/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py +++ b/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from .. import mgr -from . import ControllerTestCase # pylint: disable=no-name-in-module from ..controllers.erasure_code_profile import ErasureCodeProfile +from . import ControllerTestCase # pylint: disable=no-name-in-module class ErasureCodeProfileTest(ControllerTestCase): diff --git a/src/pybind/mgr/dashboard/tests/test_exceptions.py b/src/pybind/mgr/dashboard/tests/test_exceptions.py index d08c1b01d4c..bbf90909572 100644 --- a/src/pybind/mgr/dashboard/tests/test_exceptions.py +++ b/src/pybind/mgr/dashboard/tests/test_exceptions.py @@ -5,12 +5,12 @@ import time import rados -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..controllers import Controller, Endpoint, RESTController, Task from ..services.ceph_service import SendCommandError -from ..controllers import RESTController, Controller, Task, Endpoint -from ..services.exception import handle_rados_error, handle_send_command_error, \ - serialize_dashboard_exception -from ..tools import ViewCache, TaskManager, NotificationQueue +from ..services.exception import handle_rados_error, \ + handle_send_command_error, serialize_dashboard_exception +from ..tools import NotificationQueue, TaskManager, ViewCache +from . import ControllerTestCase # pylint: disable=no-name-in-module # pylint: disable=W0613 diff --git a/src/pybind/mgr/dashboard/tests/test_feature_toggles.py b/src/pybind/mgr/dashboard/tests/test_feature_toggles.py index 23068c5eda7..a5088e1a0c5 100644 --- a/src/pybind/mgr/dashboard/tests/test_feature_toggles.py +++ b/src/pybind/mgr/dashboard/tests/test_feature_toggles.py @@ -2,13 +2,14 @@ from __future__ import absolute_import import unittest + try: from mock import Mock, patch except ImportError: from unittest.mock import Mock, patch +from ..plugins.feature_toggles import Features, FeatureToggles from . import KVStoreMockMixin # pylint: disable=no-name-in-module -from ..plugins.feature_toggles import FeatureToggles, Features class SettingsTest(unittest.TestCase, KVStoreMockMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_ganesha.py b/src/pybind/mgr/dashboard/tests/test_ganesha.py index 44498ac40cc..8e2d5804395 100644 --- a/src/pybind/mgr/dashboard/tests/test_ganesha.py +++ b/src/pybind/mgr/dashboard/tests/test_ganesha.py @@ -9,11 +9,12 @@ except ImportError: from unittest.mock import MagicMock, Mock import orchestrator -from . import KVStoreMockMixin # pylint: disable=no-name-in-module + from .. import mgr -from ..settings import Settings from ..services import ganesha -from ..services.ganesha import GaneshaConf, Export, GaneshaConfParser +from ..services.ganesha import Export, GaneshaConf, GaneshaConfParser +from ..settings import Settings +from . import KVStoreMockMixin # pylint: disable=no-name-in-module class GaneshaConfTest(unittest.TestCase, KVStoreMockMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_grafana.py b/src/pybind/mgr/dashboard/tests/test_grafana.py index a5456905f20..d9b15e8231e 100644 --- a/src/pybind/mgr/dashboard/tests/test_grafana.py +++ b/src/pybind/mgr/dashboard/tests/test_grafana.py @@ -8,10 +8,10 @@ except ImportError: from requests import RequestException -from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module from ..controllers.grafana import Grafana from ..grafana import GrafanaRestClient from ..settings import Settings +from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module class GrafanaTest(ControllerTestCase, KVStoreMockMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_home.py b/src/pybind/mgr/dashboard/tests/test_home.py index b0646e41d9e..37e09b4b2af 100644 --- a/src/pybind/mgr/dashboard/tests/test_home.py +++ b/src/pybind/mgr/dashboard/tests/test_home.py @@ -8,10 +8,9 @@ try: except ImportError: import unittest.mock as mock -from . import ControllerTestCase, FakeFsMixin # pylint: disable=no-name-in-module from .. import mgr - from ..controllers.home import HomeController, LanguageMixin +from . import ControllerTestCase, FakeFsMixin # pylint: disable=no-name-in-module logger = logging.getLogger() diff --git a/src/pybind/mgr/dashboard/tests/test_host.py b/src/pybind/mgr/dashboard/tests/test_host.py index aaf4b1dd4d9..9c2500cd078 100644 --- a/src/pybind/mgr/dashboard/tests/test_host.py +++ b/src/pybind/mgr/dashboard/tests/test_host.py @@ -7,9 +7,9 @@ except ImportError: from orchestrator import HostSpec -from . import ControllerTestCase # pylint: disable=no-name-in-module -from ..controllers.host import get_hosts, Host, HostUi from .. import mgr +from ..controllers.host import Host, HostUi, get_hosts +from . import ControllerTestCase # pylint: disable=no-name-in-module class HostControllerTest(ControllerTestCase): diff --git a/src/pybind/mgr/dashboard/tests/test_iscsi.py b/src/pybind/mgr/dashboard/tests/test_iscsi.py index 475c1a77798..fc51c61028a 100644 --- a/src/pybind/mgr/dashboard/tests/test_iscsi.py +++ b/src/pybind/mgr/dashboard/tests/test_iscsi.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-public-methods +# pylint: disable=too-many-public-methods,too-many-lines import copy import errno @@ -10,14 +10,16 @@ try: except ImportError: import unittest.mock as mock -from . import CmdException, ControllerTestCase, CLICommandTestMixin, \ - KVStoreMockMixin # pylint: disable=no-name-in-module from .. import mgr from ..controllers.iscsi import Iscsi, IscsiTarget +from ..rest_client import RequestException from ..services.iscsi_client import IscsiClient from ..services.orchestrator import OrchClient -from ..rest_client import RequestException from ..tools import NotificationQueue, TaskManager +from . import CLICommandTestMixin # pylint: disable=no-name-in-module +from . import CmdException # pylint: disable=no-name-in-module +from . import ControllerTestCase # pylint: disable=no-name-in-module +from . import KVStoreMockMixin # pylint: disable=no-name-in-module class IscsiTestCli(unittest.TestCase, CLICommandTestMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_notification.py b/src/pybind/mgr/dashboard/tests/test_notification.py index 185ddc127b5..df303e45563 100644 --- a/src/pybind/mgr/dashboard/tests/test_notification.py +++ b/src/pybind/mgr/dashboard/tests/test_notification.py @@ -5,7 +5,6 @@ import random import time import unittest - from ..tools import NotificationQueue diff --git a/src/pybind/mgr/dashboard/tests/test_orchestrator.py b/src/pybind/mgr/dashboard/tests/test_orchestrator.py index c053f920d16..00102f36a58 100644 --- a/src/pybind/mgr/dashboard/tests/test_orchestrator.py +++ b/src/pybind/mgr/dashboard/tests/test_orchestrator.py @@ -1,5 +1,6 @@ import inspect import unittest + try: import mock except ImportError: @@ -8,12 +9,10 @@ except ImportError: from orchestrator import InventoryHost from orchestrator import Orchestrator as OrchestratorBase -from . import ControllerTestCase # pylint: disable=no-name-in-module from .. import mgr -from ..controllers.orchestrator import get_device_osd_map -from ..controllers.orchestrator import Orchestrator -from ..controllers.orchestrator import OrchestratorInventory +from ..controllers.orchestrator import Orchestrator, OrchestratorInventory, get_device_osd_map from ..services.orchestrator import OrchFeature +from . import ControllerTestCase # pylint: disable=no-name-in-module class OrchestratorControllerTest(ControllerTestCase): diff --git a/src/pybind/mgr/dashboard/tests/test_osd.py b/src/pybind/mgr/dashboard/tests/test_osd.py index 925035a169e..2c4080adbe9 100644 --- a/src/pybind/mgr/dashboard/tests/test_osd.py +++ b/src/pybind/mgr/dashboard/tests/test_osd.py @@ -1,19 +1,18 @@ # -*- coding: utf-8 -*- import uuid from contextlib import contextmanager - +from typing import Any, Dict, List, Optional from unittest import mock + from ceph.deployment.drive_group import DeviceSelection, DriveGroupSpec # type: ignore from ceph.deployment.service_spec import PlacementSpec # type: ignore -from . import ControllerTestCase # pylint: disable=no-name-in-module +from .. import mgr from ..controllers.osd import Osd from ..tools import NotificationQueue, TaskManager -from .. import mgr +from . import ControllerTestCase # pylint: disable=no-name-in-module from .helper import update_dict # pylint: disable=import-error -from typing import Any, Dict, List, Optional # pylint: disable=C0411 - class OsdHelper(object): DEFAULT_OSD_IDS = [0, 1, 2] diff --git a/src/pybind/mgr/dashboard/tests/test_pool.py b/src/pybind/mgr/dashboard/tests/test_pool.py index 179a8feeed8..d5cdb63e0e5 100644 --- a/src/pybind/mgr/dashboard/tests/test_pool.py +++ b/src/pybind/mgr/dashboard/tests/test_pool.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- # pylint: disable=protected-access import time + try: import mock except ImportError: import unittest.mock as mock -from . import ControllerTestCase # pylint: disable=no-name-in-module from ..controllers.pool import Pool from ..controllers.task import Task from ..tools import NotificationQueue, TaskManager +from . import ControllerTestCase # pylint: disable=no-name-in-module class MockTask(object): diff --git a/src/pybind/mgr/dashboard/tests/test_prometheus.py b/src/pybind/mgr/dashboard/tests/test_prometheus.py index ef669a62033..3b84f0e0044 100644 --- a/src/pybind/mgr/dashboard/tests/test_prometheus.py +++ b/src/pybind/mgr/dashboard/tests/test_prometheus.py @@ -5,9 +5,9 @@ try: except ImportError: from unittest.mock import patch -from . import ControllerTestCase # pylint: disable=no-name-in-module from .. import mgr -from ..controllers.prometheus import Prometheus, PrometheusReceiver, PrometheusNotifications +from ..controllers.prometheus import Prometheus, PrometheusNotifications, PrometheusReceiver +from . import ControllerTestCase # pylint: disable=no-name-in-module class PrometheusControllerTest(ControllerTestCase): diff --git a/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py b/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py index d7e0c7dd1e8..9f83bad83e1 100644 --- a/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py @@ -1,18 +1,17 @@ from __future__ import absolute_import import json + try: import mock except ImportError: import unittest.mock as mock -from . import ControllerTestCase # pylint: disable=no-name-in-module from .. import mgr +from ..controllers.rbd_mirroring import RbdMirroring, RbdMirroringPoolBootstrap, RbdMirroringSummary from ..controllers.summary import Summary -from ..controllers.rbd_mirroring import RbdMirroring, RbdMirroringSummary, \ - RbdMirroringPoolBootstrap from ..services import progress - +from . import ControllerTestCase # pylint: disable=no-name-in-module mock_list_servers = [{ 'hostname': 'ceph-host', @@ -137,7 +136,7 @@ class RbdMirroringSummaryControllerTest(ControllerTestCase): 'mgr_map': { 'services': { 'dashboard': 'https://ceph.dev:11000/' - }, + }, } }[key] mgr.url_prefix = '' diff --git a/src/pybind/mgr/dashboard/tests/test_rbd_service.py b/src/pybind/mgr/dashboard/tests/test_rbd_service.py index caee4029180..99cf27d8214 100644 --- a/src/pybind/mgr/dashboard/tests/test_rbd_service.py +++ b/src/pybind/mgr/dashboard/tests/test_rbd_service.py @@ -3,12 +3,13 @@ from __future__ import absolute_import import unittest + try: import mock except ImportError: import unittest.mock as mock -from ..services.rbd import get_image_spec, parse_image_spec, RbdConfiguration +from ..services.rbd import RbdConfiguration, get_image_spec, parse_image_spec class RbdServiceTest(unittest.TestCase): diff --git a/src/pybind/mgr/dashboard/tests/test_rest_client.py b/src/pybind/mgr/dashboard/tests/test_rest_client.py index fc48f0eb036..ba71b4f153e 100644 --- a/src/pybind/mgr/dashboard/tests/test_rest_client.py +++ b/src/pybind/mgr/dashboard/tests/test_rest_client.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import unittest + import requests.exceptions try: @@ -8,6 +9,7 @@ except ImportError: from unittest.mock import patch from urllib3.exceptions import MaxRetryError, ProtocolError + from .. import mgr from ..rest_client import RequestException, RestClient diff --git a/src/pybind/mgr/dashboard/tests/test_rest_tasks.py b/src/pybind/mgr/dashboard/tests/test_rest_tasks.py index f9e7a428e6c..b4abbdea36b 100644 --- a/src/pybind/mgr/dashboard/tests/test_rest_tasks.py +++ b/src/pybind/mgr/dashboard/tests/test_rest_tasks.py @@ -7,11 +7,11 @@ try: except ImportError: import unittest.mock as mock -from . import ControllerTestCase # pylint: disable=no-name-in-module from ..controllers import Controller, RESTController, Task from ..controllers.task import Task as TaskController from ..services import progress from ..tools import NotificationQueue, TaskManager +from . import ControllerTestCase # pylint: disable=no-name-in-module @Controller('/test/task', secure=False) diff --git a/src/pybind/mgr/dashboard/tests/test_rgw.py b/src/pybind/mgr/dashboard/tests/test_rgw.py index 11818ca2b78..05a7bbbc5db 100644 --- a/src/pybind/mgr/dashboard/tests/test_rgw.py +++ b/src/pybind/mgr/dashboard/tests/test_rgw.py @@ -3,8 +3,8 @@ try: except ImportError: import unittest.mock as mock -from . import ControllerTestCase # pylint: disable=no-name-in-module from ..controllers.rgw import RgwUser +from . import ControllerTestCase # pylint: disable=no-name-in-module class RgwUserControllerTestCase(ControllerTestCase): diff --git a/src/pybind/mgr/dashboard/tests/test_settings.py b/src/pybind/mgr/dashboard/tests/test_settings.py index abdb059c1d5..1fdd8f96e5a 100644 --- a/src/pybind/mgr/dashboard/tests/test_settings.py +++ b/src/pybind/mgr/dashboard/tests/test_settings.py @@ -3,10 +3,11 @@ from __future__ import absolute_import import errno import unittest -from . import KVStoreMockMixin, ControllerTestCase # pylint: disable=no-name-in-module + from .. import settings from ..controllers.settings import Settings as SettingsController from ..settings import Settings, handle_option_command +from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module class SettingsTest(unittest.TestCase, KVStoreMockMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_sso.py b/src/pybind/mgr/dashboard/tests/test_sso.py index e8141a09cc3..ee97fb20fdd 100644 --- a/src/pybind/mgr/dashboard/tests/test_sso.py +++ b/src/pybind/mgr/dashboard/tests/test_sso.py @@ -5,9 +5,10 @@ from __future__ import absolute_import import errno import unittest -from . import CmdException, exec_dashboard_cmd, \ - KVStoreMockMixin # pylint: disable=no-name-in-module from ..services.sso import handle_sso_command, load_sso_db +from . import CmdException # pylint: disable=no-name-in-module +from . import KVStoreMockMixin # pylint: disable=no-name-in-module +from . import exec_dashboard_cmd # pylint: disable=no-name-in-module class AccessControlTest(unittest.TestCase, KVStoreMockMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_task.py b/src/pybind/mgr/dashboard/tests/test_task.py index f3e8ed77f46..0d51e2d3f88 100644 --- a/src/pybind/mgr/dashboard/tests/test_task.py +++ b/src/pybind/mgr/dashboard/tests/test_task.py @@ -2,14 +2,14 @@ from __future__ import absolute_import import json -import unittest import threading import time +import unittest from collections import defaultdict from functools import partial from ..services.exception import serialize_dashboard_exception -from ..tools import NotificationQueue, TaskManager, TaskExecutor +from ..tools import NotificationQueue, TaskExecutor, TaskManager class MyTask(object): diff --git a/src/pybind/mgr/dashboard/tests/test_tools.py b/src/pybind/mgr/dashboard/tests/test_tools.py index cb1c12cb020..4f9b17c0327 100644 --- a/src/pybind/mgr/dashboard/tests/test_tools.py +++ b/src/pybind/mgr/dashboard/tests/test_tools.py @@ -5,17 +5,17 @@ import unittest import cherrypy from cherrypy.lib.sessions import RamSession + try: from mock import patch except ImportError: from unittest.mock import patch -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..controllers import ApiController, BaseController, Controller, Proxy, RESTController from ..services.exception import handle_rados_error -from ..controllers import RESTController, ApiController, Controller, \ - BaseController, Proxy -from ..tools import dict_contains_path, json_str_to_object, partial_dict,\ - dict_get, RequestLoggingTool +from ..tools import RequestLoggingTool, dict_contains_path, dict_get, \ + json_str_to_object, partial_dict +from . import ControllerTestCase # pylint: disable=no-name-in-module # pylint: disable=W0613 diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index bf15b745b5c..c4819ef3026 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -1,30 +1,27 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +import collections +import fnmatch import inspect import json import logging - -import collections -from datetime import datetime, timedelta -from distutils.util import strtobool -import fnmatch -import time import threading +import time import urllib +from datetime import datetime, timedelta +from distutils.util import strtobool import cherrypy - from ceph.deployment.utils import wrap_ipv6 from . import mgr from .exceptions import ViewCacheNoDataException -from .settings import Settings from .services.auth import JwtManager +from .settings import Settings try: - from typing import Any, AnyStr, Callable, DefaultDict, Deque,\ - Dict, List, Set, Tuple, Union # noqa + from typing import Any, AnyStr, Callable, DefaultDict, Deque, Dict, List, Set, Tuple, Union except ImportError: pass # For typing only diff --git a/src/pybind/mgr/dashboard/tox.ini b/src/pybind/mgr/dashboard/tox.ini index e45907be7a2..a4438cff326 100644 --- a/src/pybind/mgr/dashboard/tox.ini +++ b/src/pybind/mgr/dashboard/tox.ini @@ -73,6 +73,12 @@ statistics = True #max-complexity = 10 format = ${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s +[isort] +atomic = true +multi_line_output = 2 +line_length = 100 +wrap_length = 80 + [pylint] # Allow similarity/code duplication detection jobs = 1 @@ -97,6 +103,7 @@ deps = {[base-lint]deps} commands = flake8 + isort . --check {[base-pylint]commands} {[base-rst]commands} @@ -137,7 +144,7 @@ deps = commands = python --version autopep8 {[autopep8]addopts} {posargs:.} - + isort . [testenv:check] commands = -- 2.39.5