summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTails developers <tails@boum.org>2015-02-15 17:56:21 +0000
committerTails developers <tails@boum.org>2015-02-15 21:32:47 +0000
commit22fef2ac412ae7fc0d70f76d60d5d569974bcd5d (patch)
treec14090e8ae859085cd54832289b73426a7ac90ed
parent9ab9774eda23c1fad50a120ad1296deb78c9056a (diff)
Check available free space before trying to create storage disks.
-rw-r--r--features/support/helpers/misc_helpers.rb15
-rw-r--r--features/support/helpers/storage_helper.rb5
2 files changed, 20 insertions, 0 deletions
diff --git a/features/support/helpers/misc_helpers.rb b/features/support/helpers/misc_helpers.rb
index 9b015b0..e2d57a3 100644
--- a/features/support/helpers/misc_helpers.rb
+++ b/features/support/helpers/misc_helpers.rb
@@ -119,3 +119,18 @@ def save_pcap_file
FileUtils.cp(@sniffer.pcap_file, pcap_copy)
puts "Full network capture available at: #{pcap_copy}"
end
+
+def get_free_space(machine, path)
+ case machine
+ when 'host'
+ assert(File.exists?(path), "Path '#{path}' not found on #{machine}.")
+ free = `df "#{path}"`
+ when 'guest'
+ assert(@vm.file_exist?(path), "Path '#{path}' not found on #{machine}.")
+ free = @vm.execute_successfully("df '#{path}'")
+ else
+ raise 'Unsupported machine type #{machine} passed.'
+ end
+ output = free.split("\n").last
+ return output.match(/[^\s]\s+[0-9]+\s+[0-9]+\s+([0-9]+)\s+.*/)[1].chomp.to_i
+end
diff --git a/features/support/helpers/storage_helper.rb b/features/support/helpers/storage_helper.rb
index 8ebe360..9860e2a 100644
--- a/features/support/helpers/storage_helper.rb
+++ b/features/support/helpers/storage_helper.rb
@@ -70,6 +70,11 @@ class VMStorage
options[:size] ||= 2
options[:unit] ||= "GiB"
options[:type] ||= "qcow2"
+ needed = convert_to_MiB(options[:size].to_i, options[:unit]) + 500
+ avail = convert_to_MiB(get_free_space('host', "#{@pool_path}"), "KiB")
+ assert(avail > needed, "Error creating disk \"#{name}\" in \"#{@pool_path}\". Need " +
+ "#{needed} MiB but only #{avail} MiB is available.")
+
begin
old_vol = @pool.lookup_volume_by_name(name)
rescue Libvirt::RetrieveError