From 6bd7204bed48d64e92e1ea472e6b14e3bae1b409 Mon Sep 17 00:00:00 2001 From: xin liang Date: Thu, 2 Jan 2025 17:28:02 +0800 Subject: [PATCH 1/2] Fix: bootstrap: Improve sync_files_to_disk function (bsc#1219537) Filter out the files that not exist in local and remote --- crmsh/bootstrap.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crmsh/bootstrap.py b/crmsh/bootstrap.py index f76cde87c..d83a1a67d 100644 --- a/crmsh/bootstrap.py +++ b/crmsh/bootstrap.py @@ -1882,9 +1882,22 @@ def sync_files_to_disk(): """ Sync file content to disk between cluster nodes """ - files_string = ' '.join(filter(lambda f: os.path.isfile(f), FILES_TO_SYNC)) - if files_string: - utils.cluster_run_cmd("sync {}".format(files_string.strip())) + target_files_str = "" + + for f in FILES_TO_SYNC: + # check if the file exists on the local node + if not os.path.isfile(f): + continue + try: + # check if the file exists on the remote node + utils.cluster_run_cmd(f"test -f {f}") + except ValueError: + continue + else: + target_files_str += f + " " + + if target_files_str: + utils.cluster_run_cmd(f"sync {target_files_str.strip()}") def detect_mountpoint(seed_host: str) -> None: From 270eb99fa4a384117d235b26b6ef62d224b49123 Mon Sep 17 00:00:00 2001 From: xin liang Date: Thu, 2 Jan 2025 21:39:50 +0800 Subject: [PATCH 2/2] Dev: unittests: Adjust unit test for previous commit --- test/unittests/test_bootstrap.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unittests/test_bootstrap.py b/test/unittests/test_bootstrap.py index 4f6cd49a3..69bc44c16 100644 --- a/test/unittests/test_bootstrap.py +++ b/test/unittests/test_bootstrap.py @@ -1323,7 +1323,11 @@ def test_sync_files_to_disk(self, mock_isfile, mock_cluster_cmd): mock_isfile.side_effect = [True, True] bootstrap.sync_files_to_disk() mock_isfile.assert_has_calls([mock.call("file1"), mock.call("file2")]) - mock_cluster_cmd.assert_called_once_with("sync file1 file2") + mock_cluster_cmd.assert_has_calls([ + mock.call("test -f file1"), + mock.call("test -f file2"), + mock.call("sync file1 file2") + ]) @mock.patch('logging.Logger.debug') @mock.patch('crmsh.sh.ClusterShell.get_stdout_or_raise_error')