]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/test/vhost/hotplug/common.sh
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / vhost / hotplug / common.sh
CommitLineData
9f95a23c
TL
1testdir=$(readlink -f $(dirname $0))
2rootdir=$(readlink -f $testdir/../../..)
3source $rootdir/test/common/autotest_common.sh
4source $rootdir/test/vhost/common.sh
5
11fdf7f2
TL
6dry_run=false
7no_shutdown=false
8fio_bin="fio"
9f95a23c 9fio_jobs="$testdir/fio_jobs/"
11fdf7f2
TL
10test_type=spdk_vhost_scsi
11reuse_vms=false
12vms=()
13used_vms=""
14disk_split=""
15x=""
16scsi_hot_remove_test=0
17blk_hot_remove_test=0
f67539c2 18readonly=""
11fdf7f2
TL
19
20function usage() {
f67539c2
TL
21 [[ -n $2 ]] && (
22 echo "$2"
23 echo ""
24 )
25 echo "Shortcut script for doing automated hotattach/hotdetach test"
26 echo "Usage: $(basename $1) [OPTIONS]"
27 echo
28 echo "-h, --help print help and exit"
29 echo " --test-type=TYPE Perform specified test:"
30 echo " virtio - test host virtio-scsi-pci using file as disk image"
31 echo " kernel_vhost - use kernel driver vhost-scsi"
32 echo " spdk_vhost_scsi - use spdk vhost scsi"
33 echo " spdk_vhost_blk - use spdk vhost block"
34 echo "-x set -x for script debug"
35 echo " --fio-bin=FIO Use specific fio binary (will be uploaded to VM)"
36 echo " --fio-jobs= Fio configs to use for tests. Can point to a directory or"
37 echo " --vm=NUM[,OS][,DISKS] VM configuration. This parameter might be used more than once:"
38 echo " NUM - VM number (mandatory)"
39 echo " OS - VM os disk path (optional)"
40 echo " DISKS - VM os test disks/devices path (virtio - optional, kernel_vhost - mandatory)"
41 echo " --scsi-hotremove-test Run scsi hotremove tests"
42 echo " --readonly Use readonly for fio"
43 exit 0
11fdf7f2
TL
44}
45
46while getopts 'xh-:' optchar; do
f67539c2
TL
47 case "$optchar" in
48 -)
49 case "$OPTARG" in
50 help) usage $0 ;;
51 fio-bin=*) fio_bin="${OPTARG#*=}" ;;
52 fio-jobs=*) fio_jobs="${OPTARG#*=}" ;;
53 test-type=*) test_type="${OPTARG#*=}" ;;
54 vm=*) vms+=("${OPTARG#*=}") ;;
55 scsi-hotremove-test) scsi_hot_remove_test=1 ;;
56 blk-hotremove-test) blk_hot_remove_test=1 ;;
57 readonly) readonly="--readonly" ;;
58 *) usage $0 "Invalid argument '$OPTARG'" ;;
59 esac
60 ;;
61 h) usage $0 ;;
62 x)
63 set -x
64 x="-x"
65 ;;
66 *) usage $0 "Invalid argument '$OPTARG'" ;;
67 esac
11fdf7f2 68done
f67539c2 69shift $((OPTIND - 1))
11fdf7f2 70
9f95a23c
TL
71fio_job=$testdir/fio_jobs/default_integrity.job
72tmp_attach_job=$testdir/fio_jobs/fio_attach.job.tmp
73tmp_detach_job=$testdir/fio_jobs/fio_detach.job.tmp
11fdf7f2 74
f67539c2 75rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock"
11fdf7f2
TL
76
77function print_test_fio_header() {
f67539c2
TL
78 notice "==============="
79 notice ""
80 notice "Testing..."
11fdf7f2 81
f67539c2
TL
82 notice "Running fio jobs ..."
83 if [ $# -gt 0 ]; then
84 echo $1
85 fi
11fdf7f2
TL
86}
87
11fdf7f2 88function vms_setup() {
f67539c2
TL
89 for vm_conf in "${vms[@]}"; do
90 IFS=',' read -ra conf <<< "$vm_conf"
91 if [[ x"${conf[0]}" == x"" ]] || ! assert_number ${conf[0]}; then
92 fail "invalid VM configuration syntax $vm_conf"
93 fi
11fdf7f2 94
f67539c2
TL
95 # Sanity check if VM is not defined twice
96 for vm_num in $used_vms; do
97 if [[ $vm_num -eq ${conf[0]} ]]; then
98 fail "VM$vm_num defined more than twice ( $(printf "'%s' " "${vms[@]}"))!"
99 fi
100 done
11fdf7f2 101
f67539c2 102 used_vms+=" ${conf[0]}"
11fdf7f2 103
f67539c2
TL
104 setup_cmd="vm_setup --disk-type=$test_type --force=${conf[0]}"
105 [[ x"${conf[1]}" != x"" ]] && setup_cmd+=" --os=${conf[1]}"
106 [[ x"${conf[2]}" != x"" ]] && setup_cmd+=" --disks=${conf[2]}"
107 $setup_cmd
108 done
11fdf7f2
TL
109}
110
111function vm_run_with_arg() {
f67539c2
TL
112 local vms_to_run="$*"
113 vm_run $vms_to_run
114 vm_wait_for_boot 300 $vms_to_run
11fdf7f2
TL
115}
116
117function vms_setup_and_run() {
f67539c2
TL
118 local vms_to_run="$*"
119 vms_setup
120 vm_run_with_arg $vms_to_run
11fdf7f2
TL
121}
122
123function vms_prepare() {
f67539c2
TL
124 for vm_num in $1; do
125 qemu_mask_param="VM_${vm_num}_qemu_mask"
11fdf7f2 126
f67539c2
TL
127 host_name="VM-${vm_num}-${!qemu_mask_param}"
128 notice "Setting up hostname: $host_name"
129 vm_exec $vm_num "hostname $host_name"
130 vm_start_fio_server --fio-bin=$fio_bin $readonly $vm_num
131 done
11fdf7f2
TL
132}
133
134function vms_reboot_all() {
f67539c2
TL
135 notice "Rebooting all vms "
136 for vm_num in $1; do
137 vm_exec $vm_num "reboot" || true
138 while vm_os_booted $vm_num; do
139 sleep 0.5
140 done
141 done
11fdf7f2 142
f67539c2 143 vm_wait_for_boot 300 $1
11fdf7f2
TL
144}
145
146function check_fio_retcode() {
f67539c2
TL
147 local fio_retcode=$3
148 echo $1
149 local retcode_expected=$2
150 if [ $retcode_expected == 0 ]; then
151 if [ $fio_retcode != 0 ]; then
152 error " Fio test ended with error."
153 else
154 notice " Fio test ended with success."
155 fi
156 else
157 if [ $fio_retcode != 0 ]; then
158 notice " Fio test ended with expected error."
159 else
160 error " Fio test ended with unexpected success."
161 fi
162 fi
11fdf7f2
TL
163}
164
165function wait_for_finish() {
f67539c2
TL
166 local wait_for_pid=$1
167 local sequence=${2:-30}
168 for i in $(seq 1 $sequence); do
169 if kill -0 $wait_for_pid; then
170 sleep 0.5
171 continue
172 else
173 break
174 fi
175 done
176 if kill -0 $wait_for_pid; then
177 error "Timeout for fio command"
178 fi
179
180 wait $wait_for_pid
11fdf7f2
TL
181}
182
11fdf7f2 183function reboot_all_and_prepare() {
f67539c2
TL
184 vms_reboot_all "$1"
185 vms_prepare "$1"
11fdf7f2
TL
186}
187
188function post_test_case() {
f67539c2
TL
189 vm_shutdown_all
190 vhost_kill 0
11fdf7f2
TL
191}
192
193function on_error_exit() {
f67539c2
TL
194 set +e
195 echo "Error on $1 - $2"
196 post_test_case
197 print_backtrace
198 exit 1
11fdf7f2
TL
199}
200
201function check_disks() {
f67539c2
TL
202 if [ "$1" == "$2" ]; then
203 echo "Disk has not been deleted"
204 exit 1
205 fi
11fdf7f2
TL
206}
207
208function get_traddr() {
f67539c2
TL
209 local nvme_name=$1
210 local nvme
211 nvme="$($rootdir/scripts/gen_nvme.sh)"
212 while read -r line; do
213 if [[ $line == *"TransportID"* ]] && [[ $line == *$nvme_name* ]]; then
214 local word_array=($line)
215 for word in "${word_array[@]}"; do
216 if [[ $word == *"traddr"* ]]; then
217 traddr=$(echo $word | sed 's/traddr://' | sed 's/"//')
218 fi
219 done
220 fi
221 done <<< "$nvme"
11fdf7f2
TL
222}
223
224function delete_nvme() {
f67539c2 225 $rpc_py bdev_nvme_detach_controller $1
11fdf7f2
TL
226}
227
228function add_nvme() {
f67539c2 229 $rpc_py bdev_nvme_attach_controller -b $1 -t PCIe -a $2
11fdf7f2 230}