From: Michael Fritch Date: Thu, 7 Oct 2021 16:18:00 +0000 (-0600) Subject: mgr/cephadm: use `asyncssh.scp` to write remote files X-Git-Tag: v17.1.0~719^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6c57113b1815c70cbe0844ffd1cbfb87d1f9d955;p=ceph.git mgr/cephadm: use `asyncssh.scp` to write remote files `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 --- diff --git a/src/pybind/mgr/cephadm/ssh.py b/src/pybind/mgr/cephadm/ssh.py index a9d83d7e168..57c3ecd7982 100644 --- a/src/pybind/mgr/cephadm/ssh.py +++ b/src/pybind/mgr/cephadm/ssh.py @@ -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}"