nixos/tests/hibernate: Simplify and always set resumeDevice
This commit is contained in:
parent
7a3730f901
commit
a923cc53e7
1 changed files with 28 additions and 108 deletions
|
@ -8,128 +8,48 @@
|
||||||
|
|
||||||
with import ../lib/testing-python.nix { inherit system pkgs; };
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||||
|
|
||||||
let
|
makeTest {
|
||||||
# System configuration of the installed system, which is used for the actual
|
|
||||||
# hibernate testing.
|
|
||||||
installedConfig = with pkgs.lib; {
|
|
||||||
imports = [
|
|
||||||
../modules/testing/test-instrumentation.nix
|
|
||||||
../modules/profiles/qemu-guest.nix
|
|
||||||
../modules/profiles/minimal.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
hardware.enableAllFirmware = mkForce false;
|
|
||||||
documentation.nixos.enable = false;
|
|
||||||
boot.loader.grub.device = "/dev/vda";
|
|
||||||
|
|
||||||
systemd.services.backdoor.conflicts = [ "sleep.target" ];
|
|
||||||
|
|
||||||
powerManagement.resumeCommands = "systemctl --no-block restart backdoor.service";
|
|
||||||
|
|
||||||
fileSystems."/" = {
|
|
||||||
device = "/dev/vda2";
|
|
||||||
fsType = "ext3";
|
|
||||||
};
|
|
||||||
swapDevices = mkOverride 0 [ { device = "/dev/vda1"; } ];
|
|
||||||
boot.resumeDevice = mkIf systemdStage1 "/dev/vda1";
|
|
||||||
boot.initrd.systemd = mkIf systemdStage1 {
|
|
||||||
enable = true;
|
|
||||||
emergencyAccess = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
installedSystem = (import ../lib/eval-config.nix {
|
|
||||||
inherit system;
|
|
||||||
modules = [ installedConfig ];
|
|
||||||
}).config.system.build.toplevel;
|
|
||||||
in makeTest {
|
|
||||||
name = "hibernate";
|
name = "hibernate";
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
# System configuration used for installing the installedConfig from above.
|
|
||||||
machine = { config, lib, pkgs, ... }: {
|
machine = { config, lib, pkgs, ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
../modules/profiles/installation-device.nix
|
|
||||||
../modules/profiles/base.nix
|
|
||||||
./common/auto-format-root-device.nix
|
./common/auto-format-root-device.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
nix.settings = {
|
systemd.services.backdoor.conflicts = [ "sleep.target" ];
|
||||||
substituters = lib.mkForce [];
|
powerManagement.resumeCommands = "systemctl --no-block restart backdoor.service";
|
||||||
hashed-mirrors = null;
|
|
||||||
connect-timeout = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtualisation.diskSize = 8 * 1024;
|
virtualisation.emptyDiskImages = [ (2 * config.virtualisation.memorySize) ];
|
||||||
virtualisation.emptyDiskImages = [
|
virtualisation.useNixStoreImage = true;
|
||||||
# Small root disk for installer
|
|
||||||
512
|
swapDevices = lib.mkOverride 0 [ { device = "/dev/vdc"; options = [ "x-systemd.makefs" ]; } ];
|
||||||
];
|
boot.resumeDevice = "/dev/vdc";
|
||||||
virtualisation.rootDevice = "/dev/vdb";
|
boot.initrd.systemd.enable = systemdStage1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# 9P doesn't support reconnection to virtio transport after a hibernation.
|
testScript = ''
|
||||||
# Therefore, machine just hangs on any Nix store access.
|
# Drop in file that checks if we un-hibernated properly (and not booted fresh)
|
||||||
# To avoid this, we install NixOS onto a temporary disk with everything we need
|
machine.wait_for_unit("default.target")
|
||||||
# included into the store.
|
machine.succeed(
|
||||||
|
"mkdir /run/test",
|
||||||
|
"mount -t ramfs -o size=1m ramfs /run/test",
|
||||||
|
"echo not persisted to disk > /run/test/suspended",
|
||||||
|
)
|
||||||
|
|
||||||
testScript =
|
# Hibernate machine
|
||||||
''
|
machine.execute("systemctl hibernate >&2 &", check_return=False)
|
||||||
def create_named_machine(name):
|
machine.wait_for_shutdown()
|
||||||
machine = create_machine(
|
|
||||||
{
|
|
||||||
"qemuFlags": "-cpu max ${
|
|
||||||
if system == "x86_64-linux" then "-m 1024"
|
|
||||||
else "-m 768 -enable-kvm -machine virt,gic-version=host"}",
|
|
||||||
"hdaInterface": "virtio",
|
|
||||||
"hda": "vm-state-machine/machine.qcow2",
|
|
||||||
"name": name,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
driver.machines.append(machine)
|
|
||||||
return machine
|
|
||||||
|
|
||||||
|
# Restore machine from hibernation, validate our ramfs file is there.
|
||||||
|
machine.start()
|
||||||
|
machine.succeed("grep 'not persisted to disk' /run/test/suspended")
|
||||||
|
|
||||||
# Install NixOS
|
# Ensure we don't restore from hibernation when booting again
|
||||||
machine.start()
|
machine.crash()
|
||||||
machine.succeed(
|
machine.wait_for_unit("default.target")
|
||||||
# Partition /dev/vda
|
machine.fail("grep 'not persisted to disk' /run/test/suspended")
|
||||||
"flock /dev/vda parted --script /dev/vda -- mklabel msdos"
|
'';
|
||||||
+ " mkpart primary linux-swap 1M 1024M"
|
|
||||||
+ " mkpart primary ext2 1024M -1s",
|
|
||||||
"udevadm settle",
|
|
||||||
"mkfs.ext3 -L nixos /dev/vda2",
|
|
||||||
"mount LABEL=nixos /mnt",
|
|
||||||
"mkswap /dev/vda1 -L swap",
|
|
||||||
# Install onto /mnt
|
|
||||||
"nix-store --load-db < ${pkgs.closureInfo {rootPaths = [installedSystem];}}/registration",
|
|
||||||
"nixos-install --root /mnt --system ${installedSystem} --no-root-passwd --no-channel-copy >&2",
|
|
||||||
)
|
|
||||||
machine.shutdown()
|
|
||||||
|
|
||||||
# Start up
|
|
||||||
hibernate = create_named_machine("hibernate")
|
|
||||||
|
|
||||||
# Drop in file that checks if we un-hibernated properly (and not booted fresh)
|
|
||||||
hibernate.succeed(
|
|
||||||
"mkdir /run/test",
|
|
||||||
"mount -t ramfs -o size=1m ramfs /run/test",
|
|
||||||
"echo not persisted to disk > /run/test/suspended",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Hibernate machine
|
|
||||||
hibernate.execute("systemctl hibernate >&2 &", check_return=False)
|
|
||||||
hibernate.wait_for_shutdown()
|
|
||||||
|
|
||||||
# Restore machine from hibernation, validate our ramfs file is there.
|
|
||||||
resume = create_named_machine("resume")
|
|
||||||
resume.start()
|
|
||||||
resume.succeed("grep 'not persisted to disk' /run/test/suspended")
|
|
||||||
|
|
||||||
# Ensure we don't restore from hibernation when booting again
|
|
||||||
resume.crash()
|
|
||||||
resume.wait_for_unit("default.target")
|
|
||||||
resume.fail("grep 'not persisted to disk' /run/test/suspended")
|
|
||||||
'';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue