Isolated environment removes virtual machines after run.

This commit is contained in:
Mitchell Hashimoto 2011-11-06 18:45:49 -08:00
parent 797f124e6d
commit 2febc9fcff
1 changed files with 17 additions and 0 deletions

View File

@ -109,6 +109,23 @@ module Acceptance
# Closes the environment, cleans up the temporary directories, etc. # Closes the environment, cleans up the temporary directories, etc.
def close def close
# Delete all virtual machines
@logger.debug("Finding all virtual machines")
execute("VBoxManage", "list", "vms").stdout.lines.each do |line|
data = /^"(?<name>.+?)" {(?<uuid>.+?)}$/.match(line)
@logger.debug("Removing VM: #{data[:name]}")
result = execute("VBoxManage", "controlvm", data[:uuid], "poweroff")
raise Exception, "VM halt failed!" if result.exit_status != 0
sleep 0.5
result = execute("VBoxManage", "unregistervm", data[:uuid], "--delete")
raise Exception, "VM unregistration failed!" if result.exit_status != 0
end
@logger.info("Removed all virtual machines")
# Delete the temporary directory # Delete the temporary directory
@logger.info("Removing isolated environment: #{@tempdir.path}") @logger.info("Removing isolated environment: #{@tempdir.path}")
FileUtils.rm_rf(@tempdir.path) FileUtils.rm_rf(@tempdir.path)