Skip to content

Commit

Permalink
Fix: bootstrap: Improve sync_files_to_disk function (bsc#1219537) (#1653
Browse files Browse the repository at this point in the history
)

Filter out the files that not exist in local and remote
  • Loading branch information
liangxin1300 authored Jan 3, 2025
2 parents 150f4c8 + 270eb99 commit 44145ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 16 additions & 3 deletions crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion test/unittests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 44145ae

Please sign in to comment.