1 import ./make-test-python.nix (
4 initiatorName = "iqn.2020-08.org.linux-iscsi.initiatorhost:example";
5 targetName = "iqn.2003-01.org.linux-iscsi.target.x8664:sn.acf8fd9c23af";
10 maintainers = pkgs.lib.teams.deshaw.members;
14 target = { config, pkgs, lib, ... }: {
15 virtualisation.vlans = [ 1 2 ];
26 wwn = "92b17c3f-6b40-4168-b082-ceeb7b495522";
37 generate_node_acls = 1;
42 alua_tg_pt_gp_name = "default_tg_pt_gp";
44 storage_object = "/backstores/block/test";
54 write_protect = false;
57 node_wwn = initiatorName;
62 ip_address = "0.0.0.0";
77 networking.firewall.allowedTCPPorts = [ 3260 ];
78 networking.firewall.allowedUDPPorts = [ 3260 ];
80 virtualisation.memorySize = 2048;
81 virtualisation.emptyDiskImages = [ 2048 ];
84 initiatorAuto = { nodes, config, pkgs, ... }: {
85 virtualisation.vlans = [ 1 2 ];
87 services.multipath = {
91 user_friendly_names yes
96 wwid = "3600140592b17c3f6b404168b082ceeb7";
101 services.openiscsi = {
103 enableAutoLoginOut = true;
104 discoverPortal = "target";
105 name = initiatorName;
108 environment.systemPackages = with pkgs; [
112 environment.etc."initiator-root-disk-closure".source = nodes.initiatorRootDisk.config.system.build.toplevel;
115 substituters = lib.mkForce [ ];
116 hashed-mirrors = null;
121 initiatorRootDisk = { config, pkgs, modulesPath, lib, ... }: {
122 boot.initrd.network.enable = true;
123 boot.loader.grub.enable = false;
125 boot.kernelParams = lib.mkOverride 5 (
129 "ip=192.168.1.1:::255.255.255.0::ens9:none"
130 "ip=192.168.2.1:::255.255.255.0::ens10:none"
134 # defaults to true, puts some code in the initrd that tries to mount an overlayfs on /nix/store
135 virtualisation.writableStore = false;
136 virtualisation.vlans = [ 1 2 ];
138 services.multipath = {
142 user_friendly_names yes
147 wwid = "3600140592b17c3f6b404168b082ceeb7";
152 fileSystems = lib.mkOverride 5 {
155 device = "/dev/mapper/123456";
156 options = [ "_netdev" ];
160 boot.initrd.extraFiles."etc/multipath/wwids".source = pkgs.writeText "wwids" "/3600140592b17c3f6b404168b082ceeb7/";
162 boot.iscsi-initiator = {
163 discoverPortal = "target";
164 name = initiatorName;
166 extraIscsiCommands = ''
167 iscsiadm -m discovery -o update -t sendtargets -p 192.168.2.3 --login
174 testScript = { nodes, ... }: ''
176 target.wait_for_unit("iscsi-target.service")
178 initiatorAuto.start()
180 initiatorAuto.wait_for_unit("iscsid.service")
181 initiatorAuto.wait_for_unit("iscsi.service")
182 initiatorAuto.get_unit_info("iscsi")
184 # Expecting this to fail since we should already know about 192.168.1.3
185 initiatorAuto.fail("iscsiadm -m discovery -o update -t sendtargets -p 192.168.1.3 --login")
186 # Expecting this to succeed since we don't yet know about 192.168.2.3
187 initiatorAuto.succeed("iscsiadm -m discovery -o update -t sendtargets -p 192.168.2.3 --login")
189 # /dev/sda is provided by iscsi on target
190 initiatorAuto.succeed("set -x; while ! test -e /dev/sda; do sleep 1; done")
192 initiatorAuto.succeed("mkfs.xfs /dev/sda")
193 initiatorAuto.succeed("mkdir /mnt")
195 # Start by verifying /dev/sda and /dev/sdb are both the same disk
196 initiatorAuto.succeed("mount /dev/sda /mnt")
197 initiatorAuto.succeed("touch /mnt/hi")
198 initiatorAuto.succeed("umount /mnt")
200 initiatorAuto.succeed("mount /dev/sdb /mnt")
201 initiatorAuto.succeed("test -e /mnt/hi")
202 initiatorAuto.succeed("umount /mnt")
204 initiatorAuto.succeed("systemctl restart multipathd")
205 initiatorAuto.succeed("multipath -ll | systemd-cat")
207 # Install our RootDisk machine to 123456, the alias to the device that multipath is now managing
208 initiatorAuto.succeed("mount /dev/mapper/123456 /mnt")
209 initiatorAuto.succeed("mkdir -p /mnt/etc/{multipath,iscsi}")
210 initiatorAuto.succeed("cp -r /etc/multipath/wwids /mnt/etc/multipath/wwids")
211 initiatorAuto.succeed("cp -r /etc/iscsi/{nodes,send_targets} /mnt/etc/iscsi")
212 initiatorAuto.succeed(
213 "nixos-install --no-bootloader --no-root-passwd --system /etc/initiator-root-disk-closure"
215 initiatorAuto.succeed("umount /mnt")
216 initiatorAuto.shutdown()
218 initiatorRootDisk.start()
219 initiatorRootDisk.wait_for_unit("multi-user.target")
220 initiatorRootDisk.wait_for_unit("iscsid")
222 # Log in over both nodes
223 initiatorRootDisk.fail("iscsiadm -m discovery -o update -t sendtargets -p 192.168.1.3 --login")
224 initiatorRootDisk.fail("iscsiadm -m discovery -o update -t sendtargets -p 192.168.2.3 --login")
225 initiatorRootDisk.succeed("systemctl restart multipathd")
226 initiatorRootDisk.succeed("multipath -ll | systemd-cat")
228 # Verify we can write and sync the root disk
229 initiatorRootDisk.succeed("mkdir /scratch")
230 initiatorRootDisk.succeed("touch /scratch/both-up")
231 initiatorRootDisk.succeed("sync /scratch")
233 # Verify we can write to the root with ens9 (sda, 192.168.1.3) down
234 initiatorRootDisk.succeed("ip link set ens9 down")
235 initiatorRootDisk.succeed("touch /scratch/ens9-down")
236 initiatorRootDisk.succeed("sync /scratch")
237 initiatorRootDisk.succeed("ip link set ens9 up")
239 # todo: better way to wait until multipath notices the link is back
240 initiatorRootDisk.succeed("sleep 5")
241 initiatorRootDisk.succeed("touch /scratch/both-down")
242 initiatorRootDisk.succeed("sync /scratch")
244 # Verify we can write to the root with ens10 (sdb, 192.168.2.3) down
245 initiatorRootDisk.succeed("ip link set ens10 down")
246 initiatorRootDisk.succeed("touch /scratch/ens10-down")
247 initiatorRootDisk.succeed("sync /scratch")
248 initiatorRootDisk.succeed("ip link set ens10 up")
249 initiatorRootDisk.succeed("touch /scratch/ens10-down")
250 initiatorRootDisk.succeed("sync /scratch")
252 initiatorRootDisk.succeed("ip link set ens9 up")
253 initiatorRootDisk.succeed("ip link set ens10 up")
254 initiatorRootDisk.shutdown()
256 # Verify we can boot with the target's eth1 down, forcing
257 # it to multipath via the second link
258 target.succeed("ip link set eth1 down")
259 initiatorRootDisk.start()
260 initiatorRootDisk.wait_for_unit("multi-user.target")
261 initiatorRootDisk.wait_for_unit("iscsid")
262 initiatorRootDisk.succeed("test -e /scratch/both-up")