From 52c20e5551730d27f535cc00ab5f94e8b2f5da4f Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Thu, 7 Oct 2021 10:17:28 -0600 Subject: [PATCH] mgr/cephadm: use str type for `stdin` avoid encode/decode confusion by using a str data type to both send (stdin) and receive (stdout) data Signed-off-by: Michael Fritch --- src/pybind/mgr/cephadm/serve.py | 6 +++--- src/pybind/mgr/cephadm/ssh.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 1cf024fac310a..446860442f312 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -1270,14 +1270,14 @@ class CephadmServe: try: out, err, code = self.mgr.ssh.execute_command( - host, cmd, stdin=stdin.encode('utf-8') if stdin else None, addr=addr) + host, cmd, stdin=stdin, addr=addr) if code == 2: ls_cmd = ['ls', self.mgr.cephadm_binary_path] out_ls, err_ls, code_ls = self.mgr.ssh.execute_command(host, ls_cmd, addr=addr) if code_ls == 2: self._deploy_cephadm_binary(host, addr) out, err, code = self.mgr.ssh.execute_command( - host, cmd, stdin=stdin.encode('utf-8') if stdin else None, addr=addr) + host, cmd, stdin=stdin, addr=addr) except Exception as e: self.mgr.ssh._reset_con(host) @@ -1289,7 +1289,7 @@ class CephadmServe: try: cmd = ['/usr/bin/cephadm'] + final_args out, err, code = self.mgr.ssh.execute_command( - host, cmd, stdin=stdin.encode('utf-8') if stdin else None, addr=addr) + host, cmd, stdin=stdin, addr=addr) except Exception as e: self.mgr.ssh._reset_con(host) if error_ok: diff --git a/src/pybind/mgr/cephadm/ssh.py b/src/pybind/mgr/cephadm/ssh.py index 57c3ecd798294..eb13496027611 100644 --- a/src/pybind/mgr/cephadm/ssh.py +++ b/src/pybind/mgr/cephadm/ssh.py @@ -128,14 +128,14 @@ class SSHManager: async def _execute_command(self, host: str, cmd: List[str], - stdin: Optional[bytes] = None, + stdin: Optional[str] = None, addr: Optional[str] = None, ) -> Tuple[str, str, int]: conn = await self._remote_connection(host, addr) cmd = "sudo " + " ".join(quote(x) for x in cmd) logger.debug(f'Running command: {cmd}') try: - r = await conn.run(cmd, input=stdin.decode() if stdin else None) + r = await conn.run(cmd, input=stdin) # handle these Exceptions otherwise you might get a weird error like TypeError: __init__() missing 1 required positional argument: 'reason' (due to the asyncssh error interacting with raise_if_exception) except (asyncssh.ChannelOpenError, Exception) as e: # SSH connection closed or broken, will create new connection next call @@ -150,7 +150,7 @@ class SSHManager: def execute_command(self, host: str, cmd: List[str], - stdin: Optional[bytes] = None, + stdin: Optional[str] = None, addr: Optional[str] = None, ) -> Tuple[str, str, int]: return self.mgr.event_loop.get_result(self._execute_command(host, cmd, stdin, addr)) @@ -158,7 +158,7 @@ class SSHManager: async def _check_execute_command(self, host: str, cmd: List[str], - stdin: Optional[bytes] = None, + stdin: Optional[str] = None, addr: Optional[str] = None, ) -> str: out, err, code = await self._execute_command(host, cmd, stdin, addr) @@ -171,7 +171,7 @@ class SSHManager: def check_execute_command(self, host: str, cmd: List[str], - stdin: Optional[bytes] = None, + stdin: Optional[str] = None, addr: Optional[str] = None, ) -> str: return self.mgr.event_loop.get_result(self._check_execute_command(host, cmd, stdin, addr)) -- 2.39.5