Skip to content

Commit

Permalink
fix(remote_file): write inplace into the file
Browse files Browse the repository at this point in the history
since in some cases there's a process listing on changes
to this file, doing so with `mv` fails to continue the watch
on those files
  • Loading branch information
fruch authored and soyacz committed Nov 9, 2023
1 parent 1528062 commit 64bde24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion sdcm/remote/remote_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import yaml

from sdcm import wait
from sdcm.remote import shell_script_cmd


LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,7 +65,10 @@ def remote_file(remoter, remote_path, serializer=StringIO.getvalue, deserializer
LOGGER.debug("New content of `%s':\n%s", remote_path, content)

remote_tempfile = remoter.run("mktemp").stdout.strip()
remote_tempfile_move_cmd = f"mv '{remote_tempfile}' '{remote_path}'"
remote_tempfile_move_cmd = shell_script_cmd(f"""\
cat '{remote_tempfile}' > '{remote_path}'
rm '{remote_tempfile}'
""")
wait.wait_for(remoter.send_files,
step=10,
text=f"Waiting for updating of `{remote_path}' on {remoter.hostname}",
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/test_remoter.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_remote_file(self):
self.assertEqual(remoter.rf_dst, remoter.sf_src)
self.assertEqual(remoter.sf_data, "test data")
self.assertFalse(os.path.exists(remoter.sf_src))
self.assertEqual(remoter.command_to_run, f"mv 'temporary' '{some_file}'")
self.assertEqual(remoter.command_to_run, f'bash -cxe "cat \'temporary\' > \'{some_file}\'\nrm \'temporary\'\n"')

def test_remote_file_preserve_ownership(self):
remoter = self.remoter_cls()
Expand Down

0 comments on commit 64bde24

Please sign in to comment.