Commit cf9e9b2e authored by Pawel Piatek's avatar Pawel Piatek Committed by Tomasz Zawadzki
Browse files

test/nvmf: add waitforcondition function



Previous sleep for one second was not always enough to
detect changes by discovery service. This commit
replace this sleep by pooling for some condition.

Fixes #2956

Signed-off-by: default avatarPawel Piatek <pawelx.piatek@intel.com>
Change-Id: I88c884c136e6a3c8c7269864b5bae2d52d20af0a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22380


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent 4e347247
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -896,6 +896,18 @@ function waitforbdev() {
	return 1
}

function waitforcondition() {
	local cond=$1
	local max=${2:-10}
	while ((max--)); do
		if eval $cond; then
			return 0
		fi
		sleep 1
	done
	return 1
}

function make_filesystem() {
	local fstype=$1
	local dev_name=$2
+17 −17
Original line number Diff line number Diff line
@@ -97,44 +97,44 @@ get_notification_count
# Discovery hostnqn is added, so now the host should see the subsystem, with a single path for the
# port of the single listener on the target.
$rpc_py nvmf_subsystem_add_host ${NQN}0 $HOST_NQN
sleep 1 # Wait a bit to make sure the discovery service has a chance to detect the changes
[[ "$(get_subsystem_names)" == "nvme0" ]]
[[ "$(get_bdev_list)" == "nvme0n1" ]]
[[ "$(get_subsystem_paths nvme0)" == "$NVMF_PORT" ]]
# Wait a bit to make sure the discovery service has a chance to detect the changes
waitforcondition '[[ "$(get_subsystem_names)" == "nvme0" ]]'
waitforcondition '[[ "$(get_bdev_list)" == "nvme0n1" ]]'
waitforcondition '[[ "$(get_subsystem_paths nvme0)" == "$NVMF_PORT" ]]'
get_notification_count
[[ $notification_count == 1 ]]

# Adding a namespace isn't a discovery function, but do it here anyways just to confirm we see a new bdev.
$rpc_py nvmf_subsystem_add_ns ${NQN}0 null1
sleep 1 # Wait a bit to make sure the discovery service has a chance to detect the changes
[[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]]
# Wait a bit to make sure the discovery service has a chance to detect the changes
waitforcondition '[[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]]'
get_notification_count
[[ $notification_count == 1 ]]

# Add a second path to the same subsystem.  This shouldn't change the list of subsystems or bdevs, but
# we should see a second path on the nvme0 subsystem now.
$rpc_py nvmf_subsystem_add_listener ${NQN}0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT
sleep 1 # Wait a bit to make sure the discovery service has a chance to detect the changes
[[ "$(get_subsystem_names)" == "nvme0" ]]
[[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]]
[[ "$(get_subsystem_paths nvme0)" == "$NVMF_PORT $NVMF_SECOND_PORT" ]]
# Wait a bit to make sure the discovery service has a chance to detect the changes
waitforcondition '[[ "$(get_subsystem_names)" == "nvme0" ]]'
waitforcondition '[[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]]'
waitforcondition '[[ "$(get_subsystem_paths nvme0)" == "$NVMF_PORT $NVMF_SECOND_PORT" ]]'
get_notification_count
[[ $notification_count == 0 ]]

# Remove the listener for the first port.  The subsystem and bdevs should stay, but we should see
# the path to that first port disappear.
$rpc_py nvmf_subsystem_remove_listener ${NQN}0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
sleep 1 # Wait a bit to make sure the discovery service has a chance to detect the changes
[[ "$(get_subsystem_names)" == "nvme0" ]]
[[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]]
[[ "$(get_subsystem_paths nvme0)" == "$NVMF_SECOND_PORT" ]]
# Wait a bit to make sure the discovery service has a chance to detect the changes
waitforcondition '[[ "$(get_subsystem_names)" == "nvme0" ]]'
waitforcondition '[[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]]'
waitforcondition '[[ "$(get_subsystem_paths nvme0)" == "$NVMF_SECOND_PORT" ]]'
get_notification_count
[[ $notification_count == 0 ]]

$rpc_py -s $HOST_SOCK bdev_nvme_stop_discovery -b nvme
sleep 1 # Wait a bit to make sure the discovery service has a chance to detect the changes
[[ "$(get_subsystem_names)" == "" ]]
[[ "$(get_bdev_list)" == "" ]]
# Wait a bit to make sure the discovery service has a chance to detect the changes
waitforcondition '[[ "$(get_subsystem_names)" == "" ]]'
waitforcondition '[[ "$(get_bdev_list)" == "" ]]'
get_notification_count
[[ $notification_count == 2 ]]