Add Aarch64 tests and include multiple test images. (#9)

This commit is contained in:
Ramses 2023-04-27 14:57:00 +02:00 committed by GitHub
parent 804f9b947f
commit af43744006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 175 additions and 133 deletions

75
examples/example.nix Normal file
View file

@ -0,0 +1,75 @@
{ lib, pkgs, ... }: {
config = {
nixpkgs.hostPlatform = "x86_64-linux";
services.nginx.enable = true;
environment.etc = {
foo = {
text = ''
This is just a test!
'';
target = "foo_test";
};
"foo.conf".text = ''
launch_the_rockets = true
'';
"baz/bar/foo2" = {
text = ''
Another test!
'';
mode = "symlink";
};
foo3 = {
text = "boo!";
mode = "0700";
user = "root";
group = "root";
};
"a/nested/example/foo3" = {
text = "boo!";
mode = "0764";
user = "root";
group = "root";
};
"a/nested/example2/foo3" = {
text = "boo!";
mode = "0764";
user = "root";
group = "root";
};
out-of-store = {
source = "/run/systemd/system/";
};
};
systemd.services =
lib.listToAttrs
(lib.flip lib.genList 10 (ix:
lib.nameValuePair "service-${toString ix}"
{
enable = true;
description = "service-${toString ix}";
wants = [ "network-online.target" ];
after = [
"network-online.target"
];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecReload = "${lib.getBin pkgs.coreutils}/bin/true";
};
wantedBy = [ "system-manager.target" ];
requiredBy = lib.mkIf (ix > 5) [ "service-0.service" ];
script = ''
sleep ${if ix > 5 then "2" else "1"}
'';
})
);
};
}

View file

@ -186,16 +186,23 @@
}).shellHook; }).shellHook;
}; };
checks = { checks =
inherit let
# Build the crate as part of `nix flake check` for convenience # The Aarch64 VM tests seem to hang on garnix, we disable them for now
system-manager enableVmTests = system != flake-utils.lib.system.aarch64-linux;
system-manager-clippy in
system-manager-test; {
basicTest = import ./test/nix/modules { inherit
# Build the crate as part of `nix flake check` for convenience
system-manager
system-manager-clippy
system-manager-test;
} //
pkgs.lib.optionalAttrs enableVmTests (import ./test/nix/modules {
inherit system; inherit system;
inherit (pkgs) lib;
system-manager = self; system-manager = self;
}; });
}; })
})); );
} }

View file

@ -175,17 +175,51 @@ in
] ]
); );
images = { # TODO: put these in an external JSON file that we can automatically update
ubuntu_22_10_cloudimg = { images.ubuntu = {
name = "ubuntu-22.10-server-cloudimg-amd64.img"; x86_64-linux = {
release = "20230302"; ubuntu_22_10_cloudimg = {
hash = "sha256-9hjGjlUQoXZfAYTwsEjHE3Zawd6qqrVc6VXshthNS44="; name = "kinetic-server-cloudimg-amd64.img";
}; releaseName = "kinetic";
releaseTimeStamp = "20230424";
hash = "sha256-54LucfgXtNAxKKQKmvHCk8EzPRlULGq/IfUjAvUaOXk=";
};
ubuntu_20_04_cloudimg = { ubuntu_22_04_cloudimg = {
name = "ubuntu-20.04-server-cloudimg-amd64.img"; name = "jammy-server-cloudimg-amd64.img";
release = ""; releaseName = "jammy";
hash = ""; releaseTimeStamp = "20230427";
hash = "sha256-m76TZOKYnBzOLBZpt6kcK70TkFKHaoyBzVLA+q77ZHQ=";
};
ubuntu_20_04_cloudimg = {
name = "focal-server-cloudimg-amd64.img";
releaseName = "focal";
releaseTimeStamp = "20230420";
hash = "sha256-XFUVWvk8O1IHfp+sAiOSCU5ASk/qJG2JIF4WH0ex12U=";
};
};
aarch64-linux = {
ubuntu_22_10_cloudimg = {
name = "kinetic-server-cloudimg-arm64.img";
releaseName = "kinetic";
releaseTimeStamp = "20230424";
hash = "sha256-AS8bXXqWwJdlKUYxI1MO48AyWR++Ttf1+C7ahicKiks=";
};
ubuntu_22_04_cloudimg = {
name = "jammy-server-cloudimg-arm64.img";
releaseName = "jammy";
releaseTimeStamp = "20230427";
hash = "sha256-9vkeg5VumVBxj4TaLd0SgJEWjw11pcP7SBz5zd1V0EE=";
};
ubuntu_20_04_cloudimg = {
name = "focal-server-cloudimg-arm64.img";
releaseName = "focal";
releaseTimeStamp = "20230420";
hash = "sha256-YUtW3oMHz4Hw7WeIu6ksx+/mUfxp7cCSSETvY6KGwU4=";
};
}; };
}; };
@ -197,7 +231,7 @@ in
[Service] [Service]
Type = oneshot Type = oneshot
ExecStart = mkdir -p /nix/.ro-store ExecStart = mkdir -p /nix/.ro-store
ExecStart = mount -t 9p -o defaults,trans=virtio,version=9p2000.L,cache=loose nix-store /nix/.ro-store ExecStart = mount -t 9p -o defaults,trans=virtio,version=9p2000.L,cache=loose,msize=${toString (256 * 1024 * 1024)} nix-store /nix/.ro-store
ExecStart = mkdir -p -m 0755 /nix/.rw-store/ /nix/store ExecStart = mkdir -p -m 0755 /nix/.rw-store/ /nix/store
ExecStart = mount -t tmpfs tmpfs /nix/.rw-store ExecStart = mount -t tmpfs tmpfs /nix/.rw-store
ExecStart = mkdir -p -m 0755 /nix/.rw-store/store /nix/.rw-store/work ExecStart = mkdir -p -m 0755 /nix/.rw-store/store /nix/.rw-store/work
@ -258,7 +292,7 @@ in
img = pkgs.fetchurl { img = pkgs.fetchurl {
inherit (image) hash; inherit (image) hash;
url = "https://cloud-images.ubuntu.com/releases/kinetic/release-${image.release}/${image.name}"; url = "https://cloud-images.ubuntu.com/${image.releaseName}/${image.releaseTimeStamp}/${image.name}";
}; };
in in
pkgs.runCommand "configure-vm" { } '' pkgs.runCommand "configure-vm" { } ''

View file

@ -1,121 +1,47 @@
{ system-manager { lib
, system-manager
, system , system
}: }:
let lib.flip lib.mapAttrs' system-manager.lib.images.ubuntu.${system} (imgName: image:
testConfig = { lib, pkgs, ... }: { lib.nameValuePair "example-${imgName}"
config = { (system-manager.lib.make-vm-test {
nixpkgs.hostPlatform = "x86_64-linux"; inherit system;
modules = [
({ config, ... }:
let
inherit (config) hostPkgs;
in
{
nodes = {
node1 = { config, ... }: {
modules = [
../../../examples/example.nix
];
services.nginx.enable = true; virtualisation.rootImage = system-manager.lib.prepareUbuntuImage {
inherit hostPkgs image;
environment.etc = { nodeConfig = config;
foo = { };
text = ''
This is just a test!
'';
target = "foo_test";
};
"foo.conf".text = ''
launch_the_rockets = true
'';
"baz/bar/foo2" = {
text = ''
Another test!
'';
mode = "symlink";
};
foo3 = {
text = "boo!";
mode = "0700";
user = "root";
group = "root";
};
"a/nested/example/foo3" = {
text = "boo!";
mode = "0764";
user = "root";
group = "root";
};
"a/nested/example2/foo3" = {
text = "boo!";
mode = "0764";
user = "root";
group = "root";
};
out-of-store = {
source = "/run/systemd/system/";
};
};
systemd.services =
lib.listToAttrs
(lib.flip lib.genList 10 (ix:
lib.nameValuePair "service-${toString ix}"
{
enable = true;
description = "service-${toString ix}";
wants = [ "network-online.target" ];
after = [
"network-online.target"
];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecReload = "${lib.getBin pkgs.coreutils}/bin/true";
};
wantedBy = [ "system-manager.target" ];
requiredBy = lib.mkIf (ix > 5) [ "service-0.service" ];
script = ''
sleep ${if ix > 5 then "2" else "1"}
'';
})
);
};
};
in
system-manager.lib.make-vm-test {
inherit system;
modules = [
({ config, ... }:
let
inherit (config) hostPkgs;
in
{
nodes = {
node1 = { config, ... }: {
modules = [
testConfig
];
virtualisation.rootImage = system-manager.lib.prepareUbuntuImage {
inherit hostPkgs;
nodeConfig = config;
image = system-manager.lib.images.ubuntu_22_10_cloudimg;
}; };
}; };
};
testScript = '' testScript = ''
# Start all machines in parallel # Start all machines in parallel
start_all() start_all()
node1.wait_for_unit("default.target") node1.wait_for_unit("default.target")
node1.execute("/system-manager-profile/bin/activate") node1.execute("/system-manager-profile/bin/activate")
node1.wait_for_unit("system-manager.target") node1.wait_for_unit("system-manager.target")
node1.wait_for_unit("service-9.service") node1.wait_for_unit("service-9.service")
node1.wait_for_file("/etc/baz/bar/foo2") node1.wait_for_file("/etc/baz/bar/foo2")
node1.wait_for_file("/etc/foo.conf") node1.wait_for_file("/etc/foo.conf")
node1.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf") node1.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf")
node1.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf") node1.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf")
''; '';
}) })
]; ];
} })
)