nixosTestLib: fix various linting issues
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
"""Nix store setup utilities for VM tests"""
|
"""Nix store setup utilities for VM tests"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -10,7 +9,8 @@ def setup_nix_in_nix(closure_info: str | None) -> None:
|
|||||||
"""Set up Nix store inside test environment
|
"""Set up Nix store inside test environment
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
closure_info: Path to closure info directory containing store-paths file, or None if no closure info
|
closure_info: Path to closure info directory containing store-paths file,
|
||||||
|
or None if no closure info
|
||||||
"""
|
"""
|
||||||
tmpdir = Path(os.environ.get("TMPDIR", "/tmp"))
|
tmpdir = Path(os.environ.get("TMPDIR", "/tmp"))
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ def setup_nix_in_nix(closure_info: str | None) -> None:
|
|||||||
os.environ["NIX_CONFIG"] = "substituters = \ntrusted-public-keys = "
|
os.environ["NIX_CONFIG"] = "substituters = \ntrusted-public-keys = "
|
||||||
|
|
||||||
# Set up environment variables for test environment
|
# Set up environment variables for test environment
|
||||||
os.environ["HOME"] = tmpdir
|
os.environ["HOME"] = str(tmpdir)
|
||||||
os.environ["NIX_STATE_DIR"] = f"{tmpdir}/nix"
|
os.environ["NIX_STATE_DIR"] = f"{tmpdir}/nix"
|
||||||
os.environ["NIX_CONF_DIR"] = f"{tmpdir}/etc"
|
os.environ["NIX_CONF_DIR"] = f"{tmpdir}/etc"
|
||||||
os.environ["IN_NIX_SANDBOX"] = "1"
|
os.environ["IN_NIX_SANDBOX"] = "1"
|
||||||
@@ -41,11 +41,12 @@ def setup_nix_in_nix(closure_info: str | None) -> None:
|
|||||||
with store_paths_file.open() as f:
|
with store_paths_file.open() as f:
|
||||||
store_paths = f.read().strip().split("\n")
|
store_paths = f.read().strip().split("\n")
|
||||||
|
|
||||||
# Copy store paths to test store using external cp command (handles symlinks better)
|
# Copy store paths to test store using external cp command
|
||||||
|
# (handles symlinks better)
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["cp", "--recursive", "--target", f"{tmpdir}/store"] +
|
["cp", "--recursive", "--target", f"{tmpdir}/store"]
|
||||||
[path.strip() for path in store_paths if path.strip()],
|
+ [path.strip() for path in store_paths if path.strip()],
|
||||||
check=True
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load Nix database
|
# Load Nix database
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def check_host_port_open(port: int) -> bool:
|
|||||||
s.settimeout(1)
|
s.settimeout(1)
|
||||||
result = s.connect_ex(("localhost", port))
|
result = s.connect_ex(("localhost", port))
|
||||||
return result == 0
|
return result == 0
|
||||||
except Exception as e:
|
except OSError as e:
|
||||||
print(f"Port check failed: {e}")
|
print(f"Port check failed: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""SSH and test setup utilities"""
|
"""SSH and test setup utilities"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from .nix_setup import setup_nix_in_nix
|
from .nix_setup import setup_nix_in_nix
|
||||||
@@ -34,15 +35,14 @@ def setup_test_environment(
|
|||||||
|
|
||||||
setup_port_forwarding(target, host_port)
|
setup_port_forwarding(target, host_port)
|
||||||
|
|
||||||
ssh_key = os.path.join(temp_dir, "id_ed25519")
|
ssh_key = Path(temp_dir) / "id_ed25519"
|
||||||
with open(ssh_key, "w") as f:
|
with ssh_key.open("w") as f, Path(assets_ssh_privkey).open() as src:
|
||||||
with open(assets_ssh_privkey) as src:
|
f.write(src.read())
|
||||||
f.write(src.read())
|
ssh_key.chmod(0o600)
|
||||||
os.chmod(ssh_key, 0o600)
|
|
||||||
|
|
||||||
# Copy test flake to temp directory
|
# Copy test flake to temp directory
|
||||||
flake_dir = os.path.join(temp_dir, "test-flake")
|
flake_dir = Path(temp_dir) / "test-flake"
|
||||||
subprocess.run(["cp", "-r", clan_core_for_checks, flake_dir], check=True)
|
subprocess.run(["cp", "-r", clan_core_for_checks, flake_dir], check=True) # noqa: S603, S607
|
||||||
subprocess.run(["chmod", "-R", "+w", flake_dir], check=True)
|
subprocess.run(["chmod", "-R", "+w", flake_dir], check=True) # noqa: S603, S607
|
||||||
|
|
||||||
return TestEnvironment(host_port, ssh_key, flake_dir)
|
return TestEnvironment(host_port, str(ssh_key), str(flake_dir))
|
||||||
|
|||||||
@@ -41,4 +41,5 @@ ignore = [
|
|||||||
"ANN", # type annotations
|
"ANN", # type annotations
|
||||||
"COM812", # trailing comma
|
"COM812", # trailing comma
|
||||||
"ISC001", # string concatenation
|
"ISC001", # string concatenation
|
||||||
|
"T201", # print statements
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user