]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: improve asyncssh type checking 44760/head
authorMichael Fritch <mfritch@suse.com>
Mon, 24 Jan 2022 19:39:15 +0000 (12:39 -0700)
committerMichael Fritch <mfritch@suse.com>
Tue, 25 Jan 2022 18:10:04 +0000 (11:10 -0700)
asyncssh 2.9.0 introduces additional type hints

Fixes: https://tracker.ceph.com/issues/54003
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/ssh.py
src/pybind/mgr/requirements.txt

index b45f4a2c3e52f3df4dc956cd8835de8e10e5c1ff..f59ade2c79af755aec320fb70947ca94f62240f5 100644 (file)
@@ -63,7 +63,7 @@ from .configchecks import CephadmConfigChecks
 try:
     import asyncssh
 except ImportError as e:
-    asyncssh = None
+    asyncssh = None  # type: ignore
     asyncssh_import_error = str(e)
 
 logger = logging.getLogger(__name__)
index 7c438e897ac2335794dd1bc707f8ec8d2f72383d..034688023e9bff00bbc054af47e95b8d7500ec4f 100644 (file)
@@ -6,13 +6,13 @@ from threading import Thread
 from contextlib import contextmanager
 from io import StringIO
 from shlex import quote
-from typing import TYPE_CHECKING, Optional, List, Tuple, Dict, Iterator, TypeVar, Awaitable
+from typing import TYPE_CHECKING, Optional, List, Tuple, Dict, Iterator, TypeVar, Awaitable, Union
 from orchestrator import OrchestratorError
 
 try:
     import asyncssh
 except ImportError:
-    asyncssh = None
+    asyncssh = None  # type: ignore
 
 if TYPE_CHECKING:
     from cephadm.module import CephadmOrchestrator
@@ -85,8 +85,8 @@ class SSHManager:
             self.cons[host] = conn
 
         self.mgr.offline_hosts_remove(host)
-        conn = self.cons.get(host)
-        return conn
+
+        return self.cons[host]
 
     @contextmanager
     def redirect_log(self, host: str, addr: str) -> Iterator[None]:
@@ -144,9 +144,22 @@ class SSHManager:
             await self._reset_con(host)
             self.mgr.offline_hosts.add(host)
             raise OrchestratorError(f'Unable to reach remote host {host}. {str(e)}')
-        out = r.stdout.rstrip('\n')
-        err = r.stderr.rstrip('\n')
-        return out, err, r.returncode
+
+        def _rstrip(v: Union[bytes, str, None]) -> str:
+            if not v:
+                return ''
+            if isinstance(v, str):
+                return v.rstrip('\n')
+            if isinstance(v, bytes):
+                return v.decode().rstrip('\n')
+            raise OrchestratorError(
+                f'Unable to parse ssh output with type {type(v)} from remote host {host}')
+
+        out = _rstrip(r.stdout)
+        err = _rstrip(r.stderr)
+        rc = r.returncode if r.returncode else 0
+
+        return out, err, rc
 
     def execute_command(self,
                         host: str,
index fd6d938a01e85a845adfbf4fc63a0618c32f7f9a..9ee93f481be38e02132b4aa48905b8acf3a2322b 100644 (file)
@@ -1,3 +1,3 @@
 -rrequirements-required.txt
-asyncssh==2.8
+asyncssh==2.9
 kubernetes==11.0.0