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

fix: Avoid implicit storage probing #1226

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 9 additions & 3 deletions service/lib/agama/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ def on_calculate(&block)
#
# @return [Array<Y2Storage::Device>]
def available_devices
disk_analyzer.candidate_disks
disk_analyzer&.candidate_disks || []
end

# Calculates a new proposal.
#
# @param settings [Agamal::Storage::ProposalSettings] settings to calculate the proposal.
# @return [Boolean] whether the proposal was correctly calculated.
def calculate(settings)
return false unless storage_manager.probed?

select_target_device(settings) if missing_target_device?(settings)

calculate_proposal(settings)
Expand Down Expand Up @@ -170,15 +172,19 @@ def calculate_proposal(settings)
storage_manager.proposal = proposal
end

# @return [Y2Storage::DiskAnalyzer]
# @return [Y2Storage::DiskAnalyzer, nil]
def disk_analyzer
return nil unless storage_manager.probed?

storage_manager.probed_disk_analyzer
end

# Devicegraph representing the system
#
# @return [Y2Storage::Devicegraph]
# @return [Y2Storage::Devicegraph, nil]
joseivanlopez marked this conversation as resolved.
Show resolved Hide resolved
def probed_devicegraph
return nil unless storage_manager.probed?

storage_manager.probed
end

Expand Down
5 changes: 5 additions & 0 deletions service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Thu May 16 15:36:16 UTC 2024 - José Iván López González <[email protected]>

- Do not probe devices implictly (gh#openSUSE/agama#1226).

-------------------------------------------------------------------
Wed May 15 12:52:42 UTC 2024 - José Iván López González <[email protected]>

Expand Down
28 changes: 28 additions & 0 deletions service/test/agama/storage/proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,34 @@
end
end
end

context "if the system has not been probed yet" do
before do
allow(Y2Storage::StorageManager.instance).to receive(:probed?).and_return(false)
end

it "does not calculate a proposal" do
subject.calculate(achievable_settings)
expect(Y2Storage::StorageManager.instance.proposal).to be_nil
end

it "does not run the callbacks" do
callback1 = proc {}
callback2 = proc {}

subject.on_calculate(&callback1)
subject.on_calculate(&callback2)

expect(callback1).to_not receive(:call)
expect(callback2).to_not receive(:call)

subject.calculate(achievable_settings)
end

it "returns false" do
expect(subject.calculate(achievable_settings)).to eq(false)
end
end
end

describe "#settings" do
Expand Down
Loading