Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed Feb 4, 2024
1 parent c484c4b commit a3ec5fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions aiidalab_launch/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def remove(self, conda: bool = False, data: bool = False) -> None:
try:
self.client.volumes.get(self.profile.conda_volume_name()).remove()
except docker.errors.NotFound: # already removed
LOGGER.info(
LOGGER.warning(
f"Failed to remove conda volume '{self.profile.conda_volume_name()}', likely already removed."
)
except Exception as error: # unexpected error
Expand All @@ -243,9 +243,10 @@ def remove(self, conda: bool = False, data: bool = False) -> None:
home_mount_path = PurePosixPath(self.profile.home_mount)
try:
if home_mount_path.is_absolute():
# TODO: Perhaps we should ask user for confirmation here?
rmtree(home_mount_path)
else:
self.client.volumes.get(str(home_mount_path)).remove()
self.client.volumes.get(self.profile.home_mount).remove()
except docker.errors.NotFound:
pass # already removed
except Exception as error: # unexpected error
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ def instance(docker_client, profile):
def remove_extra_mounts():
for extra_mount in instance.profile.extra_mounts:
mount = ExtraMount.parse_mount_string(extra_mount)
# TODO: Rmtree on bind mount? Maybe for safety let's just keep them in /tmp
# NOTE: We should also remove test bind mounts, but it feels pretty dangerous,
# we do not want to accidentaly remove users' home (even though we monkeypatch it).
if mount["Type"] == "volume":
docker_client.volumes.get(mount["Source"]).remove()
print(mount)

for op in (
instance.stop,
Expand All @@ -156,7 +156,7 @@ def remove_extra_mounts():
try:
op()
except (docker.errors.NotFound, RequiresContainerInstance):
pass
continue
except (RuntimeError, docker.errors.APIError) as error:
print(
f"WARNING: Issue while stopping/removing instance: {error}",
Expand Down

0 comments on commit a3ec5fd

Please sign in to comment.