]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: use `asyncssh.scp` to write remote files
authorMichael Fritch <mfritch@suse.com>
Thu, 7 Oct 2021 16:18:00 +0000 (10:18 -0600)
committerMichael Fritch <mfritch@suse.com>
Thu, 7 Oct 2021 23:55:05 +0000 (17:55 -0600)
`tee` via stdin happens to work when the file is a utf-8 byte encoded
string, but won't work if the file happens to be binary data

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

index a9d83d7e1684505ca7cc95fa284ba962de58c9a5..57c3ecd79829447780301f9b81afbc13fa934de3 100644 (file)
@@ -194,7 +194,12 @@ class SSHManager:
                 # shlex quote takes str or byte object, not int
                 await self._check_execute_command(host, ['chown', '-R', str(uid) + ':' + str(gid), tmp_path], addr=addr)
                 await self._check_execute_command(host, ['chmod', oct(mode)[2:], tmp_path], addr=addr)
-            await self._check_execute_command(host, ['tee', '-', tmp_path], stdin=content, addr=addr)
+            with NamedTemporaryFile(prefix='cephadm-write-remote-file-') as f:
+                os.fchmod(f.fileno(), 0o600)
+                f.write(content)
+                f.flush()
+                conn = await self._remote_connection(host, addr)
+                await asyncssh.scp(f.name, (conn, tmp_path))
             await self._check_execute_command(host, ['mv', tmp_path, path], addr=addr)
         except Exception as e:
             msg = f"Unable to write {host}:{path}: {e}"