From 6c57113b1815c70cbe0844ffd1cbfb87d1f9d955 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Thu, 7 Oct 2021 10:18:00 -0600 Subject: [PATCH] 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 --- src/pybind/mgr/cephadm/ssh.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/ssh.py b/src/pybind/mgr/cephadm/ssh.py index a9d83d7e16845..57c3ecd798294 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}" -- 2.39.5