diff --git a/aiidalab_launch/instance.py b/aiidalab_launch/instance.py index abe0d44..59f0444 100644 --- a/aiidalab_launch/instance.py +++ b/aiidalab_launch/instance.py @@ -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 @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index fe92cbe..67c9c60 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, @@ -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}",