python312Packages.millheater: 0.11.8 -> 0.12.0
[NixPkgs.git] / nixos / tests / iscsi-root.nix
blob6953b6ce9a0650cb9038e089a6ea42b0b3002818
1 import ./make-test-python.nix (
2   { pkgs, lib, ... }:
3     let
4       initiatorName = "iqn.2020-08.org.linux-iscsi.initiatorhost:example";
5       targetName = "iqn.2003-01.org.linux-iscsi.target.x8664:sn.acf8fd9c23af";
6     in
7       {
8         name = "iscsi";
9         meta = {
10           maintainers = lib.teams.deshaw.members
11             ++ lib.teams.helsinki-systems.members;
12         };
14         nodes = {
15           target = { config, pkgs, lib, ... }: {
16             services.target = {
17               enable = true;
18               config = {
19                 fabric_modules = [];
20                 storage_objects = [
21                   {
22                     dev = "/dev/vdb";
23                     name = "test";
24                     plugin = "block";
25                     write_back = true;
26                     wwn = "92b17c3f-6b40-4168-b082-ceeb7b495522";
27                   }
28                 ];
29                 targets = [
30                   {
31                     fabric = "iscsi";
32                     tpgs = [
33                       {
34                         enable = true;
35                         attributes = {
36                           authentication = 0;
37                           generate_node_acls = 1;
38                         };
39                         luns = [
40                           {
41                             alias = "94dfe06967";
42                             alua_tg_pt_gp_name = "default_tg_pt_gp";
43                             index = 0;
44                             storage_object = "/backstores/block/test";
45                           }
46                         ];
47                         node_acls = [
48                           {
49                             mapped_luns = [
50                               {
51                                 alias = "d42f5bdf8a";
52                                 index = 0;
53                                 tpg_lun = 0;
54                                 write_protect = false;
55                               }
56                             ];
57                             node_wwn = initiatorName;
58                           }
59                         ];
60                         portals = [
61                           {
62                             ip_address = "[::]";
63                             iser = false;
64                             offload = false;
65                             port = 3260;
66                           }
67                         ];
68                         tag = 1;
69                       }
70                     ];
71                     wwn = targetName;
72                   }
73                 ];
74               };
75             };
77             networking.firewall.allowedTCPPorts = [ 3260 ];
78             networking.firewall.allowedUDPPorts = [ 3260 ];
80             virtualisation.memorySize = 2048;
81             virtualisation.emptyDiskImages = [ 2048 ];
82           };
84           initiatorAuto = { nodes, config, pkgs, ... }: {
85             services.openiscsi = {
86               enable = true;
87               enableAutoLoginOut = true;
88               discoverPortal = "target";
89               name = initiatorName;
90             };
92             environment.systemPackages = with pkgs; [
93               xfsprogs
94             ];
96             system.extraDependencies = [ nodes.initiatorRootDisk.system.build.toplevel ];
98             nix.settings = {
99               substituters = lib.mkForce [];
100               hashed-mirrors = null;
101               connect-timeout = 1;
102             };
103           };
105           initiatorRootDisk = { config, pkgs, modulesPath, lib, ... }: {
106             boot.loader.grub.enable = false;
107             boot.kernelParams = lib.mkOverride 5 (
108               [
109                 "boot.shell_on_fail"
110                 "console=tty1"
111                 "ip=${config.networking.primaryIPAddress}:::255.255.255.0::eth1:none"
112               ]
113             );
115             # defaults to true, puts some code in the initrd that tries to mount an overlayfs on /nix/store
116             virtualisation.writableStore = false;
118             fileSystems = lib.mkOverride 5 {
119               "/" = {
120                 fsType = "xfs";
121                 device = "/dev/sda";
122                 options = [ "_netdev" ];
123               };
124             };
126             boot.iscsi-initiator = {
127               discoverPortal = "target";
128               name = initiatorName;
129               target = targetName;
130             };
131           };
132         };
134         testScript = { nodes, ... }: ''
135           target.start()
136           target.wait_for_unit("iscsi-target.service")
138           initiatorAuto.start()
140           initiatorAuto.wait_for_unit("iscsid.service")
141           initiatorAuto.wait_for_unit("iscsi.service")
142           initiatorAuto.get_unit_info("iscsi")
144           initiatorAuto.succeed("set -x; while ! test -e /dev/sda; do sleep 1; done")
146           initiatorAuto.succeed("mkfs.xfs /dev/sda")
147           initiatorAuto.succeed("mkdir /mnt && mount /dev/sda /mnt")
148           initiatorAuto.succeed(
149               "nixos-install --no-bootloader --no-root-passwd --system ${nodes.initiatorRootDisk.config.system.build.toplevel}"
150           )
151           initiatorAuto.succeed("umount /mnt && rmdir /mnt")
152           initiatorAuto.shutdown()
154           initiatorRootDisk.start()
155           initiatorRootDisk.wait_for_unit("multi-user.target")
156           initiatorRootDisk.wait_for_unit("iscsid")
157           initiatorRootDisk.succeed("touch test")
158           initiatorRootDisk.shutdown()
159         '';
160       }