diff --git a/kvm-install-vm b/kvm-install-vm index 5a00943..3339d1a 100755 --- a/kvm-install-vm +++ b/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 \ diff --git a/tests/check_destroy.bats b/tests/check_destroy.bats new file mode 100644 index 0000000..063f8ea --- /dev/null +++ b/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 ] +}