summaryrefslogtreecommitdiffstats
path: root/nixos/tests/grub/mirrored-boots.nix
blob: f3059bf675bcd9e54bf06c1e2de130d1cf952fb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ lib, ... }:
{
  name = "grub-mirrored-boots";

  meta = with lib.maintainers; {
    maintainers = [
      tomfitzhenry
      rnhmjoj
    ];
  };

  nodes.machine =
    { lib, ... }:
    {
      virtualisation.useBootLoader = true;

      boot.loader.timeout = null;
      boot.loader.grub = {
        enable = true;
        device = lib.mkOverride 0 "";
        mirroredBoots = [
          {
            path = "/boot1";
            devices = [ "/dev/vda" ];
          }
          {
            path = "/boot2";
            devices = [ "nodev" ];
          }
        ];

        # Read GRUB from the serial console so its output can be matched
        # deterministically with wait_for_console_text, rather than via OCR.
        extraConfig = "serial; terminal_output serial";
      };
    };

  testScript = ''
    machine.start()

    # wait for grub screen
    machine.wait_for_console_text("GNU GRUB")

    machine.send_chars("\n")  # press enter to boot default option

    with subtest("Machine boots correctly"):
        machine.wait_for_unit("multi-user.target")

    with subtest("Verify boot path 1 GRUB installation and configuration"):
        machine.succeed("test -d /boot1/grub")
        machine.succeed("test -f /boot1/grub/grub.cfg")
        machine.succeed("test -f /boot1/grub/state")
        machine.succeed("grep -q 'menuentry' /boot1/grub/grub.cfg")

    with subtest("Verify boot path 2 GRUB installation and configuration"):
        machine.succeed("test -d /boot2/grub")
        machine.succeed("test -f /boot2/grub/grub.cfg")
        machine.succeed("test -f /boot2/grub/state")
        machine.succeed("grep -q 'menuentry' /boot2/grub/grub.cfg")
  '';
}