]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc: optimize append_lines_to_file() to reuse remote.write_file
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Thu, 16 Jul 2020 17:35:11 +0000 (19:35 +0200)
committerKyr Shatskyy <kyrylo.shatskyy@suse.com>
Thu, 3 Sep 2020 21:43:48 +0000 (23:43 +0200)
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 <kyrylo.shatskyy@suse.com>
teuthology/misc.py

index e6041d7025649a77b2aeee4acac4c112936fa0bc..b66e78c0ca7cac6143e7572a6c0cd42132b47dd6 100644 (file)
@@ -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):
     """