]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: use str type for `stdin` 43458/head
authorMichael Fritch <mfritch@suse.com>
Thu, 7 Oct 2021 16:17:28 +0000 (10:17 -0600)
committerMichael Fritch <mfritch@suse.com>
Thu, 7 Oct 2021 23:57:12 +0000 (17:57 -0600)
avoid encode/decode confusion by using a str data type to both
send (stdin) and receive (stdout) data

Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/cephadm/serve.py
src/pybind/mgr/cephadm/ssh.py

index 1cf024fac310a9889b8df62223844840e9e4b6ea..446860442f31232cd29a6eea18364ea809c63d30 100644 (file)
@@ -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:
index 57c3ecd79829447780301f9b81afbc13fa934de3..eb1349602761107a8a4437ac62482ee38ee23293 100644 (file)
@@ -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))