summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--features/step_definitions/common_steps.rb4
-rw-r--r--features/support/helpers/vm_helper.rb41
-rw-r--r--features/support/hooks.rb4
3 files changed, 16 insertions, 33 deletions
diff --git a/features/step_definitions/common_steps.rb b/features/step_definitions/common_steps.rb
index 8cf8ecd..bb8aeb1 100644
--- a/features/step_definitions/common_steps.rb
+++ b/features/step_definitions/common_steps.rb
@@ -62,7 +62,7 @@ def restore_background
end
Given /^a computer$/ do
- @vm.destroy if @vm
+ @vm.destroy_and_undefine if @vm
@vm = VM.new($virt, $vm_xml_path, $vmnet, $vmstorage, $x_display)
end
@@ -207,7 +207,7 @@ end
When /^I destroy the computer$/ do
next if @skip_steps_while_restoring_background
- @vm.destroy
+ @vm.destroy_and_undefine
end
Given /^the computer (re)?boots Tails$/ do |reboot|
diff --git a/features/support/helpers/vm_helper.rb b/features/support/helpers/vm_helper.rb
index 6a12993..5656b73 100644
--- a/features/support/helpers/vm_helper.rb
+++ b/features/support/helpers/vm_helper.rb
@@ -10,15 +10,13 @@ class VMNet
net_xml = File.read("#{xml_path}/default_net.xml")
update(net_xml)
rescue Exception => e
- clean_up
+ destroy_and_undefine
raise e
end
- # Used internally to clean up previous created libvirt networks with
- # same name. We lookup by name so we also catch networks from
- # previous test suite runs that weren't properly cleaned up
- # (e.g. aborted).
- def clean_up
+ # We lookup by name so we also catch networks from previous test
+ # suite runs that weren't properly cleaned up (e.g. aborted).
+ def destroy_and_undefine
begin
old_net = @virt.lookup_network_by_name(@net_name)
old_net.destroy if old_net.active?
@@ -30,16 +28,11 @@ class VMNet
def update(xml)
net_xml = REXML::Document.new(xml)
@net_name = net_xml.elements['network/name'].text
- clean_up
+ destroy_and_undefine
@net = @virt.define_network_xml(xml)
@net.create
end
- def destroy
- @net.destroy if net.active?
- @net.undefine
- end
-
def bridge_name
@net.bridge_name
end
@@ -48,8 +41,6 @@ class VMNet
File.open("/sys/class/net/#{bridge_name}/address", "rb").read.chomp
end
- private :clean_up
-
end
@@ -68,26 +59,25 @@ class VM
set_cdrom_boot($tails_iso)
plug_network
rescue Exception => e
- clean_up
+ destroy_and_undefine
raise e
end
def update(xml)
domain_xml = REXML::Document.new(xml)
@domain_name = domain_xml.elements['domain/name'].text
- clean_up
+ destroy_and_undefine
@domain = @virt.define_domain_xml(xml)
end
- # Used internally to clean up previous created libvirt domains with
- # same name. We lookup by name so we also catch domains from
- # previous test suite runs that weren't properly cleaned up
- # (e.g. aborted).
- def clean_up
+ # We lookup by name so we also catch domains from previous test
+ # suite runs that weren't properly cleaned up (e.g. aborted).
+ def destroy_and_undefine
begin
old_domain = @virt.lookup_domain_by_name(@domain_name)
old_domain.destroy if old_domain.active?
old_domain.undefine
+ @display.stop if @display && @display.active?
rescue
end
end
@@ -408,7 +398,7 @@ EOF
def restore_snapshot(path)
# Clean up current domain so its snapshot can be restored
- clean_up
+ destroy_and_undefine
Libvirt::Domain::restore(@virt, path)
@domain = @virt.lookup_domain_by_name(@domain_name)
@display.start
@@ -431,11 +421,6 @@ EOF
@display.stop
end
- def destroy
- clean_up
- power_off
- end
-
def take_screenshot(description)
@display.take_screenshot(description)
end
@@ -449,6 +434,4 @@ EOF
end
end
- private :clean_up
-
end
diff --git a/features/support/hooks.rb b/features/support/hooks.rb
index 4dce707..cf79832 100644
--- a/features/support/hooks.rb
+++ b/features/support/hooks.rb
@@ -70,7 +70,7 @@ end
AfterFeature('@product') do
delete_snapshot($background_snapshot) if !$keep_snapshots
$vmstorage.clear_pool
- $vmnet.destroy
+ $vmnet.destroy_and_undefine
$virt.close
end
@@ -123,7 +123,7 @@ After('@product') do |scenario|
@sniffer.stop
@sniffer.clear
end
- @vm.destroy if @vm
+ @vm.destroy_and_undefine if @vm
end
After('@product', '~@keep_volumes') do