From 04e77b28de39bd0f96b16c57c57930f677fdc0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 1 Jul 2024 15:23:53 +0100 Subject: [PATCH 1/4] feat(storage): generate the storage config including all settings --- service/lib/agama/dbus/storage/manager.rb | 9 ++-- .../test/agama/dbus/storage/manager_test.rb | 52 ++++++------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/service/lib/agama/dbus/storage/manager.rb b/service/lib/agama/dbus/storage/manager.rb index 79aea7d2de..b92a1b9c9e 100644 --- a/service/lib/agama/dbus/storage/manager.rb +++ b/service/lib/agama/dbus/storage/manager.rb @@ -91,14 +91,13 @@ def probe busy_while { backend.probe } end - # Sets the storage config and calculates a proposal (guided or AutoYaST). + # Calculates a proposal (guided or AutoYaST) from a given storage config. # # @raise If config is not valid. # # @param serialized_config [String] Serialized storage config. It can be storage or legacy # AutoYaST settings: { "storage": ... } vs { "legacyAutoyastStorage": ... }. def apply_storage_config(serialized_config) - @serialized_storage_config = serialized_config config_json = JSON.parse(serialized_config, symbolize_names: true) if (settings_json = config_json.dig(:storage, :guided)) @@ -115,7 +114,7 @@ def apply_storage_config(serialized_config) # # @return [String] def serialized_storage_config - @serialized_storage_config || JSON.pretty_generate(generate_storage_config) + JSON.pretty_generate(storage_config) end def install @@ -433,10 +432,10 @@ def calculate_autoyast_proposal(settings_json) success ? 0 : 1 end - # Generates the storage config from the current proposal, if any. + # Storage config from the current proposal, if any. # # @return [Hash] Storage config according to JSON schema. - def generate_storage_config + def storage_config if proposal.strategy?(ProposalStrategy::GUIDED) { storage: { diff --git a/service/test/agama/dbus/storage/manager_test.rb b/service/test/agama/dbus/storage/manager_test.rb index 6bd71ca962..03ac109478 100644 --- a/service/test/agama/dbus/storage/manager_test.rb +++ b/service/test/agama/dbus/storage/manager_test.rb @@ -520,53 +520,31 @@ def pretty_json(value) JSON.pretty_generate(value) end - context "if the storage config has not been set yet" do - context "and a proposal has not been calculated" do - it "returns serialized empty storage config" do - expect(subject.serialized_storage_config).to eq(pretty_json({})) - end - end - - context "and a proposal has been calculated" do - before do - proposal.calculate_guided(settings) - end - - let(:settings) do - Agama::Storage::ProposalSettings.new.tap do |settings| - settings.device = Agama::Storage::DeviceSettings::Disk.new("/dev/vda") - end - end - - it "returns serialized storage config including guided proposal settings" do - expected_config = { - storage: { - guided: settings.to_json_settings - } - } - - expect(subject.serialized_storage_config).to eq(pretty_json(expected_config)) - end + context "if a proposal has not been calculated" do + it "returns serialized empty storage config" do + expect(subject.serialized_storage_config).to eq(pretty_json({})) end end - context "if the storage config has been set" do + context "if a proposal has been calculated" do before do - subject.apply_storage_config(storage_config.to_json) + proposal.calculate_guided(settings) end - let(:storage_config) do - { + let(:settings) do + Agama::Storage::ProposalSettings.new.tap do |settings| + settings.device = Agama::Storage::DeviceSettings::Disk.new("/dev/vda") + end + end + + it "returns serialized storage config including guided proposal settings" do + expected_config = { storage: { - guided: { - disk: "/dev/vdc" - } + guided: settings.to_json_settings } } - end - it "returns the serialized storage config" do - expect(subject.serialized_storage_config).to eq(storage_config.to_json) + expect(subject.serialized_storage_config).to eq(pretty_json(expected_config)) end end end From d63262c9fd6998e45cbf9a83440ddd13b3c151ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 1 Jul 2024 15:24:50 +0100 Subject: [PATCH 2/4] fix(storage): do not generate actions if no needed --- .../proposal_settings_conversions/to_json.rb | 14 ++++++++++---- .../proposal_settings_conversions/to_json_test.rb | 6 ++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/service/lib/agama/storage/proposal_settings_conversions/to_json.rb b/service/lib/agama/storage/proposal_settings_conversions/to_json.rb index 9eee973d39..a137412b51 100644 --- a/service/lib/agama/storage/proposal_settings_conversions/to_json.rb +++ b/service/lib/agama/storage/proposal_settings_conversions/to_json.rb @@ -86,10 +86,16 @@ def encryption_conversion end def space_conversion - { - policy: settings.space.policy.to_s, - actions: settings.space.actions.map { |d, a| { action_key(a) => d } } - } + if settings.space.policy == :custom + { + policy: "custom", + actions: settings.space.actions.map { |d, a| { action_key(a) => d } } + } + else + { + policy: settings.space.policy.to_s + } + end end def action_key(action) diff --git a/service/test/agama/storage/proposal_settings_conversions/to_json_test.rb b/service/test/agama/storage/proposal_settings_conversions/to_json_test.rb index fad93ce2d5..79f6080eb6 100644 --- a/service/test/agama/storage/proposal_settings_conversions/to_json_test.rb +++ b/service/test/agama/storage/proposal_settings_conversions/to_json_test.rb @@ -53,8 +53,7 @@ configure: true }, space: { - policy: "keep", - actions: [] + policy: "keep" }, volumes: [] ) @@ -110,8 +109,7 @@ configure: true }, space: { - policy: "keep", - actions: [] + policy: "keep" }, volumes: [] ) From a3c29d86c097a8e4839c2918286fb41ffa4d6b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 1 Jul 2024 15:33:27 +0100 Subject: [PATCH 3/4] service: changelog --- service/package/rubygem-agama-yast.changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/service/package/rubygem-agama-yast.changes b/service/package/rubygem-agama-yast.changes index fd095727bb..936d114774 100644 --- a/service/package/rubygem-agama-yast.changes +++ b/service/package/rubygem-agama-yast.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Jul 1 14:30:05 UTC 2024 - José Iván López González + +- Always generate storage config including all the proposal + settings (gh#openSUSE/agama#1422). + ------------------------------------------------------------------- Mon Jul 1 10:36:18 UTC 2024 - José Iván López González From dd5e72938eafb437157a4e4c9b0d0d0a2c794a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 1 Jul 2024 15:53:45 +0100 Subject: [PATCH 4/4] fix(software): adapt tests to changes in products - https://github.com/openSUSE/agama/pull/1421 --- service/test/agama/software/manager_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/test/agama/software/manager_test.rb b/service/test/agama/software/manager_test.rb index 6f29aa4af7..0b24c2b8a5 100644 --- a/service/test/agama/software/manager_test.rb +++ b/service/test/agama/software/manager_test.rb @@ -335,7 +335,7 @@ expect(proposal).to receive(:set_resolvables) .with("agama", :pattern, [], { optional: true }) expect(proposal).to receive(:set_resolvables) - .with("agama", :package, ["NetworkManager"]) + .with("agama", :package, ["NetworkManager", "openSUSE-repos"]) expect(proposal).to receive(:set_resolvables) .with("agama", :package, [], { optional: true }) subject.propose