From 057b95e3ef1154d7640f39423f57530e36dd92dc Mon Sep 17 00:00:00 2001 From: Serhiy Ovsianikov Date: Thu, 11 Dec 2014 11:31:23 +0200 Subject: [PATCH] Correct search of name virtual machines in list In the functions is_vm_running() and is_vm_present(), located in the file function/vm.sh, search of running and available virtual machines has been fixed. The search of the names virtual machines extrafuel-master and extrafuel-slave-1 didn't work correctly. Change-Id: If73546e5b4b2a8a64f0b955f85579ee0dafd93f0 Closes-Bug: #1387602 --- functions/vm.sh | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/functions/vm.sh b/functions/vm.sh index 6a3cff8..67bc067 100755 --- a/functions/vm.sh +++ b/functions/vm.sh @@ -33,22 +33,24 @@ is_vm_running() { list=$(get_vms_running) # Check that the list of running VMs contains the given VM - if [[ $list = *$name* ]]; then - return 0 - else - return 1 - fi + for name_in_list in $list; do + if [[ "$name_in_list" == "$name" ]]; then + return 0 + fi + done + return 1 } is_vm_present() { name=$1 list=$(get_vms_present) - if [[ $list = *$name* ]]; then - return 0 - else - return 1 - fi + for name_in_list in $list; do + if [[ "$name_in_list" == "$name" ]]; then + return 0 + fi + done + return 1 } create_vm() { @@ -129,9 +131,18 @@ delete_vm() { vm_path="$vm_base_path/$name/" # Power off VM, if it's running - if is_vm_running $name; then + count=0 + while is_vm_running $name; do + echo "Stopping Virtual Machine $name..." VBoxManage controlvm $name poweroff - fi + if [[ "$count" != 5 ]]; then + count=$((count+1)) + sleep 5 + else + echo "VirtualBox cannot stop VM $name... Exiting" + exit 1 + fi + done echo "Deleting existing virtual machine $name..." while is_vm_present $name