Skip to content

Commit

Permalink
storage: configure delete partition from JSON config
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Sep 4, 2024
1 parent f9a501b commit d34dd46
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ def convert(default = nil)

convert_block_device(default_config).tap do |config|
search = convert_search(config.search)
delete = partition_json[:delete]
delete_if_needed = partition_json[:deleteIfNeeded]
id = convert_id
size = convert_size(config.size)

config.search = search if search
config.delete = delete unless delete.nil?
config.delete_if_needed = delete_if_needed unless delete_if_needed.nil?
config.id = id if id
config.size = size if size
end
Expand Down
10 changes: 10 additions & 0 deletions service/lib/agama/storage/configs/partition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class Partition
# @return [Search, nil]
attr_accessor :search

# @return [Boolean]
attr_accessor :delete
alias_method :delete?, :delete

# @return [Boolean]
attr_accessor :delete_if_needed
alias_method :delete_if_needed?, :delete_if_needed

# @return [Y2Storage::PartitionId, nil]
attr_accessor :id

Expand All @@ -43,6 +51,8 @@ class Partition

def initialize
@size = Size.new
@delete = false
@delete_if_needed = false
end

# Assigned device according to the search.
Expand Down
74 changes: 74 additions & 0 deletions service/test/agama/storage/config_conversions/from_json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,80 @@
end
end

context "setting delete for a partition" do
let(:config_json) do
{
drives: [
{
partitions: [
{
search: "/dev/vda1",
delete: true
},
{
filesystem: { path: "/" }
}
]
}
]
}
end

it "sets #delete to true" do
config = subject.convert
partitions = config.drives.first.partitions
expect(partitions).to contain_exactly(
an_object_having_attributes(
search: have_attributes(name: "/dev/vda1"),
delete: true,
delete_if_needed: false
),
an_object_having_attributes(
filesystem: have_attributes(path: "/"),
delete: false,
delete_if_needed: false
)
)
end
end

context "setting delete if needed for a partition" do
let(:config_json) do
{
drives: [
{
partitions: [
{
search: "/dev/vda1",
deleteIfNeeded: true
},
{
filesystem: { path: "/" }
}
]
}
]
}
end

it "sets #delete_if_needed to true" do
config = subject.convert
partitions = config.drives.first.partitions
expect(partitions).to contain_exactly(
an_object_having_attributes(
search: have_attributes(name: "/dev/vda1"),
delete: false,
delete_if_needed: true
),
an_object_having_attributes(
filesystem: have_attributes(path: "/"),
delete: false,
delete_if_needed: false
)
)
end
end

context "omitting sizes for the partitions" do
let(:config_json) do
{
Expand Down

0 comments on commit d34dd46

Please sign in to comment.