vars: add test for deployment
This commit is contained in:
@@ -31,9 +31,11 @@ def upload_secrets(machine: Machine) -> None:
|
||||
"rsync",
|
||||
"-e",
|
||||
" ".join(["ssh"] + ssh_cmd[2:]),
|
||||
"-az",
|
||||
"--recursive",
|
||||
"--links",
|
||||
"--times",
|
||||
"--compress",
|
||||
"--delete",
|
||||
"--chown=root:root",
|
||||
"--chmod=D700,F600",
|
||||
f"{tempdir!s}/",
|
||||
f"{host.user}@{host.host}:{machine.secrets_upload_directory}/",
|
||||
|
||||
@@ -31,9 +31,11 @@ def upload_secrets(machine: Machine) -> None:
|
||||
"rsync",
|
||||
"-e",
|
||||
" ".join(["ssh"] + ssh_cmd[2:]),
|
||||
"-az",
|
||||
"--recursive",
|
||||
"--links",
|
||||
"--times",
|
||||
"--compress",
|
||||
"--delete",
|
||||
"--chown=root:root",
|
||||
"--chmod=D700,F600",
|
||||
f"{tempdir!s}/",
|
||||
f"{host.user}@{host.host}:{machine.secrets_upload_directory}/",
|
||||
|
||||
@@ -46,7 +46,7 @@ def wait_vm_up(machine_name: str, flake_url: str | None = None) -> None:
|
||||
if flake_url is None:
|
||||
flake_url = str(Path.cwd())
|
||||
socket_file = vm_state_dir(flake_url, machine_name) / "qmp.sock"
|
||||
timeout: float = 100
|
||||
timeout: float = 600
|
||||
while True:
|
||||
if timeout <= 0:
|
||||
raise TimeoutError(
|
||||
|
||||
42
pkgs/clan-cli/tests/test_vars_deployment.py
Normal file
42
pkgs/clan-cli/tests/test_vars_deployment.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.age_keys import SopsSetup
|
||||
from tests.fixtures_flakes import generate_flake
|
||||
from tests.helpers import cli
|
||||
from tests.helpers.nixos_config import nested_dict
|
||||
from tests.helpers.vms import qga_connect, run_vm_in_thread, wait_vm_down
|
||||
from tests.root import CLAN_CORE
|
||||
|
||||
|
||||
@pytest.mark.impure
|
||||
def test_vm_deployment(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
temporary_home: Path,
|
||||
sops_setup: SopsSetup,
|
||||
) -> None:
|
||||
config = nested_dict()
|
||||
config["clan"]["virtualisation"]["graphics"] = False
|
||||
config["services"]["getty"]["autologinUser"] = "root"
|
||||
config["services"]["openssh"]["enable"] = True
|
||||
config["networking"]["firewall"]["enable"] = False
|
||||
my_generator = config["clan"]["core"]["vars"]["generators"]["my_generator"]
|
||||
my_generator["files"]["my_secret"]["secret"] = True
|
||||
my_generator["files"]["my_value"]["secret"] = False
|
||||
my_generator["script"] = "echo hello > $out/my_secret && echo hello > $out/my_value"
|
||||
flake = generate_flake(
|
||||
temporary_home,
|
||||
flake_template=CLAN_CORE / "templates" / "minimal",
|
||||
machine_configs=dict(my_machine=config),
|
||||
)
|
||||
monkeypatch.chdir(flake.path)
|
||||
sops_setup.init()
|
||||
cli.run(["vars", "generate", "my_machine"])
|
||||
run_vm_in_thread("my_machine")
|
||||
qga = qga_connect("my_machine")
|
||||
qga.run("ls /run/secrets/my_machine/my_generator/my_secret", check=True)
|
||||
_, out, _ = qga.run("cat /run/secrets/my_machine/my_generator/my_secret")
|
||||
assert out == "hello\n"
|
||||
qga.exec_cmd("poweroff")
|
||||
wait_vm_down("my_machine")
|
||||
Reference in New Issue
Block a user