diff --git a/service/lib/agama/storage/proposal.rb b/service/lib/agama/storage/proposal.rb index ec6c63b1f5..af4d8773b4 100644 --- a/service/lib/agama/storage/proposal.rb +++ b/service/lib/agama/storage/proposal.rb @@ -66,7 +66,7 @@ def on_calculate(&block) # # @return [Array] def available_devices - disk_analyzer.candidate_disks + disk_analyzer&.candidate_disks || [] end # Calculates a new proposal. @@ -74,6 +74,8 @@ def available_devices # @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) @@ -170,15 +172,19 @@ def calculate_proposal(settings) storage_manager.proposal = proposal end - # @return [Y2Storage::DiskAnalyzer] + # @return [Y2Storage::DiskAnalyzer, nil] nil if the system is not probed yet. 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] nil if the system is not probed yet. def probed_devicegraph + return nil unless storage_manager.probed? + storage_manager.probed end diff --git a/service/package/rubygem-agama-yast.changes b/service/package/rubygem-agama-yast.changes index ea1ca93e08..c3fad58bb7 100644 --- a/service/package/rubygem-agama-yast.changes +++ b/service/package/rubygem-agama-yast.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Thu May 16 15:36:16 UTC 2024 - José Iván López González + +- Do not probe devices implictly (gh#openSUSE/agama#1226). + ------------------------------------------------------------------- Wed May 15 12:52:42 UTC 2024 - José Iván López González diff --git a/service/test/agama/storage/proposal_test.rb b/service/test/agama/storage/proposal_test.rb index a9bf94206c..87eb6f166b 100644 --- a/service/test/agama/storage/proposal_test.rb +++ b/service/test/agama/storage/proposal_test.rb @@ -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