Browse Source

Do not die if removing guest but guest is not running.

pull/10/head
Giovanni Torres 8 years ago
parent
commit
cc489b59d1
  1. 3
      kvm-install-vm
  2. 19
      tests/check_destroy.bats

3
kvm-install-vm

@ -142,6 +142,7 @@ function usage_subcommand ()
bold() { echo -e "\e[1m$@\e[0m" ; }
red() { echo -e "\e[31m$@\e[0m" ; }
green() { echo -e "\e[32m$@\e[0m" ; }
yellow() { echo -e "\e[33m$@\e[0m" ; }
die() { red "ERR: $@" >&2 ; exit 2 ; }
silent() { "$@" > /dev/null 2>&1 ; }
@ -177,7 +178,7 @@ function delete_vm ()
outputn "Destroying ${VMNAME} domain"
virsh destroy ${VMNAME} > /dev/null 2>&1 \
&& ok \
|| die "Could not destroy domain."
|| yellow "(Domain is not running.)"
outputn "Undefining ${VMNAME} domain"
virsh undefine ${VMNAME} > /dev/null 2>&1 \

19
tests/check_destroy.bats

@ -0,0 +1,19 @@
#!/usr/bin/env bats
VMPREFIX=batstestvm
@test "Install VM - $VMPREFIX-centos7-destroy" {
run kvm-install-vm create ${VMPREFIX}-centos7-destroy
[ "$status" -eq 0 ]
}
@test "Shutdown/Destroy VM - $VMPREFIX-centos7-destroy" {
run virsh destroy $VMPREFIX-centos7-destroy
[ "$status" -eq 0 ]
}
@test "Delete VM - $VMPREFIX-centos7-destroy" {
run kvm-install-vm remove ${VMPREFIX}-centos7-destroy
[[ "${lines[0]}" =~ "Domain is not running" ]]
[ "$status" -eq 0 ]
}
Loading…
Cancel
Save