Improve naming and error reporting in VM tests.
This commit is contained in:
parent
cead991210
commit
8ec989863d
2 changed files with 19 additions and 8 deletions
19
nix/lib.nix
19
nix/lib.nix
|
|
@ -7,6 +7,12 @@ let
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
# Function that can be used when defining inline modules to get better location
|
||||||
|
# reporting in module-system errors.
|
||||||
|
# Usage example:
|
||||||
|
# { _file = "${printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module"; }
|
||||||
|
printAttrPos = { file, line, column }: "${file}:${toString line}:${toString column}";
|
||||||
|
|
||||||
makeSystemConfig =
|
makeSystemConfig =
|
||||||
{ modules
|
{ modules
|
||||||
, extraSpecialArgs ? { }
|
, extraSpecialArgs ? { }
|
||||||
|
|
@ -15,7 +21,7 @@ in
|
||||||
let
|
let
|
||||||
# Module that sets additional module arguments
|
# Module that sets additional module arguments
|
||||||
extraArgsModule = { lib, config, pkgs, ... }: {
|
extraArgsModule = { lib, config, pkgs, ... }: {
|
||||||
_file = "lib.nix: extraArgsModule";
|
_file = "${self.lib.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
|
||||||
_module.args = {
|
_module.args = {
|
||||||
pkgs = nixpkgs.legacyPackages.${config.nixpkgs.hostPlatform};
|
pkgs = nixpkgs.legacyPackages.${config.nixpkgs.hostPlatform};
|
||||||
utils = import "${nixos}/lib/utils.nix" {
|
utils = import "${nixos}/lib/utils.nix" {
|
||||||
|
|
@ -321,7 +327,7 @@ in
|
||||||
|
|
||||||
resultImg = "./image.qcow2";
|
resultImg = "./image.qcow2";
|
||||||
in
|
in
|
||||||
pkgs.runCommand "vm-image.qcow2" { } ''
|
pkgs.runCommand "${image.name}-system-manager-vm-test.qcow2" { } ''
|
||||||
# We will modify the VM image, so we need a mutable copy
|
# We will modify the VM image, so we need a mutable copy
|
||||||
install -m777 ${img} ${resultImg}
|
install -m777 ${img} ${resultImg}
|
||||||
|
|
||||||
|
|
@ -353,6 +359,10 @@ in
|
||||||
systemctl mask snapd.socket
|
systemctl mask snapd.socket
|
||||||
systemctl mask snapd.seeded.service
|
systemctl mask snapd.seeded.service
|
||||||
|
|
||||||
|
# We have no network in the test VMs, avoid an error on bootup
|
||||||
|
systemctl mask ssh.service
|
||||||
|
systemctl mask ssh.socket
|
||||||
|
|
||||||
systemctl enable backdoor.service
|
systemctl enable backdoor.service
|
||||||
'')
|
'')
|
||||||
]};
|
]};
|
||||||
|
|
@ -361,6 +371,7 @@ in
|
||||||
'';
|
'';
|
||||||
|
|
||||||
make-vm-test =
|
make-vm-test =
|
||||||
|
name:
|
||||||
{ system
|
{ system
|
||||||
, modules
|
, modules
|
||||||
}:
|
}:
|
||||||
|
|
@ -372,7 +383,7 @@ in
|
||||||
modules = [
|
modules = [
|
||||||
../test/nix/test-driver/modules
|
../test/nix/test-driver/modules
|
||||||
{
|
{
|
||||||
_file = "inline module in lib.nix";
|
_file = "${self.lib.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
|
||||||
inherit hostPkgs;
|
inherit hostPkgs;
|
||||||
}
|
}
|
||||||
] ++ modules;
|
] ++ modules;
|
||||||
|
|
@ -451,7 +462,7 @@ in
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
hostPkgs.stdenv.mkDerivation (finalAttrs: {
|
hostPkgs.stdenv.mkDerivation (finalAttrs: {
|
||||||
name = "system-manager-vm-test";
|
inherit name;
|
||||||
|
|
||||||
requiredSystemFeatures = [ "kvm" "nixos-test" ];
|
requiredSystemFeatures = [ "kvm" "nixos-test" ];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ in
|
||||||
|
|
||||||
forEachUbuntuImage
|
forEachUbuntuImage
|
||||||
(imgName: image: lib.nameValuePair
|
(imgName: image: lib.nameValuePair
|
||||||
"example-${imgName}"
|
"vm-test-example-${imgName}"
|
||||||
(system-manager.lib.make-vm-test {
|
(system-manager.lib.make-vm-test "vm-test-example-${imgName}" {
|
||||||
inherit system;
|
inherit system;
|
||||||
modules = [
|
modules = [
|
||||||
({ config, ... }:
|
({ config, ... }:
|
||||||
|
|
@ -117,8 +117,8 @@ forEachUbuntuImage
|
||||||
|
|
||||||
forEachUbuntuImage
|
forEachUbuntuImage
|
||||||
(imgName: image: lib.nameValuePair
|
(imgName: image: lib.nameValuePair
|
||||||
"prepopulate-${imgName}"
|
"vm-test-prepopulate-${imgName}"
|
||||||
(system-manager.lib.make-vm-test {
|
(system-manager.lib.make-vm-test "vm-test-prepopulate-${imgName}" {
|
||||||
inherit system;
|
inherit system;
|
||||||
modules = [
|
modules = [
|
||||||
({ config, ... }:
|
({ config, ... }:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue