]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/vhost/migration/migration.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / test / vhost / migration / migration.sh
1 #!/usr/bin/env bash
2
3 set -e
4
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
9
10 vms=()
11 declare -A vms_os
12 declare -A vms_raw_disks
13 declare -A vms_ctrlrs
14 declare -A vms_ctrlrs_disks
15
16 # By default use Guest fio
17 fio_bin=""
18 test_cases=""
19 MGMT_TARGET_IP=""
20 MGMT_INITIATOR_IP=""
21 RDMA_TARGET_IP=""
22 RDMA_INITIATOR_IP=""
23 function usage()
24 {
25 [[ ! -z $2 ]] && ( echo "$2"; echo ""; )
26 echo "Shortcut script for doing automated test of live migration."
27 echo "Usage: $(basename $1) [OPTIONS]"
28 echo
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"
38 }
39
40 for param in "$@"; do
41 case "$param" in
42 --help|-h)
43 usage $0
44 exit 0
45 ;;
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#*=}" ;;
53 -x) set -x ;;
54 -v) SPDK_VHOST_VERBOSE=true ;;
55 *)
56 usage $0 "Invalid argument '$param'"
57 exit 1;;
58 esac
59 done
60
61 vhosttestinit
62
63 [[ ! -z "$test_cases" ]] || fail "Need '--test-cases=' parameter"
64
65 trap 'error_exit "${FUNCNAME}" "${LINENO}"' INT ERR EXIT
66
67 function vm_monitor_send()
68 {
69 local vm_num=$1
70 local cmd_result_file="$2"
71 local vm_dir="$VM_BASE_DIR/$1"
72 local vm_monitor_port=$(cat $vm_dir/monitor_port)
73
74 [[ ! -z "$vm_monitor_port" ]] || fail "No monitor port!"
75
76 shift 2
77 nc 127.0.0.1 $vm_monitor_port "$@" > $cmd_result_file
78 }
79
80 # Migrate VM $1
81 function vm_migrate()
82 {
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
88 local target_ip=$2
89 else
90 local target_ip="127.0.0.1"
91 fi
92
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"
96 fi
97
98 timing_enter vm_migrate
99 notice "Migrating VM $1 to VM "$(basename $target_vm_dir)
100 echo -e \
101 "migrate_set_speed 1g\n" \
102 "migrate tcp:$target_ip:$target_vm_migration_port\n" \
103 "info migrate\n" \
104 "quit" | vm_monitor_send $1 "$from_vm_dir/migration_result"
105
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"
110 fi
111
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
119 fi
120 fi
121
122 notice "Migration complete"
123 timing_exit vm_migrate
124 }
125
126 function is_fio_running()
127 {
128 local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
129 set +x
130
131 if vm_ssh $1 'kill -0 $(cat /root/fio.pid)'; then
132 local ret=0
133 else
134 local ret=1
135 fi
136
137 $shell_restore_x
138 return $ret
139 }
140
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 "==============================="
146
147 timing_enter migration-tc${test_case}
148 source $testdir/migration-tc${test_case}.sh
149 timing_exit migration-tc${test_case}
150 done
151
152 notice "Migration Test SUCCESS"
153 notice "==============="
154
155 trap - SIGINT ERR EXIT
156
157 vhosttestfini