Skip to content

Commit

Permalink
service: Convert autoyast storage section
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jun 4, 2024
1 parent e2c7a5a commit 8e406e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
14 changes: 3 additions & 11 deletions service/lib/agama/autoyast/storage_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,12 @@ def initialize(profile)
@profile = profile
end

# @return [Hash] Agama "storage" section
# @return [Hash] Agama "legacyAutoyastStorage" section
def read
drives = profile.fetch_as_array("partitioning")
return {} if drives.nil?
return {} if drives.empty?

# TODO: rely on AutoinstProfile classes
devices = drives.each_with_object([]) do |d, all|
next unless d["device"]

all << d["device"]
end
return {} if devices.empty?

{ "storage" => { "bootDevice" => devices.first } }
{ "legacyAutoyastStorage" => drives }
end
end
end
Expand Down
13 changes: 10 additions & 3 deletions service/test/agama/autoyast/storage_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@
end
end

context "when there are no drives" do
let(:profile) { { "partitioning" => [] } }

it "returns an empty hash" do
expect(subject.read).to be_empty
end
end

context "when there is a list of drives" do
it "uses the first 'device' key as 'bootDevice'" do
boot_device = subject.read.dig("storage", "bootDevice")
expect(boot_device).to eq("/dev/vda")
it "returns the list as 'legacyAutoyastStorage'" do
expect(subject.read["legacyAutoyastStorage"]).to eq(profile["partitioning"])
end
end
end
Expand Down

0 comments on commit 8e406e2

Please sign in to comment.