Merge pull request 'inventory tests: use containers by default' (#3398) from DavHau/clan-core:dave into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3398
This commit is contained in:
DavHau
2025-04-23 12:59:52 +00:00
13 changed files with 44 additions and 39 deletions

View File

@@ -1,3 +0,0 @@
from . import main
main()

View File

@@ -13,43 +13,15 @@ in
imports = [
self.clanLib.test.minifyModule
];
config = lib.mkMerge [
(lib.optionalAttrs (options ? clan) {
clan.core.settings.machine.name = config.networking.hostName;
})
{
documentation.enable = lib.mkDefault false;
boot.isContainer = true;
# needed since nixpkgs 7fb2f407c01b017737eafc26b065d7f56434a992 removed the getty unit by default
console.enable = true;
# undo qemu stuff
system.build.initialRamdisk = "";
virtualisation.sharedDirectories = lib.mkForce { };
networking.useDHCP = false;
# We use networkd to assign static ip addresses
networking.useNetworkd = true;
services.resolved.enable = false;
# Rename the host0 interface to eth0 to match what we expect in VM tests.
system.activationScripts.renameInterface = ''
${pkgs.iproute2}/bin/ip link set dev host0 name eth1
'';
systemd.services.backdoor.enable = false;
# we don't have permission to set cpu scheduler in our container
systemd.services.nix-daemon.serviceConfig.CPUSchedulingPolicy = lib.mkForce "";
}
];
config = lib.optionalAttrs (options ? clan) {
clan.core.settings.machine.name = config.networking.hostName;
};
};
# to accept external dependencies such as disko
node.specialArgs.self = self;
_module.args = { inherit self; };
imports = [
test
./container-driver/module.nix
../../lib/test/container-test-driver/driver-module.nix
];
}).config.result

View File

@@ -6,6 +6,8 @@
}:
clanLib.test.makeTestClan {
inherit pkgs self;
# TODO: container driver does not support: sleep, wait_for_window, send_chars, wait_for_text
useContainers = false;
nixosTest = (
{ lib, ... }:
let

View File

@@ -6,6 +6,8 @@
}:
clanLib.test.makeTestClan {
inherit pkgs self;
# TODO: container driver does not support wait_for_file() yet
useContainers = false;
nixosTest = (
{ lib, ... }:
{

View File

@@ -37,6 +37,9 @@ let
pythonizedNames = map pythonizeName nodeHostNames;
in
{
defaults.imports = [
./nixos-module.nix
];
driver = lib.mkForce (
hostPkgs.runCommand "nixos-test-driver-${config.name}"
{

View File

@@ -0,0 +1,26 @@
{ pkgs, lib, ... }:
{
boot.isContainer = true;
# needed since nixpkgs 7fb2f407c01b017737eafc26b065d7f56434a992 removed the getty unit by default
console.enable = true;
# undo qemu stuff
system.build.initialRamdisk = "";
virtualisation.sharedDirectories = lib.mkForce { };
networking.useDHCP = false;
# We use networkd to assign static ip addresses
networking.useNetworkd = true;
services.resolved.enable = false;
# Rename the host0 interface to eth0 to match what we expect in VM tests.
system.activationScripts.renameInterface = ''
${pkgs.iproute2}/bin/ip link set dev host0 name eth1
'';
systemd.services.backdoor.enable = false;
# we don't have permission to set cpu scheduler in our container
systemd.services.nix-daemon.serviceConfig.CPUSchedulingPolicy = lib.mkForce "";
}

View File

@@ -116,7 +116,7 @@ class Machine:
def container_pid(self) -> int:
return self.get_systemd_process()
def start(self) -> list[str]:
def start(self) -> None:
prepare_machine_root(self.name, self.rootdir)
cmd = [
"systemd-nspawn",
@@ -137,8 +137,6 @@ class Machine:
env = os.environ.copy()
env["SYSTEMD_NSPAWN_UNIFIED_HIERARCHY"] = "1"
self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True, env=env)
self.container_pid = self.get_systemd_process()
return cmd
def get_systemd_process(self) -> int:
assert self.process is not None, "Machine not started"
@@ -455,6 +453,7 @@ class Driver:
subprocess.run(["ip", "link", "set", "br0", "up"], check=True, text=True)
for machine in self.machines:
print(f"Starting {machine.name}")
machine.start()
def test_symbols(self) -> dict[str, Any]:

View File

@@ -4,6 +4,7 @@ let
mkOption
types
;
in
{
flakeModules = clanLib.callLib ./flakeModules.nix { };
@@ -17,6 +18,7 @@ in
nixosTest,
pkgs,
self,
useContainers ? true,
...
}:
let
@@ -28,7 +30,9 @@ in
clanFlakeResult = config.clan;
in
{
imports = [ nixosTest ];
imports = [
nixosTest
] ++ lib.optionals (useContainers) [ ./container-test-driver/driver-module.nix ];
options = {
clanSettings = mkOption {
default = { };