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
|
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
|
# Kills all VM in $VM_BASE_DIR
|
||||||
#
|
#
|
||||||
function vm_kill_all()
|
function vm_kill_all()
|
||||||
{
|
{
|
||||||
shopt -s nullglob
|
local vm
|
||||||
for vm in $VM_BASE_DIR/[0-9]*; do
|
for vm in $(vm_list_all); do
|
||||||
vm_kill $(basename $vm)
|
vm_kill $vm
|
||||||
done
|
done
|
||||||
shopt -u nullglob
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Shutdown all VM in $VM_BASE_DIR
|
# Shutdown all VM in $VM_BASE_DIR
|
||||||
@ -380,8 +389,10 @@ function vm_shutdown_all()
|
|||||||
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
|
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
shopt -s nullglob
|
local vms=$(vm_list_all)
|
||||||
for vm in $VM_BASE_DIR/[0-9]*; do
|
local vm
|
||||||
|
|
||||||
|
for vm in $vms; do
|
||||||
vm_shutdown $(basename $vm)
|
vm_shutdown $(basename $vm)
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -389,7 +400,7 @@ function vm_shutdown_all()
|
|||||||
timeo=15
|
timeo=15
|
||||||
while [[ $timeo -gt 0 ]]; do
|
while [[ $timeo -gt 0 ]]; do
|
||||||
all_vms_down=1
|
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
|
if [[ -r $vm/qemu.pid ]] && pkill -0 -F "$vm/qemu.pid"; then
|
||||||
all_vms_down=0
|
all_vms_down=0
|
||||||
break
|
break
|
||||||
@ -398,7 +409,6 @@ function vm_shutdown_all()
|
|||||||
|
|
||||||
if [[ $all_vms_down == 1 ]]; then
|
if [[ $all_vms_down == 1 ]]; then
|
||||||
notice "All VMs successfully shut down"
|
notice "All VMs successfully shut down"
|
||||||
shopt -u nullglob
|
|
||||||
$shell_restore_x
|
$shell_restore_x
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@ -406,8 +416,9 @@ function vm_shutdown_all()
|
|||||||
((timeo-=1))
|
((timeo-=1))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
shopt -u nullglob
|
|
||||||
$shell_restore_x
|
$shell_restore_x
|
||||||
|
error "Timout waiting for some VMs to shutdown"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,8 +707,10 @@ function vm_setup()
|
|||||||
|
|
||||||
function vm_run()
|
function vm_run()
|
||||||
{
|
{
|
||||||
local OPTIND optchar a
|
local OPTIND optchar vm
|
||||||
local run_all=false
|
local run_all=false
|
||||||
|
local vms_to_run=""
|
||||||
|
|
||||||
while getopts 'a-:' optchar; do
|
while getopts 'a-:' optchar; do
|
||||||
case "$optchar" in
|
case "$optchar" in
|
||||||
a) run_all=true ;;
|
a) run_all=true ;;
|
||||||
@ -708,11 +721,8 @@ function vm_run()
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
local vms_to_run=""
|
|
||||||
|
|
||||||
if $run_all; then
|
if $run_all; then
|
||||||
shopt -s nullglob
|
vms_to_run="$(vm_list_all)"
|
||||||
vms_to_run=$VM_BASE_DIR/[0-9]*
|
|
||||||
else
|
else
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
for vm in $@; do
|
for vm in $@; do
|
||||||
@ -721,18 +731,18 @@ function vm_run()
|
|||||||
error "VM$vm not defined - setup it first"
|
error "VM$vm not defined - setup it first"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
vms_to_run+=" $VM_BASE_DIR/$vm"
|
vms_to_run+=" $vm"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for vm in $vms_to_run; do
|
for vm in $vms_to_run; do
|
||||||
if vm_is_running $(basename $vm); then
|
if vm_is_running $vm; then
|
||||||
warning "VM$(basename $vm) ($vm) already running"
|
warning "VM$vm ($VM_BASE_DIR/$vm) already running"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
notice "running $vm/run.sh"
|
notice "running $VM_BASE_DIR$vm/run.sh"
|
||||||
if ! $vm/run.sh; then
|
if ! $VM_BASE_DIR/$vm/run.sh; then
|
||||||
error "FAILED to run vm $vm"
|
error "FAILED to run vm $vm"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user