Skip to content

Commit

Permalink
Export partition_type when cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 28, 2018
1 parent ba6a1f1 commit bbb5a9d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/modules/AutoinstPartPlan.rb
Expand Up @@ -426,9 +426,9 @@ def ReadHelper
Ops.set(new_pe, "create", false)
end
end
if Builtins.haskey(pe, "type") &&
Ops.get_symbol(pe, "type", :x) == :primary
Ops.set(new_pe, "partition_type", "primary") # can we always copy that element?
# Consider the partition type when dealing with 'msdos' partition tables (bsc#1091415)
if Builtins.haskey(pe, "type") && v["label"] == "msdos"
Ops.set(new_pe, "partition_type", pe["type"].to_s)
end
if Builtins.haskey(pe, "region") &&
Ops.get_boolean(new_pe, "create", true) == true
Expand Down
62 changes: 34 additions & 28 deletions src/modules/AutoinstPartition.rb
Expand Up @@ -27,33 +27,34 @@ def main
# defines data structur of a partition
# provides types for type checking
@fields = {
"crypt" => "",
"crypt_fs" => false,
"crypt_key" => "",
"create" => true,
"mount" => "/",
"fstopt" => "",
"label" => "",
"loop_fs" => false,
"uuid" => "",
"size" => "10G",
"format" => true,
"filesystem" => Partitions.DefaultFs,
"mkfs_options" => "",
"partition_nr" => 1,
"partition_id" => 131,
"mountby" => :device,
"resize" => false,
"lv_name" => "",
"stripes" => 1,
"stripesize" => 4,
"lvm_group" => "",
"raid_name" => "",
"raid_type" => "",
"raid_options" => {},
"subvolumes" => [],
"pool" => false,
"used_pool" => ""
"crypt" => "",
"crypt_fs" => false,
"crypt_key" => "",
"create" => true,
"mount" => "/",
"fstopt" => "",
"label" => "",
"loop_fs" => false,
"uuid" => "",
"size" => "10G",
"format" => true,
"filesystem" => Partitions.DefaultFs,
"mkfs_options" => "",
"partition_nr" => 1,
"partition_id" => 131,
"mountby" => :device,
"resize" => false,
"lv_name" => "",
"stripes" => 1,
"stripesize" => 4,
"lvm_group" => "",
"partition_type" => "",
"pool" => false,
"raid_name" => "",
"raid_type" => "",
"raid_options" => {},
"subvolumes" => [],
"used_pool" => ""
}

@allfs = {}
Expand Down Expand Up @@ -293,12 +294,17 @@ def parsePartition(part)
newPart = Builtins.remove(newPart, "pool")
end
newPart = set(newPart, "loop_fs", Ops.get_boolean(part, "loop_fs", false))
if part.has_key?("partition_id")
if part.key?("partition_id")
newPart["partition_id"] = part["partition_id"]
else
#removing default entry
newPart.delete("partition_id")
end
if part.key?("partition_type")
newPart = set(newPart, "partition_type", part["partition_type"].to_s)
else
newPart.delete("partition_type")
end
newPart = set(newPart, "size", Ops.get_string(part, "size", ""))
newPart = set(newPart, "lv_name", Ops.get_string(part, "lv_name", ""))
newPart = set(newPart, "lvm_group", Ops.get_string(part, "lvm_group", ""))
Expand Down
18 changes: 18 additions & 0 deletions test/AutoinstPartPlan_test.rb
Expand Up @@ -87,5 +87,23 @@
snapshots = subvolumes.select { |s| s.include?("snapshot") }
expect(snapshots).to be_empty
end

context "when the drive has a msdos partition" do
it "includes the partition_type" do
exported = subject.Export
partition = exported.first["partitions"].first
expect(partition).to include("partition_type" => "primary")
end
end

context "when the drive has a non-msdos partition" do
let(:target_map) { YAML.load_file(File.join(FIXTURES_PATH, "storage", "target_clone.yml")) }

it "does not include the partition_type" do
exported = subject.Export
partition = exported.first["partitions"].first
expect(partition).to_not have_key("partition_type")
end
end
end
end
22 changes: 22 additions & 0 deletions test/AutoinstPartition_test.rb
Expand Up @@ -44,5 +44,27 @@
end
end
end

context "when a partition_type is present" do
let(:partition) do
{ "mount" => "/", "partition_type" => "primary" }
end

it "exports the partition type" do
parsed = subject.parsePartition(partition)
expect(parsed["partition_type"]).to eq("primary")
end
end

context "when a partition_type is not present" do
let(:partition) do
{ "mount" => "/" }
end

it "ignores the partition_type" do
parsed = subject.parsePartition(partition)
expect(parsed).to_not have_key("partition_type")
end
end
end
end

0 comments on commit bbb5a9d

Please sign in to comment.