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:
@@ -1,3 +0,0 @@
|
|||||||
from . import main
|
|
||||||
|
|
||||||
main()
|
|
||||||
@@ -13,43 +13,15 @@ in
|
|||||||
imports = [
|
imports = [
|
||||||
self.clanLib.test.minifyModule
|
self.clanLib.test.minifyModule
|
||||||
];
|
];
|
||||||
config = lib.mkMerge [
|
config = lib.optionalAttrs (options ? clan) {
|
||||||
(lib.optionalAttrs (options ? clan) {
|
clan.core.settings.machine.name = config.networking.hostName;
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
# to accept external dependencies such as disko
|
# to accept external dependencies such as disko
|
||||||
node.specialArgs.self = self;
|
node.specialArgs.self = self;
|
||||||
_module.args = { inherit self; };
|
_module.args = { inherit self; };
|
||||||
imports = [
|
imports = [
|
||||||
test
|
test
|
||||||
./container-driver/module.nix
|
../../lib/test/container-test-driver/driver-module.nix
|
||||||
];
|
];
|
||||||
}).config.result
|
}).config.result
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
}:
|
}:
|
||||||
clanLib.test.makeTestClan {
|
clanLib.test.makeTestClan {
|
||||||
inherit pkgs self;
|
inherit pkgs self;
|
||||||
|
# TODO: container driver does not support: sleep, wait_for_window, send_chars, wait_for_text
|
||||||
|
useContainers = false;
|
||||||
nixosTest = (
|
nixosTest = (
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
}:
|
}:
|
||||||
clanLib.test.makeTestClan {
|
clanLib.test.makeTestClan {
|
||||||
inherit pkgs self;
|
inherit pkgs self;
|
||||||
|
# TODO: container driver does not support wait_for_file() yet
|
||||||
|
useContainers = false;
|
||||||
nixosTest = (
|
nixosTest = (
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ let
|
|||||||
pythonizedNames = map pythonizeName nodeHostNames;
|
pythonizedNames = map pythonizeName nodeHostNames;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
defaults.imports = [
|
||||||
|
./nixos-module.nix
|
||||||
|
];
|
||||||
driver = lib.mkForce (
|
driver = lib.mkForce (
|
||||||
hostPkgs.runCommand "nixos-test-driver-${config.name}"
|
hostPkgs.runCommand "nixos-test-driver-${config.name}"
|
||||||
{
|
{
|
||||||
26
lib/test/container-test-driver/nixos-module.nix
Normal file
26
lib/test/container-test-driver/nixos-module.nix
Normal 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 "";
|
||||||
|
}
|
||||||
@@ -116,7 +116,7 @@ class Machine:
|
|||||||
def container_pid(self) -> int:
|
def container_pid(self) -> int:
|
||||||
return self.get_systemd_process()
|
return self.get_systemd_process()
|
||||||
|
|
||||||
def start(self) -> list[str]:
|
def start(self) -> None:
|
||||||
prepare_machine_root(self.name, self.rootdir)
|
prepare_machine_root(self.name, self.rootdir)
|
||||||
cmd = [
|
cmd = [
|
||||||
"systemd-nspawn",
|
"systemd-nspawn",
|
||||||
@@ -137,8 +137,6 @@ class Machine:
|
|||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["SYSTEMD_NSPAWN_UNIFIED_HIERARCHY"] = "1"
|
env["SYSTEMD_NSPAWN_UNIFIED_HIERARCHY"] = "1"
|
||||||
self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True, env=env)
|
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:
|
def get_systemd_process(self) -> int:
|
||||||
assert self.process is not None, "Machine not started"
|
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)
|
subprocess.run(["ip", "link", "set", "br0", "up"], check=True, text=True)
|
||||||
|
|
||||||
for machine in self.machines:
|
for machine in self.machines:
|
||||||
|
print(f"Starting {machine.name}")
|
||||||
machine.start()
|
machine.start()
|
||||||
|
|
||||||
def test_symbols(self) -> dict[str, Any]:
|
def test_symbols(self) -> dict[str, Any]:
|
||||||
@@ -4,6 +4,7 @@ let
|
|||||||
mkOption
|
mkOption
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flakeModules = clanLib.callLib ./flakeModules.nix { };
|
flakeModules = clanLib.callLib ./flakeModules.nix { };
|
||||||
@@ -17,6 +18,7 @@ in
|
|||||||
nixosTest,
|
nixosTest,
|
||||||
pkgs,
|
pkgs,
|
||||||
self,
|
self,
|
||||||
|
useContainers ? true,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
@@ -28,7 +30,9 @@ in
|
|||||||
clanFlakeResult = config.clan;
|
clanFlakeResult = config.clan;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ nixosTest ];
|
imports = [
|
||||||
|
nixosTest
|
||||||
|
] ++ lib.optionals (useContainers) [ ./container-test-driver/driver-module.nix ];
|
||||||
options = {
|
options = {
|
||||||
clanSettings = mkOption {
|
clanSettings = mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
|
|||||||
Reference in New Issue
Block a user