test/json: Tests for virtio bdevs
Change-Id: Ibb94abdfc6881aa3e8e6dceaf70e494f0146e385 Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.gerrithub.io/406561 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
00054fc675
commit
2d7cfda2d4
@ -199,6 +199,7 @@ fi
|
||||
|
||||
if [ $SPDK_TEST_VHOST_INIT -eq 1 ]; then
|
||||
run_test ./test/vhost/initiator/blockdev.sh
|
||||
run_test ./test/vhost/initiator/json_config.sh
|
||||
report_test_completion "vhost_initiator"
|
||||
fi
|
||||
|
||||
|
@ -14,7 +14,7 @@ function test_subsystems() {
|
||||
test_json_config
|
||||
|
||||
clear_bdev_subsystem_config
|
||||
test_global_params
|
||||
test_global_params "spdk_tgt"
|
||||
kill_targets
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,16 @@ def clear_interface_subsystem(args, interface_config):
|
||||
|
||||
|
||||
def clear_vhost_subsystem(args, vhost_config):
|
||||
pass
|
||||
for vhost in reversed(vhost_config):
|
||||
if 'method' in vhost:
|
||||
method = vhost['method']
|
||||
if method in ['add_vhost_scsi_lun']:
|
||||
args.client.call("remove_vhost_scsi_target",
|
||||
{"ctrlr": vhost['params']['ctrlr'],
|
||||
"scsi_target_num": vhost['params']['scsi_target_num']})
|
||||
elif method in ['construct_vhost_scsi_controller', 'construct_vhost_blk_controller',
|
||||
'construct_vhost_nvme_controller']:
|
||||
args.client.call("remove_vhost_controller", {'ctrlr': vhost['params']['ctrlr']})
|
||||
|
||||
|
||||
def call_test_cmd(func):
|
||||
|
@ -2,8 +2,10 @@ JSON_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
|
||||
SPDK_BUILD_DIR=$JSON_DIR/../../
|
||||
source $JSON_DIR/../common/autotest_common.sh
|
||||
|
||||
spdk_rpc_py="python $SPDK_BUILD_DIR/scripts/rpc.py"
|
||||
spdk_clear_config_py="$JSON_DIR/clear_config.py"
|
||||
spdk_rpc_py="python $SPDK_BUILD_DIR/scripts/rpc.py -s /var/tmp/spdk.sock"
|
||||
spdk_clear_config_py="$JSON_DIR/clear_config.py -s /var/tmp/spdk.sock"
|
||||
initiator_rpc_py="python $SPDK_BUILD_DIR/scripts/rpc.py -s /var/tmp/virtio.sock"
|
||||
initiator_clear_config_py="$JSON_DIR/clear_config.py -s /var/tmp/virtio.sock"
|
||||
base_json_config=$JSON_DIR/base_config.json
|
||||
last_json_config=$JSON_DIR/last_config.json
|
||||
full_config=$JSON_DIR/full_config.json
|
||||
@ -32,8 +34,19 @@ function load_nvme() {
|
||||
rm nvme_config.json
|
||||
}
|
||||
|
||||
function run_initiator() {
|
||||
$SPDK_BUILD_DIR/app/spdk_tgt/spdk_tgt -m 0x2 -p 0 -g -u -s 1024 -r /var/tmp/virtio.sock -w &
|
||||
virtio_pid=$!
|
||||
waitforlisten $virtio_pid /var/tmp/virtio.sock
|
||||
}
|
||||
|
||||
function kill_targets() {
|
||||
killprocess $spdk_tgt_pid
|
||||
if [ ! -z $virtio_pid ]; then
|
||||
killprocess $virtio_pid
|
||||
fi
|
||||
if [ ! -z $spdk_tgt_pid ]; then
|
||||
killprocess $spdk_tgt_pid
|
||||
fi
|
||||
}
|
||||
|
||||
# This function test if json config was properly saved and loaded.
|
||||
@ -106,20 +119,30 @@ function clear_bdev_subsystem_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
# In this test, target is spdk_tgt or virtio_initiator.
|
||||
# 1. Save current spdk config to full_config
|
||||
# and save only global parameters to the file "base_json_config".
|
||||
# 2. Exit the running spdk_tgt.
|
||||
# 3. Start the spdk_tgt and it waits for loading config.
|
||||
# 4. Load global parameters and configuration to the spdktgt from the file full_config.
|
||||
# 2. Exit the running spdk target.
|
||||
# 3. Start the spdk target and wait for loading config.
|
||||
# 4. Load global parameters and configuration to the spdk target from the file full_config.
|
||||
# 5. Save json config to the file "full_config".
|
||||
# 6. Save only global parameters to the file "last_json_config".
|
||||
# 7. Check if the file "base_json_config" matches the file "last_json_config".
|
||||
# 8. Delete all files.
|
||||
function test_global_params() {
|
||||
target=$1
|
||||
$rpc_py save_config -f $full_config
|
||||
python $JSON_DIR/config_filter.py -method "delete_configs" -filename $full_config > $base_json_config
|
||||
killprocess $spdk_tgt_pid
|
||||
run_spdk_tgt
|
||||
if [ $target == "spdk_tgt" ]; then
|
||||
killprocess $spdk_tgt_pid
|
||||
run_spdk_tgt
|
||||
elif [ $target == "virtio_initiator" ]; then
|
||||
killprocess $virtio_pid
|
||||
run_initiator
|
||||
else
|
||||
echo "Target is not specified for test_global_params"
|
||||
return 1
|
||||
fi
|
||||
$rpc_py load_config -f $full_config
|
||||
$rpc_py save_config -f $full_config
|
||||
python $JSON_DIR/config_filter.py -method "delete_configs" -filename $full_config > $last_json_config
|
||||
@ -135,7 +158,9 @@ function on_error_exit() {
|
||||
rpc_py="$spdk_rpc_py"
|
||||
clear_config_py="$spdk_clear_config_py"
|
||||
clear_bdev_subsystem_config
|
||||
killprocess $spdk_tgt_pid
|
||||
|
||||
kill_targets
|
||||
|
||||
print_backtrace
|
||||
exit 1
|
||||
}
|
||||
|
64
test/vhost/initiator/json_config.sh
Executable file
64
test/vhost/initiator/json_config.sh
Executable file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
INITIATOR_JSON_DIR=$(readlink -f $(dirname $0))
|
||||
. $INITIATOR_JSON_DIR/../../json_config/common.sh
|
||||
|
||||
# Load spdk_tgt with controllers used by virtio initiator
|
||||
# Test also virtio_pci bdevs
|
||||
function construct_vhost_devices() {
|
||||
$rpc_py construct_split_vbdev Nvme0n1 4
|
||||
$rpc_py construct_vhost_scsi_controller $JSON_DIR/naa.Nvme0n1p0.0
|
||||
$rpc_py construct_vhost_scsi_controller $JSON_DIR/naa.Nvme0n1p1.1
|
||||
$rpc_py add_vhost_scsi_lun $JSON_DIR/naa.Nvme0n1p0.0 0 Nvme0n1p0
|
||||
$rpc_py add_vhost_scsi_lun $JSON_DIR/naa.Nvme0n1p1.1 0 Nvme0n1p1
|
||||
$rpc_py construct_vhost_blk_controller $JSON_DIR/naa.Nvme0n1p2.0 Nvme0n1p2
|
||||
$rpc_py construct_vhost_blk_controller $JSON_DIR/naa.Nvme0n1p3.1 Nvme0n1p3
|
||||
pci_scsi=$(lspci -nn -D | grep '1af4:1004' | head -1 | awk '{print $1;}')
|
||||
pci_blk=$(lspci -nn -D | grep '1af4:1001' | head -1 | awk '{print $1;}')
|
||||
if [ ! -z $pci_scsi ]; then
|
||||
$rpc_py construct_virtio_dev -t pci -a $pci_scsi -d scsi Virtio0
|
||||
fi
|
||||
if [ ! -z $pci_blk ]; then
|
||||
$rpc_py construct_virtio_dev -t pci -a $pci_blk -d blk Virtio1
|
||||
fi
|
||||
}
|
||||
|
||||
# Load virtio initiator with bdevs
|
||||
function connect_to_vhost_devices_from_initiator() {
|
||||
$rpc_py construct_virtio_dev -t user -a $JSON_DIR/naa.Nvme0n1p0.0 -d scsi Nvme0n1p0
|
||||
$rpc_py construct_virtio_dev -t user -a $JSON_DIR/naa.Nvme0n1p2.0 -d blk Nvme0n1p2
|
||||
}
|
||||
|
||||
function disconnect_and_clear_vhost_devices() {
|
||||
$clear_config_py clear_config
|
||||
}
|
||||
|
||||
function test_subsystems() {
|
||||
run_spdk_tgt
|
||||
rootdir=$(readlink -f $INITIATOR_JSON_DIR/../../..)
|
||||
|
||||
rpc_py="$spdk_rpc_py"
|
||||
clear_config_py="$spdk_clear_config_py"
|
||||
load_nvme
|
||||
|
||||
construct_vhost_devices
|
||||
test_json_config
|
||||
run_initiator
|
||||
rpc_py="$initiator_rpc_py"
|
||||
clear_config_py="$initiator_clear_config_py"
|
||||
$rpc_py start_subsystem_init
|
||||
connect_to_vhost_devices_from_initiator
|
||||
test_json_config
|
||||
disconnect_and_clear_vhost_devices
|
||||
test_global_params "virtio_initiator"
|
||||
clear_config_py="$spdk_clear_config_py"
|
||||
$clear_config_py clear_config
|
||||
kill_targets
|
||||
}
|
||||
|
||||
trap 'on_error_exit "${FUNCNAME}" "${LINENO}"' ERR
|
||||
timing_enter json_config_virtio_initiator
|
||||
|
||||
test_subsystems
|
||||
timing_exit json_config_virtio_initiator
|
||||
report_test_completion json_config_virtio_initiator
|
Loading…
Reference in New Issue
Block a user