2023-10-03 15:18:36 +00:00
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2023-10-05 13:56:15 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2023-10-23 20:31:12 +00:00
|
|
|
from fixtures_flakes import FlakeForTest
|
2023-10-03 15:18:36 +00:00
|
|
|
import pytest
|
|
|
|
from cli import Cli
|
|
|
|
|
2023-10-05 13:56:15 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from age_keys import KeyPair
|
|
|
|
|
2023-10-03 15:18:36 +00:00
|
|
|
no_kvm = not os.path.exists("/dev/kvm")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.impure
|
2023-10-23 20:31:12 +00:00
|
|
|
def test_inspect(test_flake_with_core: FlakeForTest, capsys: pytest.CaptureFixture) -> None:
|
2023-10-03 15:18:36 +00:00
|
|
|
cli = Cli()
|
2023-10-23 20:31:12 +00:00
|
|
|
cli.run(["vms", "inspect", "vm1", test_flake_with_core.name])
|
2023-10-03 15:18:36 +00:00
|
|
|
out = capsys.readouterr() # empty the buffer
|
|
|
|
assert "Cores" in out.out
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(no_kvm, reason="Requires KVM")
|
|
|
|
@pytest.mark.impure
|
2023-10-05 13:56:15 +00:00
|
|
|
def test_create(
|
|
|
|
monkeypatch: pytest.MonkeyPatch,
|
2023-10-23 20:31:12 +00:00
|
|
|
test_flake_with_core: FlakeForTest,
|
2023-10-05 13:56:15 +00:00
|
|
|
age_keys: list["KeyPair"],
|
|
|
|
) -> None:
|
2023-10-23 20:31:12 +00:00
|
|
|
monkeypatch.chdir(test_flake_with_core.path)
|
2023-10-05 13:56:15 +00:00
|
|
|
monkeypatch.setenv("SOPS_AGE_KEY", age_keys[0].privkey)
|
2023-10-03 15:18:36 +00:00
|
|
|
cli = Cli()
|
2023-10-23 20:31:12 +00:00
|
|
|
cli.run(["secrets", "users", "add", "user1", age_keys[0].pubkey, test_flake_with_core.name])
|
|
|
|
cli.run(["vms", "create", "vm1", test_flake_with_core.name])
|