From 2e2b419dafd4738553e85a905151ba1e6ffce13d Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Wed, 3 Feb 2021 07:06:06 -0700 Subject: [PATCH] mgr/cephadm: Module imported but unused (F401) Signed-off-by: Michael Fritch --- src/pybind/mgr/cephadm/__init__.py | 10 +++-- src/pybind/mgr/cephadm/migrations.py | 2 +- src/pybind/mgr/cephadm/module.py | 14 +++---- src/pybind/mgr/cephadm/schedule.py | 2 +- src/pybind/mgr/cephadm/serve.py | 1 - .../mgr/cephadm/services/cephadmservice.py | 6 +-- src/pybind/mgr/cephadm/services/ha_rgw.py | 4 +- src/pybind/mgr/cephadm/services/iscsi.py | 3 +- src/pybind/mgr/cephadm/services/nfs.py | 8 +--- src/pybind/mgr/cephadm/services/osd.py | 2 +- src/pybind/mgr/cephadm/template.py | 2 +- src/pybind/mgr/cephadm/tests/conftest.py | 27 +++++++++++++ src/pybind/mgr/cephadm/tests/fixtures.py | 26 +----------- src/pybind/mgr/cephadm/tests/test_cephadm.py | 7 ++-- .../mgr/cephadm/tests/test_completion.py | 13 +----- .../mgr/cephadm/tests/test_migration.py | 5 +-- .../mgr/cephadm/tests/test_osd_removal.py | 3 +- src/pybind/mgr/cephadm/tests/test_services.py | 4 +- src/pybind/mgr/cephadm/tests/test_spec.py | 3 +- src/pybind/mgr/cephadm/tests/test_template.py | 1 - src/pybind/mgr/cephadm/tests/test_upgrade.py | 2 +- src/pybind/mgr/cephadm/upgrade.py | 2 +- src/pybind/mgr/orchestrator/__init__.py | 40 +++++++++++++++++-- src/pybind/mgr/orchestrator/module.py | 6 +-- src/pybind/mgr/tox.ini | 1 - 25 files changed, 102 insertions(+), 92 deletions(-) create mode 100644 src/pybind/mgr/cephadm/tests/conftest.py diff --git a/src/pybind/mgr/cephadm/__init__.py b/src/pybind/mgr/cephadm/__init__.py index f390f18c16a..597d883f7ae 100644 --- a/src/pybind/mgr/cephadm/__init__.py +++ b/src/pybind/mgr/cephadm/__init__.py @@ -1,6 +1,10 @@ -import os +from .module import CephadmOrchestrator + +__all__ = [ + "CephadmOrchestrator", +] +import os if 'UNITTEST' in os.environ: import tests - -from .module import CephadmOrchestrator + __all__.append(tests.__name__) diff --git a/src/pybind/mgr/cephadm/migrations.py b/src/pybind/mgr/cephadm/migrations.py index a45cdb9a926..0b4ac978026 100644 --- a/src/pybind/mgr/cephadm/migrations.py +++ b/src/pybind/mgr/cephadm/migrations.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING, Iterator, Union +from typing import TYPE_CHECKING, Iterator from ceph.deployment.service_spec import PlacementSpec, ServiceSpec, HostPlacementSpec from cephadm.schedule import HostAssignment diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 85bb7b45b35..40d1be8b039 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -5,14 +5,13 @@ import re import shlex from collections import defaultdict from configparser import ConfigParser -from contextlib import contextmanager from functools import wraps from tempfile import TemporaryDirectory from threading import Event import string from typing import List, Dict, Optional, Callable, Tuple, TypeVar, \ - Any, Set, TYPE_CHECKING, cast, Iterator, NamedTuple, Sequence + Any, Set, TYPE_CHECKING, cast, NamedTuple, Sequence import datetime import os @@ -25,19 +24,19 @@ from ceph.deployment import inventory from ceph.deployment.drive_group import DriveGroupSpec from ceph.deployment.service_spec import \ NFSServiceSpec, ServiceSpec, PlacementSpec, assert_valid_host, \ - HostPlacementSpec, HA_RGWSpec + HostPlacementSpec from ceph.utils import str_to_datetime, datetime_to_str, datetime_now from cephadm.serve import CephadmServe from cephadm.services.cephadmservice import CephadmDaemonSpec from mgr_module import MgrModule, HandleCommandResult, Option -from mgr_util import create_self_signed_cert, verify_tls, ServerConfigException +from mgr_util import create_self_signed_cert import secrets import orchestrator from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpec, \ - CLICommandMeta, OrchestratorEvent, set_exception_subject, DaemonDescription + CLICommandMeta, DaemonDescription from orchestrator._interface import GenericSpec -from orchestrator._interface import daemon_type_to_service, service_to_daemon_types +from orchestrator._interface import daemon_type_to_service from . import remotes from . import utils @@ -48,7 +47,7 @@ from .services.container import CustomContainerService from .services.iscsi import IscsiService from .services.ha_rgw import HA_RGWService from .services.nfs import NFSService -from .services.osd import RemoveUtil, OSDRemovalQueue, OSDService, OSD, NotFoundError +from .services.osd import OSDRemovalQueue, OSDService, OSD, NotFoundError from .services.monitoring import GrafanaService, AlertmanagerService, PrometheusService, \ NodeExporterService from .schedule import HostAssignment @@ -69,7 +68,6 @@ try: from remoto.backends import BaseConnection BaseConnection.has_connection = remoto_has_connection import remoto.process - import execnet.gateway_bootstrap except ImportError as e: remoto = None remoto_import_error = str(e) diff --git a/src/pybind/mgr/cephadm/schedule.py b/src/pybind/mgr/cephadm/schedule.py index 7913c35e678..7d2e2308bae 100644 --- a/src/pybind/mgr/cephadm/schedule.py +++ b/src/pybind/mgr/cephadm/schedule.py @@ -3,7 +3,7 @@ import random from typing import List, Optional, Callable, Iterable, TypeVar, Set import orchestrator -from ceph.deployment.service_spec import PlacementSpec, HostPlacementSpec, ServiceSpec +from ceph.deployment.service_spec import HostPlacementSpec, ServiceSpec from orchestrator._interface import DaemonDescription from orchestrator import OrchestratorValidationError diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 17e279e5200..3e7b040abb3 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -1,4 +1,3 @@ -import datetime import json import logging from collections import defaultdict diff --git a/src/pybind/mgr/cephadm/services/cephadmservice.py b/src/pybind/mgr/cephadm/services/cephadmservice.py index eaa24367128..8dfb1501d7f 100644 --- a/src/pybind/mgr/cephadm/services/cephadmservice.py +++ b/src/pybind/mgr/cephadm/services/cephadmservice.py @@ -1,9 +1,7 @@ import json import re import logging -import secrets import subprocess -import collections from abc import ABCMeta, abstractmethod from typing import TYPE_CHECKING, List, Callable, Any, TypeVar, Generic, \ Optional, Dict, Any, Tuple, NewType @@ -13,9 +11,9 @@ from mgr_module import HandleCommandResult, MonCommandFailed from ceph.deployment.service_spec import ServiceSpec, RGWSpec from ceph.deployment.utils import is_ipv6, unwrap_ipv6 from orchestrator import OrchestratorError, DaemonDescription -from orchestrator._interface import daemon_type_to_service, service_to_daemon_types +from orchestrator._interface import daemon_type_to_service from cephadm import utils -from mgr_util import create_self_signed_cert, ServerConfigException, verify_tls +from mgr_util import ServerConfigException, verify_tls if TYPE_CHECKING: from cephadm.module import CephadmOrchestrator diff --git a/src/pybind/mgr/cephadm/services/ha_rgw.py b/src/pybind/mgr/cephadm/services/ha_rgw.py index 05dea1eaac8..4a37e006d58 100644 --- a/src/pybind/mgr/cephadm/services/ha_rgw.py +++ b/src/pybind/mgr/cephadm/services/ha_rgw.py @@ -1,12 +1,10 @@ -import json import logging from typing import List, cast, Tuple, Dict, Any from ceph.deployment.service_spec import HA_RGWSpec -from orchestrator import DaemonDescription, OrchestratorError from .cephadmservice import CephadmDaemonSpec, CephService -from ..utils import CephadmNoImage, cephadmNoImage, resolve_ip +from ..utils import resolve_ip logger = logging.getLogger(__name__) diff --git a/src/pybind/mgr/cephadm/services/iscsi.py b/src/pybind/mgr/cephadm/services/iscsi.py index 159c456a058..98e647bfc98 100644 --- a/src/pybind/mgr/cephadm/services/iscsi.py +++ b/src/pybind/mgr/cephadm/services/iscsi.py @@ -2,10 +2,9 @@ import json import logging from typing import List, cast -from mgr_module import MonCommandFailed from ceph.deployment.service_spec import IscsiServiceSpec -from orchestrator import DaemonDescription, OrchestratorError +from orchestrator import DaemonDescription from .cephadmservice import CephadmDaemonSpec, CephService from .. import utils diff --git a/src/pybind/mgr/cephadm/services/nfs.py b/src/pybind/mgr/cephadm/services/nfs.py index fdd080e3a3d..3a6015982ab 100644 --- a/src/pybind/mgr/cephadm/services/nfs.py +++ b/src/pybind/mgr/cephadm/services/nfs.py @@ -1,17 +1,13 @@ import logging -from typing import TYPE_CHECKING, Dict, Tuple, Any, List +from typing import Dict, Tuple, Any, List from ceph.deployment.service_spec import NFSServiceSpec import rados -from orchestrator import OrchestratorError, DaemonDescription +from orchestrator import DaemonDescription -from cephadm import utils from cephadm.services.cephadmservice import AuthEntity, CephadmDaemonSpec, CephService -if TYPE_CHECKING: - from cephadm.module import CephadmOrchestrator - logger = logging.getLogger(__name__) diff --git a/src/pybind/mgr/cephadm/services/osd.py b/src/pybind/mgr/cephadm/services/osd.py index 2f3cde6dc6e..0e898b6d9db 100644 --- a/src/pybind/mgr/cephadm/services/osd.py +++ b/src/pybind/mgr/cephadm/services/osd.py @@ -1,7 +1,7 @@ import json import logging from threading import Lock -from typing import List, Dict, Any, Set, Union, Tuple, cast, Optional, TYPE_CHECKING +from typing import List, Dict, Any, Set, Tuple, cast, Optional, TYPE_CHECKING from ceph.deployment import translate from ceph.deployment.drive_group import DriveGroupSpec diff --git a/src/pybind/mgr/cephadm/template.py b/src/pybind/mgr/cephadm/template.py index c59df3f9fb3..0d62e587c80 100644 --- a/src/pybind/mgr/cephadm/template.py +++ b/src/pybind/mgr/cephadm/template.py @@ -1,7 +1,7 @@ import copy from typing import Optional, TYPE_CHECKING -from jinja2 import Environment, PackageLoader, select_autoescape, StrictUndefined, Template +from jinja2 import Environment, PackageLoader, select_autoescape, StrictUndefined from jinja2 import exceptions as j2_exceptions if TYPE_CHECKING: diff --git a/src/pybind/mgr/cephadm/tests/conftest.py b/src/pybind/mgr/cephadm/tests/conftest.py new file mode 100644 index 00000000000..e8add2c7b83 --- /dev/null +++ b/src/pybind/mgr/cephadm/tests/conftest.py @@ -0,0 +1,27 @@ +import pytest + +from cephadm.services.osd import RemoveUtil, OSD +from tests import mock + +from .fixtures import with_cephadm_module + + +@pytest.fixture() +def cephadm_module(): + with with_cephadm_module({}) as m: + yield m + + +@pytest.fixture() +def rm_util(): + with with_cephadm_module({}) as m: + r = RemoveUtil.__new__(RemoveUtil) + r.__init__(m) + yield r + + +@pytest.fixture() +def osd_obj(): + with mock.patch("cephadm.services.osd.RemoveUtil"): + o = OSD(0, mock.MagicMock()) + yield o diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index 5c14aee1de4..8ebbb7cd0dd 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -10,10 +10,8 @@ try: from typing import Any, Iterator, List except ImportError: pass -import pytest from cephadm import CephadmOrchestrator -from cephadm.services.osd import RemoveUtil, OSD from orchestrator import raise_if_exception, Completion, HostSpec from tests import mock @@ -65,33 +63,13 @@ def with_cephadm_module(module_options=None, store=None): yield m -@pytest.fixture() -def cephadm_module(): - with with_cephadm_module({}) as m: - yield m - - -@pytest.fixture() -def rm_util(): - with with_cephadm_module({}) as m: - r = RemoveUtil.__new__(RemoveUtil) - r.__init__(m) - yield r - - -@pytest.fixture() -def osd_obj(): - with mock.patch("cephadm.services.osd.RemoveUtil"): - o = OSD(0, mock.MagicMock()) - yield o - - def wait(m, c): # type: (CephadmOrchestrator, Completion) -> Any m.process([c]) try: - import pydevd # if in debugger + # if in debugger + import pydevd # noqa: F401 in_debug = True except ImportError: in_debug = False diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index fcc953d0730..dfec2ea03b7 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -7,10 +7,9 @@ import pytest from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection from cephadm.serve import CephadmServe from cephadm.services.osd import OSD, OSDRemovalQueue -from cephadm.utils import CephadmNoImage try: - from typing import Any, List + from typing import List except ImportError: pass @@ -21,10 +20,10 @@ from ceph.deployment.service_spec import ServiceSpec, PlacementSpec, RGWSpec, \ from ceph.deployment.drive_selection.selector import DriveSelection from ceph.deployment.inventory import Devices, Device from ceph.utils import datetime_to_str, datetime_now -from orchestrator import ServiceDescription, DaemonDescription, InventoryHost, \ +from orchestrator import DaemonDescription, InventoryHost, \ HostSpec, OrchestratorError from tests import mock -from .fixtures import cephadm_module, wait, _run_cephadm, match_glob, with_host, \ +from .fixtures import wait, _run_cephadm, match_glob, with_host, \ with_cephadm_module, with_service, assert_rm_service, _deploy_cephadm_binary from cephadm.module import CephadmOrchestrator diff --git a/src/pybind/mgr/cephadm/tests/test_completion.py b/src/pybind/mgr/cephadm/tests/test_completion.py index 80592ba779d..9480ea591ee 100644 --- a/src/pybind/mgr/cephadm/tests/test_completion.py +++ b/src/pybind/mgr/cephadm/tests/test_completion.py @@ -1,17 +1,6 @@ -import sys -import time - - -try: - from typing import Any -except ImportError: - pass - import pytest - -from tests import mock -from .fixtures import cephadm_module, wait +from .fixtures import wait from ..module import trivial_completion, forall_hosts diff --git a/src/pybind/mgr/cephadm/tests/test_migration.py b/src/pybind/mgr/cephadm/tests/test_migration.py index 049743a1fb5..4b35440f6cd 100644 --- a/src/pybind/mgr/cephadm/tests/test_migration.py +++ b/src/pybind/mgr/cephadm/tests/test_migration.py @@ -1,13 +1,10 @@ import json -import pytest - from ceph.deployment.service_spec import PlacementSpec, ServiceSpec, HostPlacementSpec from ceph.utils import datetime_to_str, datetime_now from cephadm import CephadmOrchestrator from cephadm.inventory import SPEC_STORE_PREFIX -from cephadm.tests.fixtures import _run_cephadm, cephadm_module, wait, with_host -from orchestrator import OrchestratorError +from cephadm.tests.fixtures import _run_cephadm, wait, with_host from cephadm.serve import CephadmServe from tests import mock diff --git a/src/pybind/mgr/cephadm/tests/test_osd_removal.py b/src/pybind/mgr/cephadm/tests/test_osd_removal.py index f93b2c2c41a..c2bf95b4394 100644 --- a/src/pybind/mgr/cephadm/tests/test_osd_removal.py +++ b/src/pybind/mgr/cephadm/tests/test_osd_removal.py @@ -1,8 +1,7 @@ import json -from cephadm.services.osd import RemoveUtil, OSDRemovalQueue, OSD +from cephadm.services.osd import OSDRemovalQueue, OSD import pytest -from .fixtures import rm_util, osd_obj, cephadm_module from tests import mock from datetime import datetime diff --git a/src/pybind/mgr/cephadm/tests/test_services.py b/src/pybind/mgr/cephadm/tests/test_services.py index 4891b81ac00..0411b3a87b1 100644 --- a/src/pybind/mgr/cephadm/tests/test_services.py +++ b/src/pybind/mgr/cephadm/tests/test_services.py @@ -3,10 +3,10 @@ import pytest from unittest.mock import MagicMock, call from cephadm.services.cephadmservice import MonService, MgrService, MdsService, RgwService, \ - RbdMirrorService, CrashService, CephadmService, AuthEntity, CephadmExporter + RbdMirrorService, CrashService, CephadmExporter from cephadm.services.iscsi import IscsiService from cephadm.services.nfs import NFSService -from cephadm.services.osd import RemoveUtil, OSDRemovalQueue, OSDService, OSD, NotFoundError +from cephadm.services.osd import OSDService from cephadm.services.monitoring import GrafanaService, AlertmanagerService, PrometheusService, \ NodeExporterService from ceph.deployment.service_spec import IscsiServiceSpec diff --git a/src/pybind/mgr/cephadm/tests/test_spec.py b/src/pybind/mgr/cephadm/tests/test_spec.py index 586344bee9b..2018fa2cf35 100644 --- a/src/pybind/mgr/cephadm/tests/test_spec.py +++ b/src/pybind/mgr/cephadm/tests/test_spec.py @@ -9,8 +9,7 @@ import pytest import yaml from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec, RGWSpec, \ - IscsiServiceSpec, AlertManagerSpec, HostPlacementSpec, CustomContainerSpec, \ - HA_RGWSpec + IscsiServiceSpec, AlertManagerSpec, HostPlacementSpec, CustomContainerSpec from orchestrator import DaemonDescription, OrchestratorError diff --git a/src/pybind/mgr/cephadm/tests/test_template.py b/src/pybind/mgr/cephadm/tests/test_template.py index 40b783bdbf9..f6730434860 100644 --- a/src/pybind/mgr/cephadm/tests/test_template.py +++ b/src/pybind/mgr/cephadm/tests/test_template.py @@ -2,7 +2,6 @@ import pathlib import pytest -from cephadm.tests.fixtures import cephadm_module from cephadm.template import TemplateMgr, UndefinedError, TemplateNotFoundError diff --git a/src/pybind/mgr/cephadm/tests/test_upgrade.py b/src/pybind/mgr/cephadm/tests/test_upgrade.py index 7d4f091e9c5..22881119159 100644 --- a/src/pybind/mgr/cephadm/tests/test_upgrade.py +++ b/src/pybind/mgr/cephadm/tests/test_upgrade.py @@ -7,7 +7,7 @@ from ceph.deployment.service_spec import ServiceSpec from cephadm import CephadmOrchestrator from cephadm.upgrade import CephadmUpgrade from cephadm.serve import CephadmServe -from .fixtures import _run_cephadm, wait, cephadm_module, with_host, with_service +from .fixtures import _run_cephadm, wait, with_host, with_service @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}')) diff --git a/src/pybind/mgr/cephadm/upgrade.py b/src/pybind/mgr/cephadm/upgrade.py index 00941f6a667..f55751c3f30 100644 --- a/src/pybind/mgr/cephadm/upgrade.py +++ b/src/pybind/mgr/cephadm/upgrade.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Optional, Dict, List import orchestrator from cephadm.serve import CephadmServe from cephadm.utils import ceph_release_to_major, name_to_config_section, CEPH_UPGRADE_ORDER -from orchestrator import OrchestratorError, DaemonDescription, daemon_type_to_service, service_to_daemon_types +from orchestrator import OrchestratorError, DaemonDescription, daemon_type_to_service if TYPE_CHECKING: from .module import CephadmOrchestrator diff --git a/src/pybind/mgr/orchestrator/__init__.py b/src/pybind/mgr/orchestrator/__init__.py index 4bcb26cabfa..367f7b55d42 100644 --- a/src/pybind/mgr/orchestrator/__init__.py +++ b/src/pybind/mgr/orchestrator/__init__.py @@ -1,8 +1,4 @@ from __future__ import absolute_import -import os - -if 'UNITTEST' in os.environ: - import tests from .module import OrchestratorCli @@ -17,3 +13,39 @@ from ._interface import \ OrchestratorEvent, set_exception_subject, \ InventoryHost, DeviceLightLoc, \ UpgradeStatusSpec, daemon_type_to_service, service_to_daemon_types + +__all__ = [ + 'OrchestratorCli', + 'Completion', + 'TrivialReadCompletion', + 'raise_if_exception', + 'ProgressReference', + 'pretty_print', + '_Promise', + 'CLICommand', + '_cli_write_command', + '_cli_read_command', + 'CLICommandMeta', + 'Orchestrator', + 'OrchestratorClientMixin', + 'OrchestratorValidationError', + 'OrchestratorError', + 'NoOrchestrator', + 'ServiceDescription', + 'InventoryFilter', + 'HostSpec', + 'DaemonDescription', + 'OrchestratorEvent', + 'set_exception_subject', + 'InventoryHost', + 'DeviceLightLoc', + 'UpgradeStatusSpec', + 'daemon_type_to_service', + 'service_to_daemon_types', + +] + +import os +if 'UNITTEST' in os.environ: + import tests + __all__.append(tests.__name__) diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 23c4247870b..16aa8bc425b 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -13,14 +13,14 @@ from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection from ceph.deployment.service_spec import PlacementSpec, ServiceSpec from ceph.utils import datetime_now -from mgr_util import format_bytes, to_pretty_timedelta, format_dimless +from mgr_util import to_pretty_timedelta, format_dimless from mgr_module import MgrModule, HandleCommandResult, Option from ._interface import OrchestratorClientMixin, DeviceLightLoc, _cli_read_command, \ raise_if_exception, _cli_write_command, TrivialReadCompletion, OrchestratorError, \ - NoOrchestrator, OrchestratorValidationError, NFSServiceSpec, HA_RGWSpec, \ + NoOrchestrator, OrchestratorValidationError, NFSServiceSpec, \ RGWSpec, InventoryFilter, InventoryHost, HostSpec, CLICommandMeta, \ - ServiceDescription, DaemonDescription, IscsiServiceSpec, json_to_generic_spec, GenericSpec + ServiceDescription, DaemonDescription, IscsiServiceSpec, json_to_generic_spec def nice_delta(now: datetime.datetime, t: Optional[datetime.datetime], suffix: str = '') -> str: diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index d2951143e55..ab038041980 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -12,7 +12,6 @@ requires = cython max-line-length = 100 ignore = E501, - F401, F811, W503, exclude = -- 2.39.5