Commit 5bafc240 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Daniel Verkamp
Browse files

test/iscsi: utilize network namespaces in iSCSI tests



Network namespaces are used to assure that kernel
is not routing packets within host stack,
but they go through veth interfaces.

This patch serves as a base for future VPP test changes,
where namespaces are used as well.

Change-Id: Ic7b82b0a0837bca2e16774fde244348a691fe056
Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/405641


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent adfa9f6d
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -236,13 +236,19 @@ function waitforlisten() {
		if ! kill -s 0 $1; then
			exit 1
		fi

		namespace=$(ip netns identify $1)
		if [ -n "$namespace" ]; then
			ns_cmd="ip netns exec $namespace"
		fi

		if hash ss; then
			if ss -lx | grep -q $rpc_addr; then
			if $ns_cmd ss -lx | grep -q $rpc_addr; then
				ret=0
			fi
		else
			# if system doesn't have ss, just assume it has netstat
			if netstat -an -x | grep -iw LISTENING | grep -q $rpc_addr; then
			if $ns_cmd netstat -an -x | grep -iw LISTENING | grep -q $rpc_addr; then
				ret=0
			fi
		fi
@@ -315,20 +321,29 @@ function start_iscsi_service() {

function rbd_setup() {
	# $1 = monitor ip address
	# $2 = name of the namespace
	if [ -z "$1" ]; then
		echo "No monitor IP address provided for ceph"
		exit 1
	fi
	if [ -n "$2" ]; then
		if ip netns list | grep "$2"; then
			NS_CMD="ip netns exec $2"
		else
			echo "No namespace $2 exists"
			exit 1
		fi
	fi

	if hash ceph; then
		export PG_NUM=128
		export RBD_POOL=rbd
		export RBD_NAME=foo
		$rootdir/scripts/ceph/start.sh $1
		$NS_CMD $rootdir/scripts/ceph/start.sh $1

		ceph osd pool create $RBD_POOL $PG_NUM || true
		rbd pool init $RBD_POOL || true
		rbd create $RBD_NAME --size 1000
		$NS_CMD ceph osd pool create $RBD_POOL $PG_NUM || true
		$NS_CMD rbd pool init $RBD_POOL || true
		$NS_CMD rbd create $RBD_NAME --size 1000
	fi
}

+14 −5
Original line number Diff line number Diff line
# Network configuration
TARGET_INTERFACE="spdk_tgt_int"
INITIATOR_INTERFACE="spdk_init_int"
TARGET_NAMESPACE="spdk_iscsi_ns"
TARGET_NS_CMD="ip netns exec $TARGET_NAMESPACE"

# iSCSI target configuration
TARGET_IP=10.0.0.1
INITIATOR_IP=10.0.0.2
ISCSI_PORT=3260
NETMASK=$INITIATOR_IP/30
NETMASK=$INITIATOR_IP/32
INITIATOR_TAG=2
INITIATOR_NAME=ANY
PORTAL_TAG=1
ISCSI_APP="./app/iscsi_tgt/iscsi_tgt -i 0"
ISCSI_APP="$TARGET_NS_CMD ./app/iscsi_tgt/iscsi_tgt -i 0"
ISCSI_TEST_CORE_MASK=0xFF

function create_veth_interfaces() {
	ip netns del $TARGET_NAMESPACE || true
	ip link delete $INITIATOR_INTERFACE || true

	# Create veth (Virtual ethernet) interface pair
@@ -21,14 +24,20 @@ function create_veth_interfaces() {
	ip addr add $INITIATOR_IP/24 dev $INITIATOR_INTERFACE
	ip link set $INITIATOR_INTERFACE up

	ip addr add $TARGET_IP/24 dev $TARGET_INTERFACE
	ip link set $TARGET_INTERFACE up
	# Create and add interface for target to network namespace
	ip netns add $TARGET_NAMESPACE
	ip link set $TARGET_INTERFACE netns $TARGET_NAMESPACE

	$TARGET_NS_CMD ip link set lo up
	$TARGET_NS_CMD ip addr add $TARGET_IP/24 dev $TARGET_INTERFACE
	$TARGET_NS_CMD ip link set $TARGET_INTERFACE up

	trap "cleanup_veth_interfaces; exit 1" SIGINT SIGTERM EXIT
}

function cleanup_veth_interfaces() {
	# Cleanup veth interfaces
	# Cleanup veth interfaces and network namespace
	# Note: removing one veth, removes the pair
	ip link delete $INITIATOR_INTERFACE
	ip netns del $TARGET_NAMESPACE
}
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ timing_enter start_iscsi_tgt

# Start the iSCSI target without using stub
# Reason: Two SPDK processes will be started
$rootdir/app/iscsi_tgt/iscsi_tgt -c $testdir/iscsi.conf -m 0x2 -p 1 -s 512 &
$ISCSI_APP -c $testdir/iscsi.conf -m 0x2 -p 1 -s 512 &
pid=$!
echo "iSCSI target launched. pid: $pid"
trap "killprocess $pid;exit 1" SIGINT SIGTERM EXIT
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ source $rootdir/test/iscsi_tgt/common.sh
rpc_py="python $rootdir/scripts/rpc.py"
fio_py="python $rootdir/scripts/fio.py"

# Namespaces are NOT used here on purpose. This test requires changes to detect
# ifc_index for interface that was put into namespace. Needed for add_ip_address.
ISCSI_APP="$rootdir/app/iscsi_tgt/iscsi_tgt"
NETMASK=127.0.0.0/24
MIGRATION_ADDRESS=127.0.0.2

+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ $rootdir/scripts/gen_nvme.sh >> $testdir/iscsi.conf

timing_enter start_iscsi_tgt
# Start the iSCSI target without using stub.
$rootdir/app/iscsi_tgt/iscsi_tgt -c $testdir/iscsi.conf &
$ISCSI_APP -c $testdir/iscsi.conf &
iscsipid=$!
echo "iSCSI target launched. pid: $iscsipid"
trap "remove_backends; iscsicleanup; killprocess $iscsipid; exit 1" SIGINT SIGTERM EXIT
Loading