Add checks for imperative guest management

This commit is contained in:
Julie B. 2021-08-03 22:06:02 +02:00
parent 83de5d86c8
commit 566a98bb0a
4 changed files with 111 additions and 34 deletions

View File

@ -0,0 +1,11 @@
{
description = "A Miniguest guest";
outputs = { self, nixpkgs }: with nixpkgs.lib; with importJSON ./params.json; {
nixosConfigurations.dummy.config.system.build.miniguest =
nixpkgs.legacyPackages.${system}.runCommand "dummy" { } ''
mkdir -p $out/boot
echo foo > $out/boot/init
'';
};
}

View File

@ -1,34 +1,4 @@
inputs@{ self, nixpkgs, ... }:
system:
let
kvm_guest = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
self.nixosModules.miniguest
{
boot.miniguest.enable = true;
fileSystems."/" = {
device = "none";
fsType = "tmpfs";
options = [ "defaults" "mode=755" ];
};
}
];
};
lxc_guest = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
self.nixosModules.miniguest
{
boot.miniguest.enable = true;
boot.miniguest.guestType = "lxc";
boot.miniguest.storeCorruptionWarning = false;
}
];
};
in
with nixpkgs.legacyPackages.${system};
lib.optionalAttrs stdenv.isLinux {
build_kvm_guest = kvm_guest.config.system.build.miniguest;
build_lxc_guest = lxc_guest.config.system.build.miniguest;
}
inputs: system:
import ./simple-guests.nix inputs system //
import ./imperative-management.nix inputs system

View File

@ -0,0 +1,61 @@
inputs@{ self, nixpkgs, ... }: system:
with nixpkgs.legacyPackages.${system};
with self.packages.${system};
let
# need a fixed-output copy of nixpkgs for offline use and reproducibility
pinned-nixpkgs = fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "21.05";
sha256 = "sha256-ZjBd81a6J3TwtlBr3rHsZspYUwT9OdhDk+a/SgSEf7I=";
};
mkTest = { name, testScript }: nixosTest {
inherit name;
machine = {
environment.systemPackages = [ miniguest ];
environment.etc."pinned-nixpkgs".source = pinned-nixpkgs;
system.extraDependencies = [ (import pinned-nixpkgs { inherit system; }).stdenvNoCC ];
virtualisation.memorySize = 1024;
};
testScript = ''
machine.copy_from_host("${data/flake1}", "/tmp/flake1")
machine.succeed("""
cat > /tmp/flake1/params.json << EOF
${builtins.toJSON { inherit system; }}
EOF
# override nixpkgs
${nixFlakes}/bin/nix --experimental-features "nix-command flakes" flake update /tmp/flake1 --override-input nixpkgs /etc/pinned-nixpkgs
""");
'' + testScript;
};
in
lib.optionalAttrs stdenv.isLinux {
install_dummy = mkTest {
name = "miniguest-install-dummy";
testScript = ''
machine.succeed("""
miniguest install /tmp/flake1#dummy
""")
assert "foo" in machine.succeed("""
cat /etc/miniguests/dummy/boot/init
""")
'';
};
install_nonexistent = mkTest {
name = "miniguest-install-nonexistent";
testScript = ''
machine.fail("""
miniguest install /tmp/flake1#nonexistent
""")
machine.succeed("""
test ! -e /etc/miniguests/nonexistent
""")
machine.succeed("""
test ! -e /nix/var/nix/miniguest-profiles/nonexistent
""")
'';
};
}

35
checks/simple-guests.nix Normal file
View File

@ -0,0 +1,35 @@
inputs@{ self, nixpkgs, ... }: system:
with nixpkgs.lib;
let
kvm_guest = nixosSystem {
inherit system;
modules = [
self.nixosModules.miniguest
{
boot.miniguest.enable = true;
fileSystems."/" = {
device = "none";
fsType = "tmpfs";
options = [ "defaults" "mode=755" ];
};
}
];
};
lxc_guest = nixosSystem {
inherit system;
modules = [
self.nixosModules.miniguest
{
boot.miniguest.enable = true;
boot.miniguest.guestType = "lxc";
boot.miniguest.storeCorruptionWarning = false;
}
];
};
in
with nixpkgs.legacyPackages.${system};
optionalAttrs stdenv.isLinux {
build_kvm_guest = kvm_guest.config.system.build.miniguest;
build_lxc_guest = lxc_guest.config.system.build.miniguest;
}