test/vhost: avoid setting nullglob's where possible
If any command fail while nullglob is set error handlers find bizare shell state and sometimes fail with odd errors. To avoid this introduce function that will never leave nullglob set after return Change-Id: Iff8ae410072c4e5f7f9e72e28171fc24e6186f5f Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/397092 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
2b8c23c7b8
commit
db0c317436
@ -362,15 +362,24 @@ function vm_kill()
|
||||
fi
|
||||
}
|
||||
|
||||
# List all VM numbers in VM_BASE_DIR
|
||||
#
|
||||
function vm_list_all()
|
||||
{
|
||||
local vms="$(shopt -s nullglob; echo $VM_BASE_DIR/[0-9])"
|
||||
if [[ ! -z "$vms" ]]; then
|
||||
basename --multiple $vms
|
||||
fi
|
||||
}
|
||||
|
||||
# Kills all VM in $VM_BASE_DIR
|
||||
#
|
||||
function vm_kill_all()
|
||||
{
|
||||
shopt -s nullglob
|
||||
for vm in $VM_BASE_DIR/[0-9]*; do
|
||||
vm_kill $(basename $vm)
|
||||
local vm
|
||||
for vm in $(vm_list_all); do
|
||||
vm_kill $vm
|
||||
done
|
||||
shopt -u nullglob
|
||||
}
|
||||
|
||||
# Shutdown all VM in $VM_BASE_DIR
|
||||
@ -380,8 +389,10 @@ function vm_shutdown_all()
|
||||
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
|
||||
set +x
|
||||
|
||||
shopt -s nullglob
|
||||
for vm in $VM_BASE_DIR/[0-9]*; do
|
||||
local vms=$(vm_list_all)
|
||||
local vm
|
||||
|
||||
for vm in $vms; do
|
||||
vm_shutdown $(basename $vm)
|
||||
done
|
||||
|
||||
@ -389,7 +400,7 @@ function vm_shutdown_all()
|
||||
timeo=15
|
||||
while [[ $timeo -gt 0 ]]; do
|
||||
all_vms_down=1
|
||||
for vm in $VM_BASE_DIR/[0-9]*; do
|
||||
for vm in $vms; do
|
||||
if [[ -r $vm/qemu.pid ]] && pkill -0 -F "$vm/qemu.pid"; then
|
||||
all_vms_down=0
|
||||
break
|
||||
@ -398,7 +409,6 @@ function vm_shutdown_all()
|
||||
|
||||
if [[ $all_vms_down == 1 ]]; then
|
||||
notice "All VMs successfully shut down"
|
||||
shopt -u nullglob
|
||||
$shell_restore_x
|
||||
return 0
|
||||
fi
|
||||
@ -406,8 +416,9 @@ function vm_shutdown_all()
|
||||
((timeo-=1))
|
||||
sleep 1
|
||||
done
|
||||
shopt -u nullglob
|
||||
|
||||
$shell_restore_x
|
||||
error "Timout waiting for some VMs to shutdown"
|
||||
return 1
|
||||
}
|
||||
|
||||
@ -696,8 +707,10 @@ function vm_setup()
|
||||
|
||||
function vm_run()
|
||||
{
|
||||
local OPTIND optchar a
|
||||
local OPTIND optchar vm
|
||||
local run_all=false
|
||||
local vms_to_run=""
|
||||
|
||||
while getopts 'a-:' optchar; do
|
||||
case "$optchar" in
|
||||
a) run_all=true ;;
|
||||
@ -708,11 +721,8 @@ function vm_run()
|
||||
esac
|
||||
done
|
||||
|
||||
local vms_to_run=""
|
||||
|
||||
if $run_all; then
|
||||
shopt -s nullglob
|
||||
vms_to_run=$VM_BASE_DIR/[0-9]*
|
||||
vms_to_run="$(vm_list_all)"
|
||||
else
|
||||
shift $((OPTIND-1))
|
||||
for vm in $@; do
|
||||
@ -721,18 +731,18 @@ function vm_run()
|
||||
error "VM$vm not defined - setup it first"
|
||||
return 1
|
||||
fi
|
||||
vms_to_run+=" $VM_BASE_DIR/$vm"
|
||||
vms_to_run+=" $vm"
|
||||
done
|
||||
fi
|
||||
|
||||
for vm in $vms_to_run; do
|
||||
if vm_is_running $(basename $vm); then
|
||||
warning "VM$(basename $vm) ($vm) already running"
|
||||
if vm_is_running $vm; then
|
||||
warning "VM$vm ($VM_BASE_DIR/$vm) already running"
|
||||
continue
|
||||
fi
|
||||
|
||||
notice "running $vm/run.sh"
|
||||
if ! $vm/run.sh; then
|
||||
notice "running $VM_BASE_DIR$vm/run.sh"
|
||||
if ! $VM_BASE_DIR/$vm/run.sh; then
|
||||
error "FAILED to run vm $vm"
|
||||
return 1
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user