1 import ./make-test-python.nix ({ lib, ... }: {
5 maintainers = with lib.maintainers; [ nickcao ];
9 server = { pkgs, ... }: {
10 boot.kernelModules = [ "nvmet" ];
11 environment.systemPackages = [ pkgs.nvmetcfg ];
12 networking.firewall.allowedTCPPorts = [ 4420 ];
13 virtualisation.emptyDiskImages = [ 512 ];
15 client = { pkgs, ... }: {
16 boot.kernelModules = [ "nvme-fabrics" ];
17 environment.systemPackages = [ pkgs.nvme-cli ];
21 testScript = let subsystem = "nqn.2014-08.org.nixos:server"; in ''
24 with subtest("Create subsystem and namespace"):
25 server.succeed("nvmet subsystem add ${subsystem}")
26 server.succeed("nvmet namespace add ${subsystem} 1 /dev/vdb")
28 with subtest("Bind subsystem to port"):
29 server.wait_for_unit("network-online.target")
30 server.succeed("nvmet port add 1 tcp [::]:4420")
31 server.succeed("nvmet port add-subsystem 1 ${subsystem}")
33 with subtest("Discover and connect to available subsystems"):
34 client.wait_for_unit("network-online.target")
35 assert "subnqn: ${subsystem}" in client.succeed("nvme discover --transport=tcp --traddr=server --trsvcid=4420")
36 client.succeed("nvme connect-all --transport=tcp --traddr=server --trsvcid=4420")
38 with subtest("Write to the connected subsystem"):
39 devices = json.loads(client.succeed("lsblk --nvme --paths --json"))["blockdevices"]
40 assert len(devices) == 1
41 client.succeed(f"dd if=/dev/zero of={devices[0]['name']} bs=1M count=64")