]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/rgw: fix module crash because of typing_extensions missing
authorRedouane Kachach <rkachach@redhat.com>
Tue, 7 Feb 2023 18:04:57 +0000 (19:04 +0100)
committerAdam King <adking@redhat.com>
Wed, 5 Apr 2023 17:35:18 +0000 (13:35 -0400)
Fixes: https://tracker.ceph.com/issues/58660
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
(cherry picked from commit 68fb4eee52b84e3cde5b9dbc44bf599904275ea3)

src/pybind/mgr/rgw/module.py

index d1fc1420eb7af8e54d99ae601bfd23a7b7feaa2d..bb1f9460025780c9726d604d645af67de95cd759 100644 (file)
@@ -10,7 +10,7 @@ from mgr_module import MgrModule, CLICommand, HandleCommandResult, Option
 import orchestrator
 
 from ceph.deployment.service_spec import RGWSpec, PlacementSpec, SpecValidationError
-from typing import Any, Optional, Sequence, Iterator, List, Callable, TypeVar, cast, Dict, Tuple, Union
+from typing import Any, Optional, Sequence, Iterator, List, Callable, TypeVar, cast, Dict, Tuple, Union, TYPE_CHECKING
 
 from ceph.rgw.types import RGWAMException, RGWAMEnvMgr, RealmToken
 from ceph.rgw.rgwam_core import EnvArgs, RGWAM
@@ -19,28 +19,30 @@ from orchestrator import OrchestratorClientMixin, OrchestratorError, DaemonDescr
 
 FuncT = TypeVar('FuncT', bound=Callable[..., Any])
 
-# this uses a version check as opposed to a try/except because this
-# form makes mypy happy and try/except doesn't.
-if sys.version_info >= (3, 8):
-    from typing import Protocol
+if TYPE_CHECKING:
+    # this uses a version check as opposed to a try/except because this
+    # form makes mypy happy and try/except doesn't.
+    if sys.version_info >= (3, 8):
+        from typing import Protocol
+    else:
+        from typing_extensions import Protocol
+
+    class MgrModuleProtocol(Protocol):
+        def tool_exec(self, args: List[str]) -> Tuple[int, str, str]:
+            ...
+
+        def apply_rgw(self, spec: RGWSpec) -> OrchResult[str]:
+            ...
+
+        def list_daemons(self, service_name: Optional[str] = None,
+                         daemon_type: Optional[str] = None,
+                         daemon_id: Optional[str] = None,
+                         host: Optional[str] = None,
+                         refresh: bool = False) -> OrchResult[List['DaemonDescription']]:
+            ...
 else:
-    # typing_extensions will not be available for the real mgr server
-    from typing_extensions import Protocol
-
-
-class MgrModuleProtocol(Protocol):
-    def tool_exec(self, args: List[str]) -> Tuple[int, str, str]:
-        ...
-
-    def apply_rgw(self, spec: RGWSpec) -> OrchResult[str]:
-        ...
-
-    def list_daemons(self, service_name: Optional[str] = None,
-                     daemon_type: Optional[str] = None,
-                     daemon_id: Optional[str] = None,
-                     host: Optional[str] = None,
-                     refresh: bool = False) -> OrchResult[List['DaemonDescription']]:
-        ...
+    class MgrModuleProtocol:
+        pass
 
 
 class RGWSpecParsingError(Exception):