From 8e406e2c4e4e57d615b82b7fb32a25e8e3439195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Tue, 4 Jun 2024 14:46:31 +0100 Subject: [PATCH] service: Convert autoyast storage section --- service/lib/agama/autoyast/storage_reader.rb | 14 +++----------- service/test/agama/autoyast/storage_reader_test.rb | 13 ++++++++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/service/lib/agama/autoyast/storage_reader.rb b/service/lib/agama/autoyast/storage_reader.rb index 54168f0b02..96a00e975c 100644 --- a/service/lib/agama/autoyast/storage_reader.rb +++ b/service/lib/agama/autoyast/storage_reader.rb @@ -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 diff --git a/service/test/agama/autoyast/storage_reader_test.rb b/service/test/agama/autoyast/storage_reader_test.rb index fd86698c4c..d8e6ce526e 100644 --- a/service/test/agama/autoyast/storage_reader_test.rb +++ b/service/test/agama/autoyast/storage_reader_test.rb @@ -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