make vm test also work in ci
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
import shlex
|
||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
@@ -8,7 +10,7 @@ from uuid import UUID
|
|||||||
from ..dirs import get_clan_flake_toplevel
|
from ..dirs import get_clan_flake_toplevel
|
||||||
from ..nix import nix_build, nix_shell
|
from ..nix import nix_build, nix_shell
|
||||||
from ..task_manager import BaseTask, CmdState, create_task
|
from ..task_manager import BaseTask, CmdState, create_task
|
||||||
from .inspect import VmConfig
|
from .inspect import VmConfig, inspect_vm
|
||||||
|
|
||||||
|
|
||||||
class BuildVmTask(BaseTask):
|
class BuildVmTask(BaseTask):
|
||||||
@@ -76,10 +78,14 @@ class BuildVmTask(BaseTask):
|
|||||||
)
|
)
|
||||||
|
|
||||||
cmd = next(cmds)
|
cmd = next(cmds)
|
||||||
cmd.run(
|
cmdline = [
|
||||||
nix_shell(
|
(Path(vm_config["toplevel"]) / "kernel-params").read_text(),
|
||||||
["qemu"],
|
f'init={vm_config["toplevel"]}/init',
|
||||||
[
|
f'regInfo={vm_config["regInfo"]}/registration',
|
||||||
|
"console=ttyS0,115200n8",
|
||||||
|
"console=tty0",
|
||||||
|
]
|
||||||
|
qemu_command = [
|
||||||
# fmt: off
|
# fmt: off
|
||||||
"qemu-kvm",
|
"qemu-kvm",
|
||||||
"-name", machine,
|
"-name", machine,
|
||||||
@@ -97,11 +103,13 @@ class BuildVmTask(BaseTask):
|
|||||||
"-device", "usb-tablet,bus=usb-bus.0",
|
"-device", "usb-tablet,bus=usb-bus.0",
|
||||||
"-kernel", f'{vm_config["toplevel"]}/kernel',
|
"-kernel", f'{vm_config["toplevel"]}/kernel',
|
||||||
"-initrd", vm_config["initrd"],
|
"-initrd", vm_config["initrd"],
|
||||||
"-append", f'{(Path(vm_config["toplevel"]) / "kernel-params").read_text()} init={vm_config["toplevel"]}/init regInfo={vm_config["regInfo"]}/registration console=ttyS0,115200n8 console=tty0',
|
"-append", " ".join(cmdline),
|
||||||
# fmt: on
|
# fmt: on
|
||||||
],
|
]
|
||||||
)
|
if not self.vm.graphics:
|
||||||
)
|
qemu_command.append("-nographic")
|
||||||
|
print("$ " + shlex.join(qemu_command))
|
||||||
|
cmd.run(nix_shell(["qemu"], qemu_command))
|
||||||
|
|
||||||
|
|
||||||
def create_vm(vm: VmConfig) -> BuildVmTask:
|
def create_vm(vm: VmConfig) -> BuildVmTask:
|
||||||
@@ -110,13 +118,7 @@ def create_vm(vm: VmConfig) -> BuildVmTask:
|
|||||||
|
|
||||||
def create_command(args: argparse.Namespace) -> None:
|
def create_command(args: argparse.Namespace) -> None:
|
||||||
clan_dir = get_clan_flake_toplevel().as_posix()
|
clan_dir = get_clan_flake_toplevel().as_posix()
|
||||||
vm = VmConfig(
|
vm = asyncio.run(inspect_vm(flake_url=clan_dir, flake_attr=args.machine))
|
||||||
flake_url=clan_dir,
|
|
||||||
flake_attr=args.machine,
|
|
||||||
cores=0,
|
|
||||||
graphics=False,
|
|
||||||
memory_size=0,
|
|
||||||
)
|
|
||||||
|
|
||||||
task = create_vm(vm)
|
task = create_vm(vm)
|
||||||
for line in task.logs_iter():
|
for line in task.logs_iter():
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
system.stateVersion = lib.version;
|
system.stateVersion = lib.version;
|
||||||
sops.age.keyFile = "__CLAN_SOPS_KEY_PATH__";
|
sops.age.keyFile = "__CLAN_SOPS_KEY_PATH__";
|
||||||
clanCore.secretsUploadDirectory = "__CLAN_SOPS_KEY_DIR__";
|
clanCore.secretsUploadDirectory = "__CLAN_SOPS_KEY_DIR__";
|
||||||
|
clan.virtualisation.graphics = false;
|
||||||
|
|
||||||
clan.networking.zerotier.controller.enable = true;
|
clan.networking.zerotier.controller.enable = true;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ def test_inspect(api: TestClient, test_flake_with_core: Path) -> None:
|
|||||||
assert config.get("flake_attr") == "vm1"
|
assert config.get("flake_attr") == "vm1"
|
||||||
assert config.get("cores") == 1
|
assert config.get("cores") == 1
|
||||||
assert config.get("memory_size") == 1024
|
assert config.get("memory_size") == 1024
|
||||||
assert config.get("graphics") is True
|
assert config.get("graphics") is False
|
||||||
|
|
||||||
|
|
||||||
def test_incorrect_uuid(api: TestClient) -> None:
|
def test_incorrect_uuid(api: TestClient) -> None:
|
||||||
@@ -42,7 +42,7 @@ def test_create(api: TestClient, test_flake_with_core: Path) -> None:
|
|||||||
flake_attr="vm1",
|
flake_attr="vm1",
|
||||||
cores=1,
|
cores=1,
|
||||||
memory_size=1024,
|
memory_size=1024,
|
||||||
graphics=True,
|
graphics=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, "Failed to create vm"
|
assert response.status_code == 200, "Failed to create vm"
|
||||||
|
|||||||
Reference in New Issue
Block a user