Skip to content

Commit 98c4e58

Browse files
authored
Merge pull request #548 from NVIDIA/am/mark-docker-as-installed
Make sure mark_as_installed respects system config
2 parents 43680a9 + aa9c1bd commit 98c4e58

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

src/cloudai/_core/base_installer.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def is_installed(self, items: Iterable[Installable]) -> InstallStatusResult:
150150
logging.debug(f"Installation check for {item!r}: {result.success}, {result.message}")
151151
install_results[item] = result
152152

153-
self._populate_sucessful_install(items, install_results)
153+
self._populate_successful_install(items, install_results)
154154

155155
nfailed = len([result for result in install_results.values() if not result.success])
156156
if nfailed:
@@ -204,7 +204,7 @@ def install(self, items: Iterable[Installable]) -> InstallStatusResult:
204204
logging.error(f"{done}/{total} Installation failed for {item!r}: {e}")
205205
install_results[item] = InstallStatusResult(False, str(e))
206206

207-
self._populate_sucessful_install(items, install_results)
207+
self._populate_successful_install(items, install_results)
208208

209209
all_success = all(result.success for result in install_results.values())
210210
if all_success:
@@ -213,22 +213,13 @@ def install(self, items: Iterable[Installable]) -> InstallStatusResult:
213213
nfailed = len([result for result in install_results.values() if not result.success])
214214
return InstallStatusResult(False, f"{nfailed} item(s) failed to install.", install_results)
215215

216-
def _populate_sucessful_install(
216+
def _populate_successful_install(
217217
self, items: Iterable[Installable], install_results: dict[Installable, InstallStatusResult]
218218
):
219-
dups: dict[Installable, list[Installable]] = {}
220219
for item in self.all_items(items, with_duplicates=True):
221-
if item in dups:
222-
dups[item].append(item)
223-
else:
224-
dups[item] = [item]
225-
226-
for item, res in install_results.items():
227-
if not res.success:
220+
if item not in install_results or not install_results[item].success:
228221
continue
229-
230-
for dup in dups[item]:
231-
self.mark_as_installed_one(dup)
222+
self.mark_as_installed_one(item)
232223

233224
@final
234225
def uninstall(self, items: Iterable[Installable]) -> InstallStatusResult:

src/cloudai/installer/slurm_installer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def is_installed_one(self, item: Installable) -> InstallStatusResult:
145145

146146
def mark_as_installed_one(self, item: Installable) -> InstallStatusResult:
147147
if isinstance(item, DockerImage):
148-
item.installed_path = self.system.install_path / item.cache_filename
148+
if self.system.cache_docker_images_locally:
149+
item.installed_path = self.system.install_path / item.cache_filename
149150
return InstallStatusResult(True)
150151
elif isinstance(item, GitRepo):
151152
item.installed_path = self.system.install_path / item.repo_name

tests/test_base_installer.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_system_installables_are_used(slurm_system: SlurmSystem):
208208
installer.uninstall_one = Mock(return_value=InstallStatusResult(True))
209209
installer.is_installed_one = Mock(return_value=InstallStatusResult(True))
210210
installer.mark_as_installed_one = Mock(return_value=InstallStatusResult(True))
211-
installer._populate_sucessful_install = Mock()
211+
installer._populate_successful_install = Mock()
212212

213213
installer.install([])
214214
assert installer.install_one.call_count == len(slurm_system.system_installables())
@@ -253,3 +253,26 @@ def test_both_is_installed(self, installer: SlurmInstaller):
253253
assert f1._installed_path is not None, "First file is not installed"
254254
assert f2._installed_path is not None, "Second file is not installed"
255255
assert f1._installed_path == f2._installed_path, "Files are installed to different paths"
256+
257+
def test_order_of_items_does_not_matter(self, installer: SlurmInstaller):
258+
f = installer.system.install_path / "file"
259+
f1, f2 = File(src=f), File(src=f)
260+
assert f1._installed_path is None, "First file is installed before testing"
261+
assert f2._installed_path is None, "Second file is installed before testing"
262+
263+
installer._populate_successful_install([f1, f2], {})
264+
assert f1._installed_path is None, "First file was marked as installed, but should not be"
265+
assert f2._installed_path is None, "Second file was marked as installed, but should not be"
266+
267+
installer._populate_successful_install([f1, f2], {f1: InstallStatusResult(success=True)})
268+
assert f1._installed_path is not None, (
269+
"First ('self', present in the statuses) file was not marked as installed"
270+
)
271+
assert f2._installed_path is not None, "Second file was not marked as installed"
272+
273+
f1._installed_path, f2._installed_path = None, None
274+
installer._populate_successful_install([f2, f1], {f1: InstallStatusResult(success=True)})
275+
assert f1._installed_path is not None, (
276+
"First ('self', present in the statuses) file was not marked as installed"
277+
)
278+
assert f2._installed_path is not None, "Second file was not marked as installed"

tests/test_slurm_installer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,16 @@ def test_mark_as_installed(slurm_system: SlurmSystem):
486486
assert res.success
487487
assert docker.installed_path == slurm_system.install_path / docker.cache_filename
488488
assert py_script.git_repo.installed_path == slurm_system.install_path / py_script.git_repo.repo_name
489+
490+
491+
@pytest.mark.parametrize("cache", [True, False])
492+
def test_mark_as_installed_docker_image_system_is_respected(slurm_system: SlurmSystem, cache: bool):
493+
slurm_system.cache_docker_images_locally = cache
494+
docker = DockerImage(url="fake_url/img")
495+
installer = SlurmInstaller(slurm_system)
496+
res = installer.mark_as_installed([docker])
497+
assert res.success
498+
if cache:
499+
assert docker.installed_path == slurm_system.install_path / docker.cache_filename
500+
else:
501+
assert docker.installed_path == docker.url

0 commit comments

Comments
 (0)