about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/incus/lxd-to-incus.nix
blob: c0fc98c224df1b79b3d8d79e49cc894aa942a0d0 (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import ../make-test-python.nix (

  { pkgs, lib, ... }:

  let
    releases = import ../../release.nix { configuration.documentation.enable = lib.mkForce false; };

    container-image-metadata = releases.lxdContainerMeta.${pkgs.stdenv.hostPlatform.system};
    container-image-rootfs = releases.lxdContainerImage.${pkgs.stdenv.hostPlatform.system};
  in
  {
    name = "lxd-to-incus";

    meta = {
      maintainers = lib.teams.lxc.members;
    };

    nodes.machine =
      { lib, ... }:
      {
        virtualisation = {
          diskSize = 6144;
          cores = 2;
          memorySize = 2048;

          lxd.enable = true;
          lxd.preseed = {
            networks = [
              {
                name = "nixostestbr0";
                type = "bridge";
                config = {
                  "ipv4.address" = "10.0.100.1/24";
                  "ipv4.nat" = "true";
                };
              }
            ];
            profiles = [
              {
                name = "default";
                devices = {
                  eth0 = {
                    name = "eth0";
                    network = "nixostestbr0";
                    type = "nic";
                  };
                  root = {
                    path = "/";
                    pool = "nixostest_pool";
                    size = "35GiB";
                    type = "disk";
                  };
                };
              }
              {
                name = "nixos_notdefault";
                devices = { };
              }
            ];
            storage_pools = [
              {
                name = "nixostest_pool";
                driver = "dir";
              }
            ];
          };

          incus.enable = true;
        };
      };

    testScript = ''
      def lxd_wait_for_preseed(_) -> bool:
        _, output = machine.systemctl("is-active lxd-preseed.service")
        return ("inactive" in output)

      def lxd_instance_is_up(_) -> bool:
          status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running")
          return status == 0

      def incus_instance_is_up(_) -> bool:
          status, _ = machine.execute("incus exec container --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running")
          return status == 0

      with machine.nested("initialize lxd and resources"):
        machine.wait_for_unit("sockets.target")
        machine.wait_for_unit("lxd.service")
        retry(lxd_wait_for_preseed)

        machine.succeed("lxc image import ${container-image-metadata}/*/*.tar.xz ${container-image-rootfs}/*/*.tar.xz --alias nixos")
        machine.succeed("lxc launch nixos container")
        retry(lxd_instance_is_up)

      machine.wait_for_unit("incus.service")

      with machine.nested("run migration"):
          machine.succeed("lxd-to-incus --yes")

      with machine.nested("verify resources migrated to incus"):
          machine.succeed("incus config show container")
          retry(incus_instance_is_up)
          machine.succeed("incus exec container -- true")
          machine.succeed("incus profile show default | grep nixostestbr0")
          machine.succeed("incus profile show default | grep nixostest_pool")
          machine.succeed("incus profile show nixos_notdefault")
          machine.succeed("incus storage show nixostest_pool")
          machine.succeed("incus network show nixostestbr0")
    '';
  }
)