Skip to content

Commit

Permalink
feat(storage): generate the storage config including all settings (#1422
Browse files Browse the repository at this point in the history
)

## Problem

If the storage settings are loaded (`agama config load`) or edited
(`agama config edit`), then the `agama config show` command only reports
the settings indicated with `load` or `edit`. That is, the rest of
default applied settings (e.g., volumes) is not included. Nevertheless,
the complete settings are reported if the proposal is calculated from
the UI.

## Solution

Always report the complete proposal settings independently on how the
reproposal was requested.
  • Loading branch information
joseivanlopez authored Jul 1, 2024
2 parents ac9543a + dd5e729 commit 32143a7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 51 deletions.
9 changes: 4 additions & 5 deletions service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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: {
Expand Down
14 changes: 10 additions & 4 deletions service/lib/agama/storage/proposal_settings_conversions/to_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Jul 1 14:30:05 UTC 2024 - José Iván López González <[email protected]>

- 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 <[email protected]>

Expand Down
52 changes: 15 additions & 37 deletions service/test/agama/dbus/storage/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/test/agama/software/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
configure: true
},
space: {
policy: "keep",
actions: []
policy: "keep"
},
volumes: []
)
Expand Down Expand Up @@ -110,8 +109,7 @@
configure: true
},
space: {
policy: "keep",
actions: []
policy: "keep"
},
volumes: []
)
Expand Down

0 comments on commit 32143a7

Please sign in to comment.