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,32 +78,38 @@ 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',
|
||||||
# fmt: off
|
"console=ttyS0,115200n8",
|
||||||
"qemu-kvm",
|
"console=tty0",
|
||||||
"-name", machine,
|
]
|
||||||
"-m", f'{vm_config["memorySize"]}M',
|
qemu_command = [
|
||||||
"-smp", str(vm_config["cores"]),
|
# fmt: off
|
||||||
"-device", "virtio-rng-pci",
|
"qemu-kvm",
|
||||||
"-net", "nic,netdev=user.0,model=virtio", "-netdev", "user,id=user.0",
|
"-name", machine,
|
||||||
"-virtfs", "local,path=/nix/store,security_model=none,mount_tag=nix-store",
|
"-m", f'{vm_config["memorySize"]}M',
|
||||||
"-virtfs", f"local,path={xchg_dir},security_model=none,mount_tag=shared",
|
"-smp", str(vm_config["cores"]),
|
||||||
"-virtfs", f"local,path={xchg_dir},security_model=none,mount_tag=xchg",
|
"-device", "virtio-rng-pci",
|
||||||
"-drive", f'cache=writeback,file={disk_img},format=raw,id=drive1,if=none,index=1,werror=report',
|
"-net", "nic,netdev=user.0,model=virtio", "-netdev", "user,id=user.0",
|
||||||
"-device", "virtio-blk-pci,bootindex=1,drive=drive1,serial=root",
|
"-virtfs", "local,path=/nix/store,security_model=none,mount_tag=nix-store",
|
||||||
"-device", "virtio-keyboard",
|
"-virtfs", f"local,path={xchg_dir},security_model=none,mount_tag=shared",
|
||||||
"-usb",
|
"-virtfs", f"local,path={xchg_dir},security_model=none,mount_tag=xchg",
|
||||||
"-device", "usb-tablet,bus=usb-bus.0",
|
"-drive", f'cache=writeback,file={disk_img},format=raw,id=drive1,if=none,index=1,werror=report',
|
||||||
"-kernel", f'{vm_config["toplevel"]}/kernel',
|
"-device", "virtio-blk-pci,bootindex=1,drive=drive1,serial=root",
|
||||||
"-initrd", vm_config["initrd"],
|
"-device", "virtio-keyboard",
|
||||||
"-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',
|
"-usb",
|
||||||
# fmt: on
|
"-device", "usb-tablet,bus=usb-bus.0",
|
||||||
],
|
"-kernel", f'{vm_config["toplevel"]}/kernel',
|
||||||
)
|
"-initrd", vm_config["initrd"],
|
||||||
)
|
"-append", " ".join(cmdline),
|
||||||
|
# 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