[PATCH 06/10] nvme/040: create authenticated connections

Hannes Reinecke
2022-06-10T11:34:02Z

tests/nvme/040 | 81 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/040.out | 7 ++++
2 files changed, 88 insertions(+)
create mode 100644 tests/nvme/040
create mode 100644 tests/nvme/040.out

diff --git a/tests/nvme/040 b/tests/nvme/040
new file mode 100644
index 0000000..ce6157f
--- /dev/null
+++ b/tests/nvme/040
@@ -0,0 +1,81 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2021 Hannes Reinecke, SUSE Labs
+#
+# Create authenticated connections
+
+. tests/nvme/rc
+
+DESCRIPTION="Create authenticated connections"
+QUICK=1
+
+requires() {
+ _nvme_requires
+ _have_loop
+ _require_nvme_trtype_is_fabrics
+ _require_nvme_cli_auth
+}
+
+
+test() {
+ local port
+ local subsys_name="blktests-subsystem-1"
+ local hostid="$(uuidgen)"
+ local hostnqn="nqn.2014-08.org.nvmexpress:uuid:${hostid}"
+ local file_path="${TMPDIR}/img"
+ local hostkey
+ local ctrldev
+
+ echo "Running ${TEST_NAME}"
+
+ hostkey="$(nvme gen-dhchap-key -n ${subsys_name} 2> /dev/null)"
+ if [ $? -ne 0 ] ; then
+ echo "nvme gen-dhchap-key command missing"
+ return 1
+ fi
+
+ _setup_nvmet
+
+ truncate -s 512M "${file_path}"
+
+ _create_nvmet_subsystem "${subsys_name}" "${file_path}" \
+ "b92842df-a394-44b1-84a4-92ae7d112861"
+ port="$(_create_nvmet_port "${nvme_trtype}")"
+ _add_nvmet_subsys_to_port "${port}" "${subsys_name}"
+ _create_nvmet_host "${subsys_name}" "${hostnqn}" "${hostkey}"
+
+ # Test unauthenticated connection (should fail)
+ echo "Test unauthenticated connection"
+ _nvme_connect_subsys "${nvme_trtype}" "${subsys_name}" \
+ "${def_traddr}" "${def_trscvid}" \
+ "${hostnqn}" "${hostid}"
+ if [ $? -eq 0 ] ; then
+ echo "nvme connect succeeded"
+ fi
+
+ _nvme_disconnect_subsys "${subsys_name}"
+
+ # Test authenticated connection
+ echo "Test authenticated connection"
+ _nvme_connect_subsys "${nvme_trtype}" "${subsys_name}" \
+ "${def_traddr}" "${def_trscvid}" \
+ "${hostnqn}" "${hostid}" "${hostkey}"
+ if [ $? -ne 0 ] ; then
+ echo "nvme connect failed"
+ fi
+
+ udevadm settle
+
+ _nvme_disconnect_subsys "${subsys_name}"
+
+ _remove_nvmet_subsystem_from_port "${port}" "${subsys_name}"
+ _remove_nvmet_subsystem "${subsys_name}"
+
+ _remove_nvmet_port "${port}"
+
+ _remove_nvmet_host "${hostnqn}"
+
+ rm "${file_path}"
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/040.out b/tests/nvme/040.out
new file mode 100644
index 0000000..b5da85f
--- /dev/null
+++ b/tests/nvme/040.out
@@ -0,0 +1,7 @@
+Running nvme/040
+Test unauthenticated connection
+no controller found: failed to write to nvme-fabrics device
+NQN:blktests-subsystem-1 disconnected 0 controller(s)
+Test authenticated connection
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Test complete
--
2.26.2