Skip to content

Commit d97ffed

Browse files
authored
[Logs] Fix logs download (skypilot-org#1502)
* fix the rsync * format * lint * reorganize * Add test * add comment
1 parent c6066dd commit d97ffed

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

sky/utils/command_runner.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -298,31 +298,34 @@ def rsync(
298298
# --filter
299299
rsync_command.append(RSYNC_FILTER_OPTION)
300300

301-
# --exclude-from
302-
resolved_source = pathlib.Path(source).expanduser().resolve()
303-
if (resolved_source / GIT_EXCLUDE).exists():
304-
# Ensure file exists; otherwise, rsync will error out.
305-
rsync_command.append(
306-
RSYNC_EXCLUDE_OPTION.format(str(resolved_source / GIT_EXCLUDE)))
307-
308-
# rsync doesn't support '~' in a quoted target path. need to expand it.
309-
full_source_str = str(resolved_source)
310-
if resolved_source.is_dir():
311-
full_source_str = os.path.join(full_source_str, '')
301+
if up:
302+
# The source is a local path, so we need to resolve it.
303+
# --exclude-from
304+
resolved_source = pathlib.Path(source).expanduser().resolve()
305+
if (resolved_source / GIT_EXCLUDE).exists():
306+
# Ensure file exists; otherwise, rsync will error out.
307+
rsync_command.append(
308+
RSYNC_EXCLUDE_OPTION.format(
309+
str(resolved_source / GIT_EXCLUDE)))
312310

313311
ssh_options = ' '.join(
314312
ssh_options_list(self.ssh_private_key, self.ssh_control_name))
315313
rsync_command.append(f'-e "ssh {ssh_options}"')
316314
# To support spaces in the path, we need to quote source and target.
315+
# rsync doesn't support '~' in a quoted local path, but it is ok to
316+
# have '~' in a quoted remote path.
317317
if up:
318+
full_source_str = str(resolved_source)
319+
if resolved_source.is_dir():
320+
full_source_str = os.path.join(full_source_str, '')
318321
rsync_command.extend([
319322
f'{full_source_str!r}',
320323
f'{self.ssh_user}@{self.ip}:{target!r}',
321324
])
322325
else:
323326
rsync_command.extend([
324-
f'{self.ssh_user}@{self.ip}:{full_source_str!r}',
325-
f'{target!r}',
327+
f'{self.ssh_user}@{self.ip}:{source!r}',
328+
f'{os.path.expanduser(target)!r}',
326329
])
327330
command = ' '.join(rsync_command)
328331

tests/test_smoke.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def test_minimal():
138138
f'sky launch -y -c {name} examples/minimal.yaml',
139139
f'sky logs {name} 2 --status',
140140
f'sky logs {name} --status | grep "Job 2: SUCCEEDED"', # Equivalent.
141+
# Check the logs downloading
142+
f'log_path=$(sky logs {name} 2 --sync-down | tail -n 1 | sed -E "s/^.*Job 2 logs: (.*)\\x1b\\[0m/\\1/g") && echo $log_path && test -f $log_path/run.log',
141143
# Ensure the raylet process has the correct file descriptor limit.
142144
f'sky exec {name} "prlimit -n --pid=\$(pgrep -f \'raylet/raylet --raylet_socket_name\') | grep \'"\'1048576 1048576\'"\'"',
143145
f'sky logs {name} 3 --status', # Ensure the job succeeded.

0 commit comments

Comments
 (0)