From 64bde24917868a9e8156e57ca7ecff7d1dbf85a2 Mon Sep 17 00:00:00 2001 From: Israel Fruchter Date: Wed, 8 Nov 2023 00:24:37 +0200 Subject: [PATCH] fix(remote_file): write inplace into the file 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 --- sdcm/remote/remote_file.py | 6 +++++- unit_tests/test_remoter.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sdcm/remote/remote_file.py b/sdcm/remote/remote_file.py index de11f08644..37d124b2df 100644 --- a/sdcm/remote/remote_file.py +++ b/sdcm/remote/remote_file.py @@ -20,6 +20,7 @@ import yaml from sdcm import wait +from sdcm.remote import shell_script_cmd LOGGER = logging.getLogger(__name__) @@ -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}", diff --git a/unit_tests/test_remoter.py b/unit_tests/test_remoter.py index 95bf47d2f0..ca92859b74 100644 --- a/unit_tests/test_remoter.py +++ b/unit_tests/test_remoter.py @@ -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()