Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): generate the storage config including all settings #1422

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <jlopez@suse.com>

- 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 <jlopez@suse.com>

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
Loading