5 testdir
=$
(readlink
-f $
(dirname $0))
6 rootdir
=$
(readlink
-f $testdir/..
/..
/..
)
7 source $rootdir/test
/common
/autotest_common.sh
8 source $rootdir/test
/vhost
/common.sh
12 declare -A vms_raw_disks
14 declare -A vms_ctrlrs_disks
16 # By default use Guest fio
25 [[ ! -z $2 ]] && ( echo "$2"; echo ""; )
26 echo "Shortcut script for doing automated test of live migration."
27 echo "Usage: $(basename $1) [OPTIONS]"
29 echo " --os ARGS VM configuration. This parameter might be used more than once:"
30 echo " --fio-bin=FIO Use specific fio binary (will be uploaded to VM)"
31 echo " --test-cases=TESTS Coma-separated list of tests to run. Implemented test cases are: 1"
32 echo " See test/vhost/test_plan.md for more info."
33 echo " --mgmt-tgt-ip=IP IP address of target."
34 echo " --mgmt-init-ip=IP IP address of initiator."
35 echo " --rdma-tgt-ip=IP IP address of targets rdma capable NIC."
36 echo " --rdma-init-ip=IP IP address of initiators rdma capable NIC."
37 echo "-x set -x for script debug"
46 --os=*) os_image
="${param#*=}" ;;
47 --fio-bin=*) fio_bin
="${param}" ;;
48 --test-cases=*) test_cases
="${param#*=}" ;;
49 --mgmt-tgt-ip=*) MGMT_TARGET_IP
="${param#*=}" ;;
50 --mgmt-init-ip=*) MGMT_INITIATOR_IP
="${param#*=}" ;;
51 --rdma-tgt-ip=*) RDMA_TARGET_IP
="${param#*=}" ;;
52 --rdma-init-ip=*) RDMA_INITIATOR_IP
="${param#*=}" ;;
54 -v) SPDK_VHOST_VERBOSE
=true
;;
56 usage
$0 "Invalid argument '$param'"
63 [[ ! -z "$test_cases" ]] || fail
"Need '--test-cases=' parameter"
65 trap 'error_exit "${FUNCNAME}" "${LINENO}"' INT ERR EXIT
67 function vm_monitor_send
()
70 local cmd_result_file
="$2"
71 local vm_dir
="$VM_BASE_DIR/$1"
72 local vm_monitor_port
=$
(cat $vm_dir/monitor_port
)
74 [[ ! -z "$vm_monitor_port" ]] || fail
"No monitor port!"
77 nc
127.0.0.1 $vm_monitor_port "$@" > $cmd_result_file
83 local from_vm_dir
="$VM_BASE_DIR/$1"
84 local target_vm_dir
="$(readlink -e $from_vm_dir/vm_migrate_to)"
85 local target_vm
="$(basename $target_vm_dir)"
86 local target_vm_migration_port
="$(cat $target_vm_dir/migration_port)"
87 if [[ -n "$2" ]]; then
90 local target_ip
="127.0.0.1"
93 # Sanity check if target VM (QEMU) is configured to accept source VM (QEMU) migration
94 if [[ "$(readlink -e ${target_vm_dir}/vm_incoming)" != "$(readlink -e ${from_vm_dir})" ]]; then
95 fail
"source VM $1 or destination VM is not properly configured for live migration"
98 timing_enter vm_migrate
99 notice
"Migrating VM $1 to VM "$
(basename $target_vm_dir)
101 "migrate_set_speed 1g\n" \
102 "migrate tcp:$target_ip:$target_vm_migration_port\n" \
104 "quit" | vm_monitor_send
$1 "$from_vm_dir/migration_result"
106 # Post migration checks:
107 if ! grep "Migration status: completed" $from_vm_dir/migration_result
-q; then
108 cat $from_vm_dir/migration_result
109 fail
"Migration failed:\n"
112 # Don't perform the following check if target VM is on remote server
113 # as we won't have access to it.
114 # If you need this check then perform it on your own.
115 if [[ "$target_ip" == "127.0.0.1" ]]; then
116 if ! vm_os_booted
$target_vm; then
117 fail
"VM$target_vm is not running"
118 cat $target_vm $target_vm_dir/cont_result
122 notice
"Migration complete"
123 timing_exit vm_migrate
126 function is_fio_running
()
128 local shell_restore_x
="$( [[ "$
-" =~ x ]] && echo 'set -x' )"
131 if vm_ssh
$1 'kill -0 $(cat /root/fio.pid)'; then
141 for test_case
in ${test_cases//,/ }; do
142 assert_number
"$test_case"
143 notice
"==============================="
144 notice
"Running Migration test case ${test_case}"
145 notice
"==============================="
147 timing_enter migration-tc
${test_case}
148 source $testdir/migration-tc
${test_case}.sh
149 timing_exit migration-tc
${test_case}
152 notice
"Migration Test SUCCESS"
153 notice
"==============="
155 trap - SIGINT ERR EXIT