Skip to content

Commit

Permalink
feat(tests): Test subsystem allowed hosts.
Browse files Browse the repository at this point in the history
  • Loading branch information
vifino committed Feb 11, 2024
1 parent d4cd7b0 commit 315ae36
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
4 changes: 4 additions & 0 deletions tests/loop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
node.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
node.fail("nvmet namespace remove ${subnqn} 1")
node.succeed("nvmet port remove-subsystem 1 ${subnqn}")
assert "${subnqn}" not in node.succeed("nvmet port list-subsystems 1")
node.fail("test -e /sys/kernel/config/nvmet/ports/1/subsystems/${subnqn}")
node.succeed("nvmet subsystem remove ${subnqn}")
node.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}")
node.fail("nvmet subsystem remove ${subnqn}")
Expand Down
30 changes: 26 additions & 4 deletions tests/rdma.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
};
testScript = let
subnqn = "nqn.2023-11.sh.tty:nvmetcfg-test-loop";
initiator1 = "nqn.2024-02.sh.tty:nvmetcfg-client1";
initiator2 = "nqn.2024-02.sh.tty:nvmetcfg-client2";
in ''
start_all()
target.wait_for_unit("default.target")
target.succeed("ip a")
# Set up the loop device.
target.succeed("fallocate -l 1G /root/test.img")
target.succeed("losetup /dev/loop0 /root/test.img")
Expand All @@ -47,6 +47,20 @@
target.succeed("nvmet subsystem add ${subnqn}")
assert "${subnqn}" in target.succeed("nvmet subsystem list")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.succeed("nvmet subsystem add-host ${subnqn} ${initiator1}")
target.succeed("test -d /sys/kernel/config/nvmet/hosts/${initiator1}")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator1}")
assert "${initiator1}" in target.succeed("nvmet subsystem list-hosts ${subnqn}")
target.succeed("nvmet subsystem add-host ${subnqn} ${initiator2}")
target.succeed("test -d /sys/kernel/config/nvmet/hosts/${initiator2}")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator2}")
assert "${initiator2}" in target.succeed("nvmet subsystem list-hosts ${subnqn}")
target.succeed("nvmet subsystem remove-host ${subnqn} ${initiator1}")
target.fail("test -e /sys/kernel/config/nvmet/hosts/${initiator1}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator1}")
assert "${initiator1}" not in target.succeed("nvmet subsystem list-hosts ${subnqn}")
target.succeed("nvmet subsystem show")
target.succeed("nvmet namespace add ${subnqn} 1 /dev/loop0")
Expand Down Expand Up @@ -86,14 +100,19 @@
assert target.succeed("cat /root/state.yml") == target.succeed("cat /root/state-after.yml")
# Test the target on the initiator.
initiator.wait_for_unit("default.target")
assert "${subnqn}" in initiator.succeed("nvme discover -t rdma -a target -s 4420")
clientnqn = initiator.succeed("nvme show-hostnqn")
target.succeed("nvmet subsystem add-host ${subnqn} " + clientnqn)
assert "${subnqn}" in initiator.succeed("nvme discover -t rdma -a target -s 4420 -q " + clientnqn)
# Cleanup.
target.succeed("nvmet namespace remove ${subnqn} 1")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
target.fail("nvmet namespace remove ${subnqn} 1")
target.succeed("nvmet port remove-subsystem 1 ${subnqn}")
assert "${subnqn}" not in target.succeed("nvmet port list-subsystems 1")
target.fail("test -e /sys/kernel/config/nvmet/ports/1/subsystems/${subnqn}")
target.succeed("nvmet subsystem remove ${subnqn}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.fail("nvmet subsystem remove ${subnqn}")
Expand All @@ -102,6 +121,9 @@
target.fail("test -e /sys/kernel/config/nvmet/ports/1")
target.fail("nvmet port remove 1")
target.fail("test -e /sys/kernel/config/nvmet/hosts/${initiator2}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator2}")
# Export coverage.
target.succeed("llvm-profdata merge --sparse -o /tmp/nvmetcfg.profdata /tmp/nvmetcfg-*.profraw")
target.succeed("llvm-cov export -format=lcov -instr-profile=/tmp/nvmetcfg.profdata " +
Expand Down
27 changes: 26 additions & 1 deletion tests/tcp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
};
testScript = let
subnqn = "nqn.2023-11.sh.tty:nvmetcfg-test-loop";
initiator1 = "nqn.2024-02.sh.tty:nvmetcfg-client1";
initiator2 = "nqn.2024-02.sh.tty:nvmetcfg-client2";
in ''
start_all()
target.wait_for_unit("default.target")
Expand All @@ -40,6 +42,20 @@
target.succeed("nvmet subsystem add ${subnqn}")
assert "${subnqn}" in target.succeed("nvmet subsystem list")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.succeed("nvmet subsystem add-host ${subnqn} ${initiator1}")
target.succeed("test -d /sys/kernel/config/nvmet/hosts/${initiator1}")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator1}")
assert "${initiator1}" in target.succeed("nvmet subsystem list-hosts ${subnqn}")
target.succeed("nvmet subsystem add-host ${subnqn} ${initiator2}")
target.succeed("test -d /sys/kernel/config/nvmet/hosts/${initiator2}")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator2}")
assert "${initiator2}" in target.succeed("nvmet subsystem list-hosts ${subnqn}")
target.succeed("nvmet subsystem remove-host ${subnqn} ${initiator1}")
target.fail("test -e /sys/kernel/config/nvmet/hosts/${initiator1}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator1}")
assert "${initiator1}" not in target.succeed("nvmet subsystem list-hosts ${subnqn}")
target.succeed("nvmet subsystem show")
target.succeed("nvmet namespace add ${subnqn} 1 /dev/loop0")
Expand Down Expand Up @@ -80,13 +96,19 @@
# Test the target on the initiator.
initiator.wait_for_unit("default.target")
assert "${subnqn}" in initiator.succeed("nvme discover -t tcp -a target -s 4420")
clientnqn = initiator.succeed("nvme show-hostnqn")
target.succeed("nvmet subsystem add-host ${subnqn} " + clientnqn)
assert "${subnqn}" in initiator.succeed("nvme discover -t tcp -a target -s 4420 -q " + clientnqn)
# Cleanup.
target.succeed("nvmet namespace remove ${subnqn} 1")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
target.fail("nvmet namespace remove ${subnqn} 1")
target.succeed("nvmet port remove-subsystem 1 ${subnqn}")
assert "${subnqn}" not in target.succeed("nvmet port list-subsystems 1")
target.fail("test -e /sys/kernel/config/nvmet/ports/1/subsystems/${subnqn}")
target.succeed("nvmet subsystem remove ${subnqn}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.fail("nvmet subsystem remove ${subnqn}")
Expand All @@ -95,6 +117,9 @@
target.fail("test -e /sys/kernel/config/nvmet/ports/1")
target.fail("nvmet port remove 1")
target.fail("test -e /sys/kernel/config/nvmet/hosts/${initiator2}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/allowed_hosts/${initiator2}")
# Export coverage.
target.succeed("llvm-profdata merge --sparse -o /tmp/nvmetcfg.profdata /tmp/nvmetcfg-*.profraw")
target.succeed("llvm-cov export -format=lcov -instr-profile=/tmp/nvmetcfg.profdata " +
Expand Down

0 comments on commit 315ae36

Please sign in to comment.