Commit 690e04cc authored by intrigeri's avatar intrigeri
Browse files

Test suite: add support for creating arbitrarily sized partitions.

parent ef91ecb9
......@@ -20,10 +20,12 @@ Then /^Tails has no disk swap enabled$/ do
mem_info)
end
Given /^I create an? ([[:alnum:]]+) partition( labeled "([^"]+)")? with an? ([[:alnum:]]+) filesystem( encrypted with password "([^"]+)")? on disk "([^"]+)"$/ do |parttype, has_label, label, fstype, is_encrypted, luks_password, name|
Given /^I create an?( (\d+) ([[:alpha:]]+))? ([[:alnum:]]+) partition( labeled "([^"]+)")? with an? ([[:alnum:]]+) filesystem( encrypted with password "([^"]+)")? on disk "([^"]+)"$/ do |with_size, size, unit, parttype, has_label, label, fstype, is_encrypted, luks_password, name|
opts = {}
opts.merge!(:label => label) if has_label
opts.merge!(:luks_password => luks_password) if is_encrypted
opts.merge!(:size => size) if with_size
opts.merge!(:unit => unit) if with_size
$vm.storage.disk_mkpartfs(name, parttype, fstype, opts)
end
......
......@@ -156,8 +156,22 @@ class VMStorage
def disk_mkpartfs(name, parttype, fstype, opts = {})
opts[:label] ||= nil
opts[:luks_password] ||= nil
opts[:size] ||= nil
opts[:unit] ||= nil
guestfs_disk_helper(name) do |g, disk_handle|
g.part_disk(disk_handle, parttype)
if ! opts[:size].nil? and ! opts[:unit].nil?
g.part_init(disk_handle, parttype)
size_in_bytes = convert_to_bytes(opts[:size].to_f, opts[:unit])
sector_size = g.blockdev_getss(disk_handle)
size_in_sectors = (size_in_bytes / sector_size).floor
# leave some room for the partition table
offset_in_sectors = (convert_to_bytes(4, 'MiB') / sector_size).floor
g.part_add(disk_handle, 'primary',
offset_in_sectors,
offset_in_sectors + size_in_sectors - 1)
else
g.part_disk(disk_handle, parttype)
end
g.part_set_name(disk_handle, 1, opts[:label]) if opts[:label]
primary_partition = g.list_partitions()[0]
if opts[:luks_password]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment