Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Dec 2, 2024
1 parent 57e69a1 commit a616f6d
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,32 @@ def partitions

# @return [Array<Hash>]
def used_partitions
new_partitions + reused_partitions
partitions.select { |p| used_partition?(p) }
end

def used_partition?(partition_model)
new_partition?(partition_model) || reused_partition?(partition_model)
end

# @return [Array<Hash>]
def new_partitions
partitions
.reject { |p| p[:name] }
.reject { |p| p[:delete] }
.reject { |p| p[:deleteIfNeeded] }
def new_partition?(partition_model)
partition_model[:name].nil? &&
!partition_model[:delete] &&
!partition_model[:deleteIfNeeded]
end

# TODO: improve check by ensuring the alias is referenced.
#
# @return [Array<Hash>]
def reused_partitions
partitions
.select { |p| p[:name] }
.reject { |p| p[:delete] }
.reject { |p| p[:deleteIfNeeded] }
.select { |p| p[:mountPath] || p[:filesystem] || p[:alias] }
def reused_partition?(partition_model)
any_usage = partition_model[:mountPath] ||
partition_model[:filesystem] ||
partition_model[:alias]

any_usage &&
partition_model[:name] &&
!partition_model[:delete] &&
!partition_model[:deleteIfNeeded]
end

# @return [Configs::Partition]
Expand Down
123 changes: 119 additions & 4 deletions service/test/agama/storage/config_conversions/from_model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,130 @@
end

shared_examples "with spacePolicy and partitions" do |config_proc|
let(:partitions) { [] }
let(:partitions) do
[
{
name: "/dev/vda1",
mountPath: "/data"
},
{
name: "/dev/vda2",
mountPath: "swap",
filesystem: { type: "swap" }
},
{
name: "/dev/vda3",
mountPath: "/home",
size: { default: false, min: 1.GiB.to_i, max: 10.GiB.to_i }
},
{
name: "/dev/vda4",
resizeIfNeeded: true
},
{
name: "/dev/vda5",
deleteIfNeeded: true
},
{
name: "/dev/vda6",
size: { default: false, min: 5.GiB }
},
{
name: "/dev/vda7",
delete: true
},
{
mountPath: "/",
filesystem: { type: "btrfs" }
}
]
end

xcontext "if space policy is 'keep'" do
context "if space policy is 'keep'" do
let(:spacePolicy) { "keep" }

it "sets #partitions to the expected value" do
config = config_proc.call(subject.convert)
partitions = config.partitions
expect(partitions).to be_empty
expect(partitions.size).to eq(4)
expect(partitions[0].search.name).to eq("/dev/vda1")
expect(partitions[1].search.name).to eq("/dev/vda2")
expect(partitions[2].search.name).to eq("/dev/vda3")
expect(partitions[2].size.default?).to eq(false)
expect(partitions[2].size.min).to eq(1.GiB)
expect(partitions[2].size.max).to eq(10.GiB)
expect(partitions[3].filesystem.path).to eq("/")
end
end

context "if space policy is 'delete'" do
let(:spacePolicy) { "delete" }

it "sets #partitions to the expected value" do
config = config_proc.call(subject.convert)
partitions = config.partitions
expect(partitions.size).to eq(5)
expect(partitions[0].search.name).to eq("/dev/vda1")
expect(partitions[1].search.name).to eq("/dev/vda2")
expect(partitions[2].search.name).to eq("/dev/vda3")
expect(partitions[2].size.default?).to eq(false)
expect(partitions[2].size.min).to eq(1.GiB)
expect(partitions[2].size.max).to eq(10.GiB)
expect(partitions[3].filesystem.path).to eq("/")
expect(partitions[4].search.name).to be_nil
expect(partitions[4].search.max).to be_nil
expect(partitions[4].delete).to eq(true)
end
end

context "if space policy is 'resize'" do
let(:spacePolicy) { "resize" }

it "sets #partitions to the expected value" do
config = config_proc.call(subject.convert)
partitions = config.partitions
expect(partitions.size).to eq(5)
expect(partitions[0].search.name).to eq("/dev/vda1")
expect(partitions[1].search.name).to eq("/dev/vda2")
expect(partitions[2].search.name).to eq("/dev/vda3")
expect(partitions[2].size.default?).to eq(false)
expect(partitions[2].size.min).to eq(1.GiB)
expect(partitions[2].size.max).to eq(10.GiB)
expect(partitions[3].filesystem.path).to eq("/")
expect(partitions[4].search.name).to be_nil
expect(partitions[4].search.max).to be_nil
expect(partitions[4].size.default?).to eq(false)
expect(partitions[4].size.min).to eq(Y2Storage::DiskSize.zero)
expect(partitions[4].size.max).to be_nil
end
end

context "if space policy is 'custom'" do
let(:spacePolicy) { "custom" }

it "sets #partitions to the expected value" do
config = config_proc.call(subject.convert)
partitions = config.partitions
expect(partitions.size).to eq(8)
expect(partitions[0].search.name).to eq("/dev/vda1")
expect(partitions[1].search.name).to eq("/dev/vda2")
expect(partitions[2].search.name).to eq("/dev/vda3")
expect(partitions[2].size.default?).to eq(false)
expect(partitions[2].size.min).to eq(1.GiB)
expect(partitions[2].size.max).to eq(10.GiB)
expect(partitions[3].search.name).to eq("/dev/vda4")
expect(partitions[3].size.default?).to eq(false)
expect(partitions[3].size.min).to eq(Y2Storage::DiskSize.zero)
expect(partitions[3].size.max).to be_nil
expect(partitions[4].search.name).to eq("/dev/vda5")
expect(partitions[4].delete_if_needed?).to eq(true)
expect(partitions[5].search.name).to eq("/dev/vda6")
expect(partitions[5].size.default?).to eq(false)
expect(partitions[5].size.min).to eq(5.GiB)
expect(partitions[5].size.max).to eq(Y2Storage::DiskSize.unlimited)
expect(partitions[6].search.name).to eq("/dev/vda7")
expect(partitions[6].delete?).to eq(true)
expect(partitions[7].filesystem.path).to eq("/")
end
end
end
Expand Down Expand Up @@ -801,7 +916,7 @@
end

context "if a drive specifies both 'spacePolicy' and 'partitions'" do
let(:drive) { { partitions: partitions } }
let(:drive) { { spacePolicy: spacePolicy, partitions: partitions } }
include_examples "with spacePolicy and partitions", drive_proc
end
end
Expand Down

0 comments on commit a616f6d

Please sign in to comment.