Skip to content

Commit

Permalink
Merge pull request #202 from NVIDIA/am/abs-docker-path
Browse files Browse the repository at this point in the history
Always return an absolute path to cached docker image
  • Loading branch information
amaslenn authored Sep 24, 2024
2 parents 178a80e + c0a0dc8 commit c3542c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/cloudai/util/docker_image_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, success: bool, docker_image_path: Optional[Path] = None, mess
message (str): A message providing additional information about the result.
"""
self.success = success
self.docker_image_path = docker_image_path or Path()
self._docker_image_path = docker_image_path or Path()
self.message = message

def __bool__(self):
Expand All @@ -103,6 +103,26 @@ def __str__(self):
"""
return self.message

@property
def docker_image_path(self) -> Path:
"""
Get the path to the Docker image.
Returns
Path: Absolute path to the Docker image.
"""
return self._docker_image_path.absolute()

@docker_image_path.setter
def docker_image_path(self, value: Path) -> None:
"""
Set the path to the Docker image.
Args:
value (Path): The path to the Docker image.
"""
self._docker_image_path = value


class DockerImageCacheManager:
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_docker_image_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,11 @@ def test_check_docker_image_accessibility_with_enroot(mock_tempdir, mock_which,
command = mock_popen.call_args[0][0]
assert "enroot import -o" in command
assert "docker://docker.io/hello-world" in command


def test_docker_image_path_is_always_absolute():
r = DockerImageCacheResult(True, Path("relative/path"), "message")
assert r.docker_image_path.is_absolute()

r.docker_image_path = Path("another/relative/path")
assert r.docker_image_path.is_absolute()

0 comments on commit c3542c7

Please sign in to comment.