clan-cli: Fix tmpdir leak and fix tests/temporary_dir inconsistencies
This commit is contained in:
parent
0676bf7283
commit
e6ad0cfbc1
@ -3,6 +3,7 @@ import importlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from contextlib import ExitStack
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
@ -108,6 +109,7 @@ def run_vm(
|
||||
socketdir: Path | None = None,
|
||||
nix_options: list[str] = [],
|
||||
) -> None:
|
||||
with ExitStack() as stack:
|
||||
machine = Machine(vm.machine_name, vm.flake_url)
|
||||
log.debug(f"Creating VM for {machine}")
|
||||
|
||||
@ -117,12 +119,12 @@ def run_vm(
|
||||
cache.mkdir(exist_ok=True)
|
||||
|
||||
if cachedir is None:
|
||||
cache_tmp = TemporaryDirectory(dir=cache)
|
||||
cachedir = Path(cache_tmp.name)
|
||||
cache_tmp = stack.enter_context(TemporaryDirectory(dir=cache))
|
||||
cachedir = Path(cache_tmp)
|
||||
|
||||
if socketdir is None:
|
||||
socket_tmp = TemporaryDirectory()
|
||||
socketdir = Path(socket_tmp.name)
|
||||
socket_tmp = stack.enter_context(TemporaryDirectory())
|
||||
socketdir = Path(socket_tmp)
|
||||
|
||||
# TODO: We should get this from the vm argument
|
||||
nixos_config = build_vm(machine, cachedir, nix_options)
|
||||
|
@ -16,6 +16,7 @@ def temporary_home(monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]:
|
||||
path = Path(env_dir).resolve()
|
||||
log.debug("Temp HOME directory: %s", str(path))
|
||||
monkeypatch.setenv("HOME", str(path))
|
||||
monkeypatch.setenv("XDG_CONFIG_HOME", str(path / ".config"))
|
||||
monkeypatch.chdir(str(path))
|
||||
yield path
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user