python312Packages.dissect-extfs: 3.11 -> 3.12
[NixPkgs.git] / nixos / tests / incus / lxd-to-incus.nix
blob66f78cbd33b4061db9e43419b83ddd3dfecf76f3
1 import ../make-test-python.nix (
3   {
4     pkgs,
5     lib,
6     incus ? pkgs.incus-lts,
7     ...
8   }:
10   let
11     releases = import ../../release.nix { configuration.documentation.enable = lib.mkForce false; };
13     container-image-metadata = releases.lxdContainerMeta.${pkgs.stdenv.hostPlatform.system};
14     container-image-rootfs = releases.lxdContainerImage.${pkgs.stdenv.hostPlatform.system};
15   in
16   {
17     name = "lxd-to-incus";
19     meta = {
20       maintainers = lib.teams.lxc.members;
21     };
23     nodes.machine =
24       { lib, ... }:
25       {
26         virtualisation = {
27           diskSize = 6144;
28           cores = 2;
29           memorySize = 2048;
31           lxd.enable = true;
32           lxd.preseed = {
33             networks = [
34               {
35                 name = "nixostestbr0";
36                 type = "bridge";
37                 config = {
38                   "ipv4.address" = "10.0.100.1/24";
39                   "ipv4.nat" = "true";
40                 };
41               }
42             ];
43             profiles = [
44               {
45                 name = "default";
46                 devices = {
47                   eth0 = {
48                     name = "eth0";
49                     network = "nixostestbr0";
50                     type = "nic";
51                   };
52                   root = {
53                     path = "/";
54                     pool = "nixostest_pool";
55                     size = "35GiB";
56                     type = "disk";
57                   };
58                 };
59               }
60               {
61                 name = "nixos_notdefault";
62                 devices = { };
63               }
64             ];
65             storage_pools = [
66               {
67                 name = "nixostest_pool";
68                 driver = "dir";
69               }
70             ];
71           };
73           incus = {
74             enable = true;
75             package = incus;
76           };
77         };
78         networking.nftables.enable = true;
79       };
81     testScript = ''
82       def lxd_wait_for_preseed(_) -> bool:
83         _, output = machine.systemctl("is-active lxd-preseed.service")
84         return ("inactive" in output)
86       def lxd_instance_is_up(_) -> bool:
87           status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running")
88           return status == 0
90       def incus_instance_is_up(_) -> bool:
91           status, _ = machine.execute("incus exec container --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running")
92           return status == 0
94       with machine.nested("initialize lxd and resources"):
95         machine.wait_for_unit("sockets.target")
96         machine.wait_for_unit("lxd.service")
97         retry(lxd_wait_for_preseed)
99         machine.succeed("lxc image import ${container-image-metadata}/*/*.tar.xz ${container-image-rootfs}/*/*.tar.xz --alias nixos")
100         machine.succeed("lxc launch nixos container")
101         retry(lxd_instance_is_up)
103       machine.wait_for_unit("incus.service")
105       with machine.nested("run migration"):
106           machine.succeed("${pkgs.incus}/bin/lxd-to-incus --yes")
108       with machine.nested("verify resources migrated to incus"):
109           machine.succeed("incus config show container")
110           retry(incus_instance_is_up)
111           machine.succeed("incus exec container -- true")
112           machine.succeed("incus profile show default | grep nixostestbr0")
113           machine.succeed("incus profile show default | grep nixostest_pool")
114           machine.succeed("incus profile show nixos_notdefault")
115           machine.succeed("incus storage show nixostest_pool")
116           machine.succeed("incus network show nixostestbr0")
117     '';
118   }