From: Kyr Shatskyy Date: Thu, 16 Jul 2020 17:35:11 +0000 (+0200) Subject: misc: optimize append_lines_to_file() to reuse remote.write_file X-Git-Tag: 1.1.0~48^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=243ff3bbf218102b24ed992e3931bf8c76cdaadd;p=teuthology.git misc: optimize append_lines_to_file() to reuse remote.write_file The misc.append_lines_to_file method has been using get remote file to temporary file and then write back to remote host. The orchestra.remote.write_file method has 'append' parameter when using which there is no data downloaded from remote host. Signed-off-by: Kyr Shatskyy --- diff --git a/teuthology/misc.py b/teuthology/misc.py index e6041d7025..b66e78c0ca 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -656,22 +656,8 @@ def remove_lines_from_file(remote, path, line_is_valid_test, def append_lines_to_file(remote, path, lines, sudo=False): """ Append lines to a file. - An intermediate file is used in the same manner as in - Remove_lines_from_list. """ - - temp_file_path = remote.mktemp() - - data = get_file(remote, path, sudo).decode() - - # add the additional data and write it back out, using a temp file - # in case of connectivity of loss, and then mv it to the - # actual desired location - data += lines - write_file(remote, temp_file_path, data) - - # then do a 'mv' to the actual file location - move_file(remote, temp_file_path, path, sudo) + remote.write_file(path, lines, append=True, sudo=sudo) def prepend_lines_to_file(remote, path, lines, sudo=False): """