Skip to content

Commit

Permalink
Fix: Error handling and smoke test update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyasKallingal committed Jul 26, 2024
1 parent 2fc73b0 commit 39cd385
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions sky/utils/log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,33 @@ def readable_time_duration(start: Optional[float],


def create_and_symlink_log_dir(log_dir: str):
"""Creates a new log directory and symlinks to it from parent directory.
"""Create a log directory and symlink to it from parent directory.
If file operations fail, will log a warning and return without error.
Args:
log_dir (str): Expanded log directory path.
"""
if log_dir == os.devnull:
try:
os.makedirs(log_dir, exist_ok=True)
except OSError:
logger.warning(f'Failed to create log directory at {log_dir!r}.'
'Check if there is a file with the same name.')
return
os.makedirs(log_dir, exist_ok=True)
symlink_path = os.path.join(log_dir, os.pardir, constants.SKY_LATEST_LINK)
symlink_path = os.path.join(os.path.dirname(os.path.abspath(log_dir)),
constants.SKY_LATEST_LINK)
if os.path.exists(symlink_path):
if os.path.islink(symlink_path):
os.remove(symlink_path)
try:
os.remove(symlink_path)
except OSError:
return
else:
logger.warning(
(f'Failed to symlink to latest logs at \'{symlink_path}\'.'
(f'Failed to symlink to latest logs at {symlink_path!r}.'
'Please remove the existing file/directory.'))
return
os.symlink(log_dir, symlink_path)
try:
os.symlink(log_dir, symlink_path)
except OSError:
return
2 changes: 1 addition & 1 deletion tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ def test_symlink_latest_logs():
test = Test(
'symlink_latest_logs',
[
'sky local up || true',
'sky launch -c test2 --cloud kubernetes -- echo hi || true',
'eval symlink_path="~/sky_logs/sky_latest"; [ -L "$symlink_path" ] || exit 1 ;'
'target_file=$(readlink -f "$symlink_path") || exit 1 ;'
'sky local down || true ;'
Expand Down

0 comments on commit 39cd385

Please sign in to comment.