2024-02-01 18:34:05 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ lib, ... }:
|
|
|
|
{
|
|
|
|
name = "nvmetcfg";
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ nickcao ];
|
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2024-02-01 18:34:05 +00:00
|
|
|
nodes = {
|
2024-12-10 19:26:33 +00:00
|
|
|
server =
|
2024-02-01 18:34:05 +00:00
|
|
|
{ pkgs, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2024-02-01 18:34:05 +00:00
|
|
|
boot.kernelModules = [ "nvmet" ];
|
|
|
|
environment.systemPackages = [ pkgs.nvmetcfg ];
|
|
|
|
networking.firewall.allowedTCPPorts = [ 4420 ];
|
|
|
|
virtualisation.emptyDiskImages = [ 512 ];
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2024-02-01 18:34:05 +00:00
|
|
|
client =
|
|
|
|
{ pkgs, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2024-02-01 18:34:05 +00:00
|
|
|
boot.kernelModules = [ "nvme-fabrics" ];
|
|
|
|
environment.systemPackages = [ pkgs.nvme-cli ];
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2024-02-01 18:34:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
let
|
|
|
|
subsystem = "nqn.2014-08.org.nixos:server";
|
|
|
|
in
|
|
|
|
''
|
|
|
|
import json
|
|
|
|
|
|
|
|
with subtest("Create subsystem and namespace"):
|
|
|
|
server.succeed("nvmet subsystem add ${subsystem}")
|
|
|
|
server.succeed("nvmet namespace add ${subsystem} 1 /dev/vdb")
|
|
|
|
|
|
|
|
with subtest("Bind subsystem to port"):
|
|
|
|
server.wait_for_unit("network-online.target")
|
2024-06-12 12:24:42 +01:00
|
|
|
server.succeed("nvmet port add 1 tcp [::]:4420")
|
2024-02-01 18:34:05 +00:00
|
|
|
server.succeed("nvmet port add-subsystem 1 ${subsystem}")
|
|
|
|
|
|
|
|
with subtest("Discover and connect to available subsystems"):
|
|
|
|
client.wait_for_unit("network-online.target")
|
|
|
|
assert "subnqn: ${subsystem}" in client.succeed("nvme discover --transport=tcp --traddr=server --trsvcid=4420")
|
|
|
|
client.succeed("nvme connect-all --transport=tcp --traddr=server --trsvcid=4420")
|
|
|
|
|
|
|
|
with subtest("Write to the connected subsystem"):
|
|
|
|
devices = json.loads(client.succeed("lsblk --nvme --paths --json"))["blockdevices"]
|
|
|
|
assert len(devices) == 1
|
|
|
|
client.succeed(f"dd if=/dev/zero of={devices[0]['name']} bs=1M count=64")
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|