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 json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from contextlib import ExitStack
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
@ -108,6 +109,7 @@ def run_vm(
|
|||||||
socketdir: Path | None = None,
|
socketdir: Path | None = None,
|
||||||
nix_options: list[str] = [],
|
nix_options: list[str] = [],
|
||||||
) -> None:
|
) -> None:
|
||||||
|
with ExitStack() as stack:
|
||||||
machine = Machine(vm.machine_name, vm.flake_url)
|
machine = Machine(vm.machine_name, vm.flake_url)
|
||||||
log.debug(f"Creating VM for {machine}")
|
log.debug(f"Creating VM for {machine}")
|
||||||
|
|
||||||
@ -117,12 +119,12 @@ def run_vm(
|
|||||||
cache.mkdir(exist_ok=True)
|
cache.mkdir(exist_ok=True)
|
||||||
|
|
||||||
if cachedir is None:
|
if cachedir is None:
|
||||||
cache_tmp = TemporaryDirectory(dir=cache)
|
cache_tmp = stack.enter_context(TemporaryDirectory(dir=cache))
|
||||||
cachedir = Path(cache_tmp.name)
|
cachedir = Path(cache_tmp)
|
||||||
|
|
||||||
if socketdir is None:
|
if socketdir is None:
|
||||||
socket_tmp = TemporaryDirectory()
|
socket_tmp = stack.enter_context(TemporaryDirectory())
|
||||||
socketdir = Path(socket_tmp.name)
|
socketdir = Path(socket_tmp)
|
||||||
|
|
||||||
# TODO: We should get this from the vm argument
|
# TODO: We should get this from the vm argument
|
||||||
nixos_config = build_vm(machine, cachedir, nix_options)
|
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()
|
path = Path(env_dir).resolve()
|
||||||
log.debug("Temp HOME directory: %s", str(path))
|
log.debug("Temp HOME directory: %s", str(path))
|
||||||
monkeypatch.setenv("HOME", str(path))
|
monkeypatch.setenv("HOME", str(path))
|
||||||
|
monkeypatch.setenv("XDG_CONFIG_HOME", str(path / ".config"))
|
||||||
monkeypatch.chdir(str(path))
|
monkeypatch.chdir(str(path))
|
||||||
yield path
|
yield path
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user